Skip to content

The LeetDiscord Bot by EpicBotCoders is a Discord bot designed to track LeetCode activity for specified users. It is built using Node.js and integrates with Discord.js, MongoDB, and Jest for testing. The bot allows users to monitor their LeetCode progress directly within Discord, facilitating community engagement and accountability.

License

Notifications You must be signed in to change notification settings

EpicBotCoders/leetDiscord

Repository files navigation

LeetDiscord Bot

License: MIT Contributor Covenant Security Policy PRs Welcome Node.js Version Discord.js MongoDB Jest ESLint Winston Logger GitHub last commit Test Coverage

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.

Table of Contents

Prerequisites

Setup Instructions

  1. Clone this repository to your local machine

  2. Install dependencies:

npm install
  1. 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 token
  • your_mongodb_connection_string with your MongoDB Atlas connection string
  1. Start the bot:
node index.js

Server Setup

When the bot joins a new server:

  1. It will automatically create initial configuration in MongoDB
  2. Use the /setchannel command to set the announcement channel
  3. Use /adduser to start tracking LeetCode users

Available Commands

  • /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

Features

  • 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

Environment Variables

Variable Description
DISCORD_TOKEN Your Discord bot token
MONGODB_URI MongoDB Atlas connection string
NODE_ENV Set to 'production' for production logging levels

Security

For details about our security practices and how to report security issues, please see our Security Policy.

Error Handling

  • 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

Data Migration

If you're upgrading from a previous version that used config.json:

  1. 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
  2. After migration, update your environment variables in .env

Contributing

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

Code of Conduct

We are committed to fostering an open and welcoming environment. Please read and follow our Code of Conduct.

Security

For details about our security practices and how to report security issues, please see our Security Policy.

Testing

The project includes a comprehensive test suite using Jest. To run the tests:

npm test

Test Coverage

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.

Running Specific Tests

Run a specific test suite:

npm test -- apiUtils

Watch mode for development:

npm run test:watch

Generate coverage report:

npm run test:coverage

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

v2.1.0 (2025-05-04)

  • ✨ 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

v2.0.0 (2025-05-02)

  • πŸŽ‰ 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

v1.0.0

  • Initial release with JSON-based configuration
  • Basic LeetCode activity tracking
  • Multi-server support
  • User management commands
  • Scheduled checks

About

The LeetDiscord Bot by EpicBotCoders is a Discord bot designed to track LeetCode activity for specified users. It is built using Node.js and integrates with Discord.js, MongoDB, and Jest for testing. The bot allows users to monitor their LeetCode progress directly within Discord, facilitating community engagement and accountability.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •