Skip to content

cxyfer/leetcode-daily-discord-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

91 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฏ LeetCode Daily Challenge Discord Bot

A modern Discord bot that automatically fetches and shares LeetCode daily challenges

Python Discord License

โœจ Features

  • ๐Ÿ”„ Automatic Daily Challenge: Automatically retrieves and posts LeetCode daily challenges
  • โฐ Scheduled Delivery: Configurable posting time for each server
  • ๐ŸŽฎ Slash Commands: Easy-to-use slash commands for manual control
  • ๐Ÿ“Š Rich Information: Includes title, difficulty, link, tags, and more
  • ๐ŸŒ Multi-server Support: Independent settings for each Discord server
  • ๐Ÿ”” Custom Notifications: Configurable role mentions and channels
  • ๐ŸŒ Timezone Support: Server-specific timezone settings
  • ๐Ÿ“… Historical Challenges: View past daily challenges by date
  • ๐Ÿ” Problem Lookup: Query single or multiple LeetCode problems with custom titles and messages
  • ๐Ÿ“ˆ Submission Tracking: View recent accepted submissions for any user
  • ๐Ÿค– AI-Powered Features: Optional problem translation and inspiration (requires Gemini API key)
  • ๐Ÿ’พ Smart Caching: Efficient caching system for better performance

๐Ÿš€ Quick Start

  1. Clone the repository:

    git clone https://github.com/cxyfer/leetcode-daily-discord-bot.git
    cd leetcode-daily-discord-bot
  2. Configure your bot:

    # Copy and edit the configuration file
    cp config.toml.example config.toml
    # Edit config.toml with your settings
    
    # Alternative: Use environment variables (.env)
    cp .env.example .env
    # Edit .env with your Discord bot token
  3. Run database migration (if upgrading from older version):

    # Migrate server settings from settings.db to data.db
    sqlite3 data/data.db < data/migrate_settings.sql
  4. Run the bot:

    uv run bot.py

๐Ÿ› ๏ธ Configuration

Configuration Methods

The bot supports two configuration methods:

1. TOML Configuration (Recommended)

Create a config.toml file from the example:

[discord]
token = "your_discord_bot_token_here"

[llm.gemini]
api_key = "your_google_gemini_api_key_here"  # Optional, for AI features

[schedule]
post_time = "00:00"  # Default posting time
timezone = "UTC"     # Default timezone

See config.toml.example for all available options.

2. Environment Variables

For backward compatibility, you can use a .env file:

DISCORD_TOKEN=your_bot_token_here
GOOGLE_GEMINI_API_KEY=your_gemini_api_key_here  # Optional
POST_TIME=00:00  # Optional
TIMEZONE=UTC     # Optional

Note: Environment variables take precedence over config.toml settings.

Required Bot Permissions

  • Send Messages
  • Embed Links
  • Use Slash Commands

Required Intents

  • Message Content - Receive message content
    • Note: When the bot joins more than 100 servers, this permission needs to be verified and approved by Discord

๐Ÿ“ Usage

Slash Commands

Command Description Required Permissions
/daily [date] [public] Display LeetCode.com (LCUS) daily challenge
โ€ข Optional: YYYY-MM-DD for historical challenges
โ€ข Optional: public - Show response publicly (default: private)
โ€ข Note: Historical data available from April 2020 onwards
None
/daily_cn [date] [public] Display LeetCode.cn (LCCN) daily challenge
โ€ข Optional: YYYY-MM-DD for historical challenges
โ€ข Optional: public - Show response publicly (default: private)
None
/problem <problem_ids> [domain] [public] [message] [title] Query one or multiple LeetCode problems
โ€ข problem_ids: Single ID (e.g., 1) or comma-separated IDs (e.g., 1,2,3)
โ€ข domain: com or cn (default: com)
โ€ข public: Show response publicly (default: private)
โ€ข message: Optional personal message/note (max 500 chars)
โ€ข title: Custom title for multi-problem mode (max 100 chars)
โ€ข Note: Supports up to 10 problems per query
None
/recent <username> [limit] [public] View recent accepted submissions for a user
โ€ข username: LeetCode username (LCUS only)
โ€ข limit: Number of submissions (1-50, default: 20)
โ€ข public: Show response publicly (default: private)
None
/set_channel Set notification channel for daily challenges Manage Channels
/set_role Set role to mention with daily challenges Manage Roles
/set_post_time Set posting time (HH:MM format) Manage Guild
/set_timezone Set server timezone for scheduling Manage Guild
/show_settings Display current server settings None
/remove_channel Remove channel settings Manage Channels

Command Examples

Daily Challenge Commands

/daily                    # Get today's LeetCode.com challenge (private)
/daily public:true        # Get today's challenge and show response publicly
/daily date:2024-01-15    # Get historical challenge from Jan 15, 2024

Problem Lookup

# Single problem lookup
/problem problem_ids:1                    # Get Two Sum problem from LeetCode.com (private)
/problem problem_ids:1 public:true        # Get Two Sum problem publicly

# Multiple problems lookup
/problem problem_ids:1,2,3                # Get multiple problems with overview
/problem problem_ids:1,2,3 title:Dynamic Programming Practice  # Custom title
/problem problem_ids:1,2,3 message:Today's study plan         # With personal note
/problem problem_ids:1,2,3 title:Weekly Contest Problems message:Need to practice these  # Both title and message

# Multi-problem with domain selection
/problem problem_ids:1,2,3 domain:cn      # Query from LeetCode.cn

Recent Submissions

/recent username:alice              # View 20 recent submissions (private)
/recent username:alice limit:50     # View 50 recent submissions
/recent username:alice limit:50 public:true  # View 50 submissions publicly

Server Configuration

/set_channel              # Set current channel for daily notifications
/set_role                 # Configure role to ping
/set_post_time time:08:00 # Set daily post time to 8:00 AM
/set_timezone timezone:America/New_York  # Set timezone
/show_settings            # View current configuration

Server Configuration Steps

  1. Set up notification channel using /set_channel (Required)
  2. Configure role mentions with /set_role (Optional)
  3. Set posting time and timezone (Optional)
  4. Verify settings with /show_settings

Multi-Problem Features

The /problem command supports querying multiple problems at once with enhanced customization:

Overview Mode

When querying multiple problems, the bot displays:

  • Grouped Display: Problems organized in groups of 5 per field
  • Problem Links: Direct clickable links to LeetCode problems
  • Difficulty Indicators: Color-coded emojis (๐ŸŸข Easy, ๐ŸŸก Medium, ๐Ÿ”ด Hard)
  • Problem Stats: Rating and acceptance rate when available
  • Interactive Buttons: Click numbered buttons to view detailed problem information

Customization Options

  • Custom Title: Replace the default title with your own (max 100 characters)
  • Personal Message: Add notes, study plans, or context (max 500 characters)
  • User Attribution: Shows your name and avatar when title or message is provided

Example Use Cases

# Study plan organization
/problem problem_ids:70,322,518 title:๐Ÿ“š Dynamic Programming Week 1 message:Focus on bottom-up approach

# Contest preparation
/problem problem_ids:1,15,42 title:๐Ÿ† Weekly Contest #420 Prep message:Practice these before Sunday

# Topic-based practice
/problem problem_ids:104,226,543 title:๐ŸŒณ Binary Tree Fundamentals message:Master tree traversal first

๐Ÿ—บ๏ธ Development Roadmap

  • ๐ŸŽฎ Enhanced Command Interface
    • Add slash command prompts
    • Reply in the same channel where slash commands are used
    • Add /problem command for querying problems by ID
    • Enhanced /problem command with multi-problem support and customization
    • Add /recent command for viewing user submissions
    • Support historical daily challenges with date parameter
  • โš™๏ธ Advanced Configuration System
    • Allow admin users to set the configuration
      • Set the channel to post the daily challenge
      • Set the posting time and timezone
      • Set the role to mention
      • Set customizable message templates
      • Integrate the existing excessive setup instructions
      • More flexible notification settings
  • ๐ŸŒ Multi-server Infrastructure
    • Support server-specific configurations
  • ๐Ÿ“ Code Optimization
    • Implement improved runtime logging
    • Implement modular architecture
    • Add comprehensive documentation
  • ๐Ÿ‡จ๐Ÿ‡ณ LeetCode.cn Integration
    • Add slash command /daily_cn for LeetCode.cn daily challenge
    • Implement separate scheduler for LeetCode.cn challenges
  • ๐Ÿ—„๏ธ Database Integration
    • Store and query problem information in database
    • Enable historical daily challenge lookup
  • ๐Ÿ” Large Language Model Integration
    • Integrate LLM to generate problem translation and inspiration
    • Cache LLM results to improve performance
  • ๐Ÿ“Š User Engagement Features
    • Track submission records of specific users
    • Interactive navigation for viewing multiple submissions
    • Paginated display with clean UI
    • Allow users to configure tracked LeetCode accounts
    • Implement server-wide submission leaderboards
  • ๐Ÿณ Containerization Support
    • Add Docker compose file and image
  • ๐ŸŒ Internationalization
    • Support multiple display languages

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

๐Ÿ“ฆ Dependencies

๐Ÿ“„ License

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

About

A modern Discord bot that automatically fetches and shares LeetCode daily challenges

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages