Conversation
- Implements core utility functions for leaderboard - Uses Redis cache for persistency - Global leaderboard, daily global leaderboard, a specific user's points & admin clear command - Implements the coin flip game for testing the leaderboard - Uses the duck coin image shown in the issue
with coinflip = 2 as baseline
rf20008
left a comment
There was a problem hiding this comment.
I think you've made some good progress so far. However, I have given you some feedback.
Now if points are clamped due to daily limit, the real value is shown instead of the constants. Updates all 14 games to use this new value.
jchristgit
left a comment
There was a problem hiding this comment.
All in all, looks really solid! I have a few improvement suggestions, but in general the design is sound, the implementation is sound, and the Python Discord Hive Mind is satisfied with your offering.
Co-authored-by: Jacob Christensen <jc@jchri.st>
Co-authored-by: Jacob Christensen <jc@jchri.st>
Co-authored-by: Jacob Christensen <jc@jchri.st>
the function leaderboard_me now invokes leaderboard_user with user=ctx.author
winner variable is now simply set to response.author
jchristgit
left a comment
There was a problem hiding this comment.
Looks good! Some minor finishing touches, then we can
!
rf20008
left a comment
There was a problem hiding this comment.
Overall, I think you've made significant progress on this PR. Still, I think these minor changes could make it even better.
| "You are not authorized to perform this action.", | ||
| ephemeral=True, | ||
| ) | ||
| return False |
There was a problem hiding this comment.
Will the exception raised by returning False (as Discord.py will internally raise a CheckFailure) be handled properly here?
There was a problem hiding this comment.
Yes, this is handled properly. The CheckFailure that discord.py raises internally doesn't cause issues because we already responded to the interaction, so there is no unhandled interaction error. The unauthorized user sees the message and the button callback just doesn't execute.
| if points <= 0: | ||
| total = await get_user_points(bot, user_id) | ||
| return (total, 0) |
There was a problem hiding this comment.
Why are you intentionally preventing adding negative points?
There was a problem hiding this comment.
Well none of the games give any penalties, etc. It's all only positive points on win. And also we do have a remove_points function, this can be used instead for corrections/penalties in the future.
| else: | ||
| for child in view.children: | ||
| child.disabled = True | ||
| await msg.edit(view=view) |
There was a problem hiding this comment.
Should this send another confirmatory message, or is disabling the view (your original design choice) confirmation enough of the leaderboard's clearing?
There was a problem hiding this comment.
The confirmation message is being sent at interaction.response.send_message("Leaderboard has been cleared.") so we are doing both for confirmation.
Co-authored-by: Jacob Christensen <jc@jchri.st>
Co-authored-by: rf20008 <64931063+rf20008@users.noreply.github.com>
Relevant Issues
Closes #627
Description
This PR implements the Global Leaderboard feature (Issue #627). It creates a unified scoring system across all fun and holiday games in the bot.
The persistent global scores are stored in
Leaderboard.points_cache(aRedisCachewith namespace"leaderboard:points"), which maintains user totals indefinitely across all games. The daily point tracking uses raw Redis keys with the patternleaderboard:daily:{user_id}:{game_name}, each with a TTL set to expire at UTC midnight viaseconds_until_midnight_utc(). Whenadd_points()is called, it first checks the daily key to enforce the 100-point cap per game, then atomically updates the persistent global cache.Core Implementation
.leaderboard, .lb)..leaderboard me,.leaderboard user @Member)..leaderboard today).!leaderboard clear).Visuals
Followed preferences from old closed PR, such as using the duck coin & using medals for top 3.
Game Integrations (Added
add_pointscalls)All integrated games now display a
(+X pts)message when winning to provide user feedback.Did you: