Skip to content
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
20 changes: 11 additions & 9 deletions bot/exts/fun/duck_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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"
Expand Down
15 changes: 6 additions & 9 deletions bot/exts/fun/snakes/_snakes_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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]}**."
Expand Down