feat: Add balance and leaderboard Discord slash commands#92
Closed
anumukul wants to merge 3 commits intoTheSoftwareDevGuild:mainfrom
Closed
feat: Add balance and leaderboard Discord slash commands#92anumukul wants to merge 3 commits intoTheSoftwareDevGuild:mainfrom
anumukul wants to merge 3 commits intoTheSoftwareDevGuild:mainfrom
Conversation
- Implement /balance command with optional user parameter - Implement /leaderboard command with configurable limit (5-25, default 10) - Add getUserBalance and getLeaderboard database queries - Create command rate limiter (10 requests/min per user) - Add guild_id column to activity_events table - Register slash commands on bot startup - Handle member left states in leaderboard display - Format numbers with thousands separators - Include comprehensive error handling Closes TheSoftwareDevGuild#89
joelamouche
requested changes
Oct 6, 2025
Contributor
joelamouche
left a comment
There was a problem hiding this comment.
Okay looks great! Tested in our discord and it works.
At this points it just needs a few updates in the readme and maybe use a tool for db migrations
| docker-compose up postgres -d | ||
| # Run migration | ||
| psql postgresql://guild_user:guild_password@localhost:5433/guild_genesis -f migrations/001_create_activity_events.sql |
Contributor
There was a problem hiding this comment.
Looks like this should be updated
| ## Database Schema | ||
| The bot creates an `activity_events` table with the following structure: |
Contributor
There was a problem hiding this comment.
and guild_id should be added here
| - `processed_status`: Whether the event has been processed for minting | ||
| - `created_at`: Record creation timestamp | ||
| ## Architecture |
| "dev": "npm run build && node -r dotenv/config dist/index.js", | ||
| "build": "tsc", | ||
| "start": "node -r dotenv/config dist/index.js", | ||
| "migrate": "psql $DATABASE_URL -f migrations/001_create_activity_events.sql", |
Contributor
There was a problem hiding this comment.
so this should be updated too. Maybe we could use a package to make it cleaner
Contributor
|
close due to inactivity |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Implements /balance and /leaderboard slash commands for Discord bot activity tracking as specified in #89.
Implementation
Commands:
/balance [user] - Display activity points for user (ephemeral)
/leaderboard [limit] - Show top members by points (public, limit: 5-25, default: 10)
Database:
Added guild_id column to activity_events table
Implemented getUserBalance(guildId, userId) query
Implemented getLeaderboard(guildId, limit) query with aggregation
Created indexes for performance optimization
Features:
Slash command registration on bot startup
Rate limiting: 10 requests/minute per user
Guild-only command validation
Member state handling (left members marked with "(left)")
Number formatting with thousands separators
Comprehensive error handling and logging
Architecture:
src/commands/balance.ts - Balance command implementation
src/commands/leaderboard.ts - Leaderboard command with embed formatting
src/commands/index.ts - Command registration and collection
src/utils/rateLimiter.ts - Rate limiting utility class
migrations/002_add_guild_id_to_activity_events.sql - Database schema update
Testing
All acceptance criteria verified:
Balance command returns correct totals (ephemeral)
Leaderboard displays ranked members with proper ordering
Input validation enforces limit constraints (5-25)
Rate limiting prevents spam
Error states handled appropriately
Edge cases covered (left members, empty states, long names)
Files Changed
discord-bot/
├── migrations/002_add_guild_id_to_activity_events.sql (new)
├── src/commands/
│ ├── balance.ts (new)
│ ├── leaderboard.ts (new)
│ └── index.ts (new)
├── src/utils/rateLimiter.ts (new)
├── src/db.ts (modified)
├── src/index.ts (modified)
└── src/listeners/messageCreate.ts (modified)
Closes #89