From eddb38e9c091e8e0f3cb4529ec501091f71d901b Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Thu, 26 Nov 2020 20:05:29 +0200 Subject: Store AoC leaderboard IDs instead join codes for users mapping --- bot/exts/christmas/adventofcode.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'bot/exts/christmas/adventofcode.py') diff --git a/bot/exts/christmas/adventofcode.py b/bot/exts/christmas/adventofcode.py index 9b7780ae..70bdc50a 100644 --- a/bot/exts/christmas/adventofcode.py +++ b/bot/exts/christmas/adventofcode.py @@ -136,8 +136,8 @@ class AdventOfCode(commands.Cog): public_leaderboard_members = RedisCache() # We don't want that users join to multiple leaderboards, so return only 1 code to user. - # User ID -> Join code - user_join_codes = RedisCache() + # User ID -> AoC Leaderboard ID + user_leaderboards = RedisCache() # We must keep track when user got (and what) stars, because we have multiple leaderboards. # Format: User ID -> AoCCachedMember (pickle) @@ -400,8 +400,8 @@ class AdventOfCode(commands.Cog): log.info(f"{author.name} ({author.id}) ran command in staff AoC channel. Returning staff code.") else: # We want that user get only 1 code - if await self.user_join_codes.contains(ctx.author.id): - join_code = await self.user_join_codes.get(ctx.author.id) + if await self.user_leaderboards.contains(ctx.author.id): + join_code = self.leaderboard_join_codes[await self.user_leaderboards.get(ctx.author.id)] log.info(f"{author.name} ({author.id}) have already cached AoC join code. Returning it.") else: least_id, least = 0, 200 @@ -412,7 +412,7 @@ class AdventOfCode(commands.Cog): join_code = self.leaderboard_join_codes[least_id] # Persist this code to Redis, so we can get it later again. - await self.user_join_codes.set(ctx.author.id, join_code) + await self.user_leaderboards.set(ctx.author.id, least_id) log.info(f"{author.name} ({author.id}) got new join code. Persisted it to cache.") info_str = ( @@ -466,6 +466,11 @@ class AdventOfCode(commands.Cog): name="Advent of Code", url=f"{self._base_url}/leaderboard/private/view/{AocConfig.leaderboard_staff_id}" ) + elif await self.user_leaderboards.contains(ctx.author.id): + aoc_embed.set_author( + name="Advent of Code", + url=f"{self._base_url}/leaderboard/private/view/{await self.user_leaderboards.get(ctx.author.id)}" + ) else: aoc_embed.set_author(name="Advent of Code") aoc_embed.set_footer(text="Last Updated") -- cgit v1.2.3