|
3 | 3 | from psnawp_api import PSNAWP |
4 | 4 |
|
5 | 5 | from utils.image_utils import get_discord_color |
6 | | -from utils.trophy_utils import format_title |
| 6 | +from utils.trophy_utils import format_title, calculate_total_time |
7 | 7 | from utils.date_utils import format_date |
8 | 8 | from config.config import PSNTOKEN, DISCORD_IMAGE, TROPHIES_INTERVAL |
9 | 9 |
|
@@ -63,16 +63,16 @@ def create_trophy_embed(trophy, trophy_title_info, client, current, total_trophi |
63 | 63 | embed.set_author(name="A Trophy Unlocked", icon_url=trophy_title.title_icon_url) |
64 | 64 | return embed |
65 | 65 |
|
66 | | -def create_platinum_embed(trophy, trophy_title_info, client): |
| 66 | +def create_platinum_embed(trophy, trophy_title_info, client, formatted_time_diff): |
67 | 67 | trophy_title = trophy_title_info['trophy_title'] |
68 | 68 | game_url = format_title(trophy_title.title_name) # format the title name into a URL |
69 | 69 | platform = trophy_title_info['platform'] |
70 | 70 | most_common_color = get_discord_color(trophy_title.title_icon_url) |
71 | | - embed = discord.Embed(description=f"**[{trophy_title.title_name}]({game_url}) ({platform})**\n\n {client.online_id} has achieved the Platinum trophy of the game! \n\n{trophy_title.title_name} has {trophy_title.defined_trophies['bronze']} Bronze, {trophy_title.defined_trophies['silver']} Silver, {trophy_title.defined_trophies['gold']} Gold, and {trophy_title.defined_trophies['platinum']} Platinum trophy.\n\n The Platinum has been achieved by {trophy.trophy_earn_rate}% of players", color=most_common_color) |
| 71 | + embed = discord.Embed(description=f"**[{trophy_title.title_name}]({game_url}) ({platform})**\n\n Achieved in {formatted_time_diff} \n\n{trophy_title.title_name} has {trophy_title.defined_trophies['bronze']} Bronze, {trophy_title.defined_trophies['silver']} Silver, {trophy_title.defined_trophies['gold']} Gold, and {trophy_title.defined_trophies['platinum']} Platinum trophy\n\n The Platinum has been achieved by {trophy.trophy_earn_rate}% of players", color=most_common_color) |
72 | 72 | embed.add_field(name="Trophy", value=f"[{trophy.trophy_name}]({trophy.trophy_icon_url})", inline=True) |
73 | 73 | embed.set_image(url=DISCORD_IMAGE) |
74 | 74 | embed.set_thumbnail(url=trophy_title.title_icon_url) |
75 | | - embed.set_footer(text=f"{client.online_id} • Earned on {format_date(trophy.earned_date_time)}", icon_url=client.profile_picture_url) |
| 75 | + embed.set_footer(text=f"{client.online_id} • Platinum achieved on {format_date(trophy.earned_date_time)}", icon_url=client.profile_picture_url) |
76 | 76 | embed.set_author(name="A New Platinum", icon_url=trophy_title.title_icon_url) |
77 | 77 | return embed |
78 | 78 |
|
@@ -107,7 +107,15 @@ async def process_trophies_embeds(client, title_ids, TROPHIES_INTERVAL): |
107 | 107 | embed = create_trophy_embed(trophy, trophy_title, client, starting_count + i + 1, total_trophies) |
108 | 108 | trophy_embeds.append((trophy.earned_date_time, embed)) |
109 | 109 | if trophy.trophy_type.name.lower() == 'platinum': |
110 | | - embed = create_platinum_embed(trophy, trophy_title, client) |
| 110 | + # Get the oldest and newest trophy |
| 111 | + oldest_trophy = earned_trophies[0] |
| 112 | + newest_trophy = earned_trophies[-1] |
| 113 | + # Calculate the time difference |
| 114 | + time_diff = newest_trophy[0].earned_date_time - oldest_trophy[0].earned_date_time |
| 115 | + # Format the time difference |
| 116 | + formatted_time_diff = calculate_total_time(time_diff) |
| 117 | + # Pass formatted_time_diff to create_platinum_embed function |
| 118 | + embed = create_platinum_embed(trophy, trophy_title, client, formatted_time_diff) |
111 | 119 | platinum_embeds.append((trophy.earned_date_time, embed)) |
112 | 120 | return trophy_embeds, len(recent_trophies), platinum_embeds |
113 | 121 |
|
|
0 commit comments