From 101965af01ae4abeab59dcd6ff36284878fadf67 Mon Sep 17 00:00:00 2001 From: Anna Remmare Date: Mon, 2 Mar 2026 21:28:13 +0100 Subject: [PATCH 1/2] refactor: duck game scoring --- bot/exts/fun/duck_game.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/bot/exts/fun/duck_game.py b/bot/exts/fun/duck_game.py index bebeb5f6f..a724854c0 100644 --- a/bot/exts/fun/duck_game.py +++ b/bot/exts/fun/duck_game.py @@ -18,6 +18,11 @@ DUCK_GAME_FIRST_PLACE_POINTS = 30 DUCK_GAME_SECOND_PLACE_POINTS = 20 DUCK_GAME_THIRD_PLACE_POINTS = 10 +DUCK_GAME_POINT_AWARDS = ( + DUCK_GAME_FIRST_PLACE_POINTS, + DUCK_GAME_SECOND_PLACE_POINTS, + DUCK_GAME_THIRD_PLACE_POINTS, +) DUCK_GAME_NAME = "duck_game" DECK = list(product(*[(0, 1, 2)]*4)) @@ -304,21 +309,18 @@ async def end_game(self, channel: discord.TextChannel, game: DuckGame, end_messa reverse=True, ) - # Award leaderboard points to top 3 players - point_awards = [ - DUCK_GAME_FIRST_PLACE_POINTS, - DUCK_GAME_SECOND_PLACE_POINTS, - DUCK_GAME_THIRD_PLACE_POINTS - ] + # Award leaderboard points to top finishers (number of places from DUCK_GAME_POINT_AWARDS) earned_points = {} - for rank, (member, score) in enumerate(scores[:3]): + for rank, (member, score) in enumerate(scores[:len(DUCK_GAME_POINT_AWARDS)]): if score > 0: - _, earned = await add_points(self.bot, member.id, point_awards[rank], DUCK_GAME_NAME) + _, earned = await add_points( + self.bot, member.id, DUCK_GAME_POINT_AWARDS[rank], DUCK_GAME_NAME + ) earned_points[member.id] = earned scoreboard = "Final scores:\n\n" for rank, (member, score) in enumerate(scores): - if rank < 3 and score > 0 and member.id in earned_points: + if rank < len(DUCK_GAME_POINT_AWARDS) and score > 0 and member.id in earned_points: scoreboard += f"{member.display_name}: {score} (+{earned_points[member.id]} global pts)\n" else: scoreboard += f"{member.display_name}: {score}\n" From da6c010467746a164bf4af66bb1fa7268c31984a Mon Sep 17 00:00:00 2001 From: Anna Remmare Date: Mon, 2 Mar 2026 21:38:51 +0100 Subject: [PATCH 2/2] refactor: remove redundant award_points check in snakes --- bot/exts/fun/snakes/_snakes_cog.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/bot/exts/fun/snakes/_snakes_cog.py b/bot/exts/fun/snakes/_snakes_cog.py index f114dda95..7baf1b77e 100644 --- a/bot/exts/fun/snakes/_snakes_cog.py +++ b/bot/exts/fun/snakes/_snakes_cog.py @@ -417,7 +417,7 @@ async def _validate_answer( answer: str, options: dict[str, str], *, - award_points: int | None = None, + award_points: int, ) -> None: """Validate the answer using a reaction event loop.""" def predicate(reaction: Reaction, user: Member) -> bool: @@ -440,14 +440,11 @@ def predicate(reaction: Reaction, user: Member) -> bool: return if str(reaction.emoji) == ANSWERS_EMOJI[answer]: - if award_points is not None: - _, earned = await add_points(self.bot, ctx.author.id, award_points, SNAKE_QUIZ_GAME_NAME) - await ctx.send( - f"{random.choice(CORRECT_GUESS)} The correct answer was **{options[answer]}**. " - f"(+{earned} pts)" - ) - else: - await ctx.send(f"{random.choice(CORRECT_GUESS)} The correct answer was **{options[answer]}**.") + _, earned = await add_points(self.bot, ctx.author.id, award_points, SNAKE_QUIZ_GAME_NAME) + await ctx.send( + f"{random.choice(CORRECT_GUESS)} The correct answer was **{options[answer]}**. " + f"(+{earned} pts)" + ) else: await ctx.send( f"{random.choice(INCORRECT_GUESS)} The correct answer was **{options[answer]}**."