Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: trophy emoji's for rarity #7

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/bronze.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/gold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/platinum.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/silver.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions config/emoji.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"emojis": {
"bronze": "",
"silver": "",
"gold": "",
"platinum": ""
}
}
4 changes: 2 additions & 2 deletions src/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
16 changes: 15 additions & 1 deletion utils/trophy.py
Original file line number Diff line number Diff line change
@@ -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
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!")
Loading