diff --git a/assets/bronze.png b/assets/bronze.png new file mode 100644 index 0000000..37749db Binary files /dev/null and b/assets/bronze.png differ diff --git a/assets/gold.png b/assets/gold.png new file mode 100644 index 0000000..42f44a9 Binary files /dev/null and b/assets/gold.png differ diff --git a/assets/platinum.png b/assets/platinum.png new file mode 100644 index 0000000..2ca6bfa Binary files /dev/null and b/assets/platinum.png differ diff --git a/assets/silver.png b/assets/silver.png new file mode 100644 index 0000000..3fb5bf3 Binary files /dev/null and b/assets/silver.png differ diff --git a/config/emoji.json b/config/emoji.json new file mode 100644 index 0000000..3a4e01e --- /dev/null +++ b/config/emoji.json @@ -0,0 +1,8 @@ +{ + "emojis": { + "bronze": "", + "silver": "", + "gold": "", + "platinum": "" + } +} \ No newline at end of file diff --git a/src/discord.py b/src/discord.py index 9b5d8c0..72ce68b 100644 --- a/src/discord.py +++ b/src/discord.py @@ -2,7 +2,7 @@ from utils.image import get_discord_color from utils.datetime import format_date -from utils.trophy import format_title +from utils.trophy import format_title, replace_trophy_with_emoji from config.config import DISCORD_IMAGE @@ -17,7 +17,7 @@ async def create_trophy_embed(trophy, trophy_title_info, client, current, total_ percentage = (completion / total_trophies) * 100 embed = discord.Embed(description=f"**[{trophy_title.title_name}]({game_url}) ({platform})**\n\n{trophy.trophy_detail}\n\nUnlocked by {trophy.trophy_earn_rate}% of players", color=most_common_color) embed.add_field(name="Trophy", value=f"[{trophy.trophy_name}]({trophy.trophy_icon_url})", inline=True) - embed.add_field(name="Rarity", value=f"{trophy.trophy_type.name.lower().capitalize()}") + embed.add_field(name="Rarity", value=replace_trophy_with_emoji(trophy.trophy_type.name.lower())) embed.add_field(name="Completion", value=f"{completion}/{total_trophies} ({percentage:.2f}%)", inline=True) embed.set_image(url=DISCORD_IMAGE) embed.set_thumbnail(url=trophy.trophy_icon_url) diff --git a/utils/trophy.py b/utils/trophy.py index 5a9d790..bad1315 100644 --- a/utils/trophy.py +++ b/utils/trophy.py @@ -1,7 +1,21 @@ import re +import json + +from utils.custom_logger import logger def format_title(title): title = title.lower() # convert to lowercase title = re.sub(r"[^\w\s]", '', title) # remove special characters except whitespace and underscores title = title.replace(' ', '-') # replace spaces with hyphens - return f"https://www.playstation.com/games/{title}/" # prepend base URL \ No newline at end of file + return f"https://www.playstation.com/games/{title}/" # prepend base URL + +def replace_trophy_with_emoji(trophy_type): + try: + with open('config/emoji.json') as f: + emoji = json.load(f) + emoji_dict = emoji['emojis'] + return emoji_dict.get(trophy_type.lower(), trophy_type) + except FileNotFoundError: + logger.error("Error: emoji.json not found!") + except json.JSONDecodeError: + logger.error("Error: emoji.json is not correctly formatted!") \ No newline at end of file