Skip to content

Commit e01a26a

Browse files
authored
Merge pull request #38 from zeroquinc:fix-total-points
feature: support for softcore
2 parents 88f5b76 + 9e98eab commit e01a26a

File tree

3 files changed

+59
-15
lines changed

3 files changed

+59
-15
lines changed

services/game.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def __init__(self, data: dict):
3737
self.richpresence = data.get('RichPresencePatch', "N/A")
3838
self.title = data.get('Title', "N/A")
3939
self.total_achievements = data.get('NumAchievements', "N/A")
40-
self.total_achievements_earned = data.get('NumAwardedToUserHardcore', "N/A")
40+
self.total_achievements_earned_hardcore = data.get('NumAwardedToUserHardcore', "N/A")
41+
self.total_achievements_earned_softcore = data.get('NumAwardedToUser', "N/A")
4142
self.total_players_hardcore = data.get('NumDistinctPlayersHardcore', "N/A")
4243
self.total_players_softcore = data.get('NumDistinctPlayersCasual', "N/A")
4344
self.total_points = data.get('points_total', "N/A")

src/achievements.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ def create_achievement_embed(game, user, achievement, profile, current, total):
112112

113113
# First style of achievement embed
114114
def create_achievement_embed_v1(game, user, achievement, profile, current, total):
115-
completion = game.total_achievements_earned - total + current
115+
if achievement.mode == "Hardcore":
116+
completion = game.total_achievements_earned_hardcore - total + current
117+
else: # Assuming 'softcore' as the default else case
118+
completion = game.total_achievements_earned_softcore - total + current
119+
116120
percentage = (completion / game.total_achievements) * 100
117121
unlock_percentage = (game.achievements[achievement.title]['NumAwardedHardcore'] / game.total_players_hardcore) * 100 if game.total_players_hardcore else 0
118122
most_common_color = get_discord_color(achievement.game_icon)
@@ -154,7 +158,11 @@ def create_achievement_embed_v1(game, user, achievement, profile, current, total
154158

155159
# Second style of achievement embed
156160
def create_achievement_embed_v2(game, user, achievement, profile, current, total):
157-
completion = game.total_achievements_earned - total + current
161+
if achievement.mode == "Hardcore":
162+
completion = game.total_achievements_earned_hardcore - total + current
163+
else: # Assuming 'softcore' as the default else case
164+
completion = game.total_achievements_earned_softcore - total + current
165+
158166
percentage = (completion / game.total_achievements) * 100
159167
unlock_percentage = (game.achievements[achievement.title]['NumAwardedHardcore'] / game.total_players_hardcore) * 100 if game.total_players_hardcore else 0
160168
most_common_color = get_discord_color(achievement.game_icon)

src/daily_overview.py

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ async def process_daily_overview(users, api_username, api_key, channel):
1818
profile = UserProfile(user, api_username, api_key)
1919
achievements = user_completion.get_achievements()
2020
if achievements: # Only process if there are achievements
21-
achievement_count, daily_points, daily_retropoints = count_daily_points(achievements)
21+
achievement_count, daily_hardcore_points, daily_softcore_points, daily_retropoints = count_daily_points(achievements)
2222
max_achievement = find_max_achievement(achievements)
2323
fav_game_details = favorite_game(achievements)
24-
logger.info(f"{user} has earned {achievement_count} achievements today, totaling {daily_points} points and {daily_retropoints} RetroPoints. Their favorite game is {fav_game_details[0]} with {fav_game_details[1]} achievements.")
25-
embed = create_embed(profile, achievement_count, daily_points, daily_retropoints, max_achievement, *fav_game_details)
24+
logger.info(f"{user} has earned {achievement_count} achievements today, totaling {daily_hardcore_points} Hardcore points, {daily_softcore_points} Softcore points and {daily_retropoints} RetroPoints. Their favorite game is {fav_game_details[0]} with {fav_game_details[1]} achievements.")
25+
embed = create_embed(profile, daily_hardcore_points, daily_softcore_points, daily_retropoints, max_achievement, *fav_game_details, achievements)
2626
all_embeds.append(embed)
2727
except Exception as e:
2828
logger.error(f'Error processing user {user}: {e}')
@@ -34,9 +34,17 @@ async def process_daily_overview(users, api_username, api_key, channel):
3434

3535
def count_daily_points(achievements):
3636
achievement_count = len(achievements) if achievements else 0
37-
daily_points = sum(achievement.points for achievement in achievements) if achievements else 0
38-
daily_retropoints = sum(achievement.retropoints for achievement in achievements) if achievements else 0
39-
return achievement_count, format_points(daily_points), format_points(daily_retropoints)
37+
38+
daily_hardcore_points = sum(a.points for a in achievements if a.mode == "Hardcore") if achievements else 0
39+
daily_softcore_points = sum(a.points for a in achievements if a.mode == "Softcore") if achievements else 0
40+
daily_retropoints = sum(a.retropoints for a in achievements if a.mode == "Hardcore") if achievements else 0 # No RetroPoints for Softcore
41+
42+
return (
43+
achievement_count,
44+
format_points(daily_hardcore_points),
45+
format_points(daily_softcore_points),
46+
format_points(daily_retropoints)
47+
)
4048

4149
def find_max_achievement(achievements):
4250
return max(achievements, key=lambda achievement: (achievement.points, achievement.retropoints), default=None)
@@ -57,10 +65,10 @@ def extract_favorite_game(game_counts):
5765
fav_details = game_counts[favorite_game]
5866
return favorite_game, fav_details[0], fav_details[1], fav_details[2], format_points(fav_details[3]), format_points(fav_details[4])
5967

60-
def create_embed(profile, achievement_count, daily_points, daily_retropoints, max_achievement, fav_game, fav_game_achievements, fav_url, fav_console_name, fav_game_points, fav_game_retropoints):
68+
def create_embed(profile, daily_hardcore_points, daily_softcore_points, daily_retropoints, max_achievement, fav_game, fav_game_achievements, fav_url, fav_console_name, fav_game_points, fav_game_retropoints, achievements):
6169
embed_color = get_discord_color(max_achievement.badge_url if max_achievement else profile.profile.user_pic_unique)
6270
embed = discord.Embed(title='', description='', color=embed_color).set_footer(
63-
text=f"Total Points: {profile.profile.total_points_format}Total RetroPoints: {profile.profile.total_true_points_format}",
71+
text=f"Hardcore Points: {profile.profile.total_points_format}Softcore Points: {profile.profile.total_softcore_points} • Retro Points: {profile.profile.total_true_points_format}",
6472
icon_url=profile.profile.user_pic_unique
6573
).set_author(
6674
name=f"Daily Overview for {profile.profile.user}",
@@ -69,15 +77,42 @@ def create_embed(profile, achievement_count, daily_points, daily_retropoints, ma
6977
url=DISCORD_IMAGE
7078
)
7179
if max_achievement:
80+
hardcore_count = sum(1 for a in achievements if a.mode == "Hardcore")
81+
softcore_count = sum(1 for a in achievements if a.mode == "Softcore")
82+
83+
achievement_mode_text = f"[{profile.profile.user}]({profile.profile.user_url}) has earned "
84+
if hardcore_count > 0 and softcore_count > 0:
85+
achievement_mode_text += f"{softcore_count} softcore achievement{'s' if softcore_count != 1 else ''} and {hardcore_count} hardcore achievement{'s' if hardcore_count != 1 else ''} today.\n\n"
86+
elif hardcore_count > 0:
87+
achievement_mode_text += f"{hardcore_count} hardcore achievement{'s' if hardcore_count != 1 else ''} today.\n\n"
88+
elif softcore_count > 0:
89+
achievement_mode_text += f"{softcore_count} softcore achievement{'s' if softcore_count != 1 else ''} today.\n\n"
90+
7291
embed.set_thumbnail(url=max_achievement.badge_url)
7392
embed.description = (
74-
f"[{profile.profile.user}]({profile.profile.user_url}) has earned **{achievement_count}** achievements today.\n\n"
93+
f"{achievement_mode_text}"
7594
f"[{fav_game}]({fav_url}) ({fav_console_name}) is the game with the most earned **({fav_game_achievements})** achievements today.\n"
76-
f"**{fav_game_points}** Points and **{fav_game_retropoints}** RetroPoints.\n\n"
95+
)
96+
if daily_hardcore_points != "0":
97+
embed.description += f"**{fav_game_points}** Hardcore Points and **{fav_game_retropoints}** Retro Points.\n\n"
98+
else:
99+
embed.description += f"**{fav_game_points}** Softcore Points.\n\n"
100+
101+
embed.description += (
77102
f"[{max_achievement.title}]({max_achievement.url}) from [{max_achievement.game_title}]({max_achievement.game_url}) ({max_achievement.remap_console_name()}) is the top achievement of the day.\n"
78-
f"**{max_achievement.points}** Points and **{max_achievement.retropoints_format}** RetroPoints.\n\n"
79-
f"***{daily_points}** Points and **{daily_retropoints}** RetroPoints have been earned in total today.*"
80103
)
104+
if max_achievement.mode == "Hardcore":
105+
embed.description += f"**{max_achievement.points}** Hardcore Points and **{max_achievement.retropoints_format}** Retro Points.\n\n"
106+
else:
107+
embed.description += f"**{max_achievement.points}** Hardcore Points.\n\n"
108+
109+
if daily_hardcore_points != "0":
110+
embed.description += f"***{daily_hardcore_points}** Hardcore Points and **{daily_retropoints}** Retro Points have been earned in total today.*"
111+
elif daily_softcore_points != "0":
112+
embed.description += f"***{daily_softcore_points}** Softcore Points have been earned in total today.*"
113+
else:
114+
embed.description += "***0** Points have been earned in total today.*"
115+
81116
else:
82117
embed.description = 'Nothing has been earned today.'
83118
return embed

0 commit comments

Comments
 (0)