This Discord bot tracks LeetCode activity for specified users and posts updates to Discord channels. It supports multiple servers (guilds) with per-server configurations, storing data in MongoDB Atlas.
- LeetDiscord Bot
- Node.js (v14 or higher)
- A Discord bot token (from Discord Developer Portal)
- MongoDB Atlas account (free tier works fine)
-
Clone this repository to your local machine
-
Install dependencies:
npm install
- Create a
.env
file in the root directory with:
DISCORD_TOKEN=your_discord_bot_token
MONGODB_URI=your_mongodb_connection_string
Replace:
your_discord_bot_token
with your Discord bot tokenyour_mongodb_connection_string
with your MongoDB Atlas connection string
- Start the bot:
node index.js
When the bot joins a new server:
- It will automatically create initial configuration in MongoDB
- Use the
/setchannel
command to set the announcement channel - Use
/adduser
to start tracking LeetCode users
/setchannel
- Set the channel for LeetCode activity announcements (requires Manage Channels permission)/adduser
- Add a LeetCode username to track (optionally link to a Discord user)/removeuser
- Remove a LeetCode username from tracking/listusers
- List all tracked users in the server/check
- Manually trigger a check of today's LeetCode challenge status/botinfo
- Display information about the bot and its GitHub repository/managecron
- Manage scheduled check times (requires Manage Channels permission)/managecron add
- Add a new check time (24h format)/managecron remove
- Remove an existing check time/managecron list
- List all scheduled check times
- Multi-server support with independent configurations
- MongoDB Atlas integration for reliable data storage
- Per-server announcement channels
- Automated welcome message with setup instructions
- Permission-based command system:
- Users can add/remove themselves
- Admins can manage all users
- Channel management requires "Manage Channels" permission
- Optional Discord user mentions when reporting challenge status
- Flexible cron job management for check schedules
- Detailed problem information in status updates:
- Problem difficulty
- Topic tags
- Acceptance rate
- Direct link to problem
- Complete submission tracking:
- Daily challenge completion history
- Submission timestamps
- Problem difficulty tracking
- Duplicate submission prevention
- Built-in retry and error handling
- Robust timestamp handling:
- Support for Unix timestamps
- Support for ISO string dates
- Fallback handling for invalid dates
- Permission handling:
- Automatic permission checks
- Guild owner notifications for permission issues
- Detailed error feedback
- Winston-based logging system with:
- Error tracking
- Warning notifications
- Debug information
- Activity logging
- Automated user tracking and status updates
Variable | Description |
---|---|
DISCORD_TOKEN | Your Discord bot token |
MONGODB_URI | MongoDB Atlas connection string |
NODE_ENV | Set to 'production' for production logging levels |
For details about our security practices and how to report security issues, please see our Security Policy.
- The bot includes comprehensive error logging
- All errors are logged to
logs/error.log
- General activity is logged to
logs/combined.log
- Console output includes colorized logging for better visibility
If you're upgrading from a previous version that used config.json:
- The migration script will automatically:
- Move guild configurations to MongoDB
- Create a backup of your config.json as config.json.bak
- Update config.json to only contain the bot token
- After migration, update your environment variables in .env
We love contributions! Please see our Contributing Guide for details on how to:
- Set up your development environment
- Run tests
- Submit pull requests
- Report bugs
- Propose new features
We are committed to fostering an open and welcoming environment. Please read and follow our Code of Conduct.
For details about our security practices and how to report security issues, please see our Security Policy.
The project includes a comprehensive test suite using Jest. To run the tests:
npm test
Tests cover all major functionality including:
- DailySubmission model validation
- Timestamp parsing and handling
- Permission checks and error handling
- API interactions and response handling
- Database operations
- Discord message handling
The test suite uses:
- mongodb-memory-server for database testing
- axios-mock-adapter for API mocking
- Jest mocks for Discord.js interactions
- Winston logger mocking
- Comprehensive assertion coverage
Test coverage reports are available in the coverage/ directory after running tests.
Run a specific test suite:
npm test -- apiUtils
Watch mode for development:
npm run test:watch
Generate coverage report:
npm run test:coverage
This project is licensed under the MIT License - see the LICENSE file for details.
- β¨ Added submission tracking with MongoDB
- π Added welcome message when bot joins a server
- β Added /botinfo command for quick bot information access
- π Improved timestamp handling with support for:
- Unix timestamps (seconds/milliseconds)
- ISO string dates
- Fallback handling for invalid dates
- π Enhanced permission handling:
- Automatic permission checks before sending messages
- Guild owner notifications for permission issues
- Detailed error feedback
- π§ͺ Added comprehensive test coverage:
- MongoDB integration tests
- Timestamp parsing tests
- Permission handling tests
- API interaction mocks
- π Improved error logging and debugging
- β‘οΈ Added duplicate submission prevention
- π Added retry mechanisms for API failures
- π Migrated from JSON file storage to MongoDB Atlas
- β¨ Added flexible cron job management with /managecron command
- π Enhanced status updates with detailed problem information
- π Improved logging system with Winston
- π Moved sensitive data to environment variables
- π Fixed user tracking and removal issues
- π Improved error handling and interaction responses
- π Added debug logging for better troubleshooting
- Initial release with JSON-based configuration
- Basic LeetCode activity tracking
- Multi-server support
- User management commands
- Scheduled checks