Skip to content

feat: add reputation leaderboard command with pagination#52

Merged
Firestone82 merged 2 commits into
masterfrom
claude/add-reps-leaderboard-3LbQr
May 19, 2026
Merged

feat: add reputation leaderboard command with pagination#52
Firestone82 merged 2 commits into
masterfrom
claude/add-reps-leaderboard-3LbQr

Conversation

@Firestone82
Copy link
Copy Markdown
Owner

Summary

Adds a new /rep_leaderboard command that displays a ranked leaderboard of users by total reputation. The leaderboard supports pagination with a summary view showing top 5 and bottom 5 users, plus detailed pages for users in between.

Changes

  • New command: rep_leaderboard in src/commands/reputation/cmd_leaderboard.rs

    • Fetches all reputation entries from the database, grouped and ranked by total rep
    • Renders a summary page (top 5 + bottom 5 with middle count indicator) plus detail pages
    • Implements interactive pagination with Previous/Next buttons
    • Enforces command-author-only navigation with 2-minute timeout
    • Cleans up buttons after interaction stream ends
  • New data type: LeaderboardEntry struct in src/commands/reputation.rs

    • Holds receiver_id, total_rep, and log_count for each ranked user
  • Embed variants: Extended ReputationEmbed enum in src/embeds/reputation/rep_embed.rs

    • LeaderboardSummary: Shows top/bottom entries with middle count
    • LeaderboardPage: Shows detailed page of entries with rank range
    • Added helper functions rank_prefix() and render_entries() for consistent formatting with medal emojis (🥇🥈🥉) for top 3
  • Module registration: Added cmd_leaderboard module declaration and command registration in src/commands/reputation.rs and src/bot.rs

Implementation Details

  • Uses sqlx::query_as!() with strongly-typed LeaderboardEntry struct for database access
  • Pagination logic: 10 items per detail page, with summary page (page 0) showing top 5 + bottom 5
  • Button state management via DeferredInteractionStream with proper permission checks
  • Graceful cleanup: removes navigation buttons after timeout or completion

https://claude.ai/code/session_01DMBDUREAZP7tfAwmp2xeLo

claude added 2 commits May 19, 2026 16:21
First page shows the top 5 and bottom 5 with a count of users in
between. Subsequent pages walk the full ranking in chunks of 10
(1-10, 11-20, ...). Same navigation UX as the rep logs list.
The summary already covers the top 5, so the first detail page now
shows ranks 6–15 (then 16–25, …). When everyone fits in the summary
(≤10 ranked users), there are no detail pages and the next button
stays disabled.
@Firestone82 Firestone82 merged commit 1c88818 into master May 19, 2026
3 checks passed
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 24aa562fce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +127 to +129
let start = SUMMARY_TOP + detail_page * ITEMS_PER_PAGE;
let end = (start + ITEMS_PER_PAGE).min(entries.len());
let slice = if start < entries.len() { &entries[start..end] } else { &[][..] };
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exclude bottom summary rows from detail pages

Detail pagination currently slices from SUMMARY_TOP through entries.len() (start..end), so once there are more than SUMMARY_TOP + SUMMARY_BOTTOM users, the final detail page(s) include the same bottom 5 users already shown on the summary page. For example, with 25 users, page 2 repeats ranks 21–25 instead of only showing the “in-between” users. This makes the paginated output inconsistent and duplicates leaderboard rows; cap detailed slices (and page count) at entries.len() - SUMMARY_BOTTOM when summary mode is active.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants