A Telegram bot written in Go to manage daily LeetCode challenges in Telegram groups.
- 🌅 Daily Challenge: Automatically posts a random LeetCode challenge at 7 AM on weekdays (Monday-Friday)
- 📊 Day Counter: Counts challenge days starting from Day 9
- 📝 Submit Command: Allows users to submit when they complete a challenge
- 🏆 Leaderboard: Displays rankings based on the number of completed challenges
- ⏰ Reminders: Automatically reminds users who haven't submitted at 3 PM and 10 PM (weekdays only)
- 🎉 Weekend Break: No challenges on Saturday and Sunday
- 🗄️ SQLite Database: Stores user information, challenges, and submissions
- 🐳 Docker Support: Easy deployment with Docker
/submit- Submit today's challenge/leaderboards- View the leaderboard/help- Display help information
- Go 1.21+
- SQLite3
- Telegram Bot Token
- Telegram Group ID
git clone <repository-url>
cd leetcode-telegram-botCopy the env.example file to .env and update the values:
cp env.example .envEdit the .env file:
TELEGRAM_BOT_TOKEN=your_bot_token_here
TELEGRAM_GROUP_ID=your_group_id_here
DATABASE_PATH=leetcode_bot.db
PROBLEMS_FILE_PATH=problem_deduplicated.yaml
TIMEZONE=Asia/Ho_Chi_MinhOption 1: Docker Compose (Easiest)
# Create .env file
echo "TELEGRAM_BOT_TOKEN=your_token_here" > .env
echo "TELEGRAM_GROUP_ID=your_group_id" >> .env
# Build and run
docker-compose up -d
# View logs
docker-compose logs -fOption 2: Multi-Architecture Build
# For Apple Silicon (ARM) and Intel (AMD64)
chmod +x build-multiarch.sh
./build-multiarch.sh
# Or ARM64 only
chmod +x build-arm.sh
./build-arm.shOption 3: Manual Docker Build
# Build for ARM64 (Apple Silicon)
docker build --platform linux/arm64 -t leetcode-telegram-bot .
# Run
docker run -d --name leetcode-bot \
-e TELEGRAM_BOT_TOKEN="your_token" \
-e TELEGRAM_GROUP_ID="your_group_id" \
-v $(pwd)/data:/data \
leetcode-telegram-bot# Download dependencies
go mod download
# Build
go build -o main .
# Run
./mainleetcode-telegram-bot/
├── main.go # Entry point
├── internal/
│ ├── bot/ # Telegram bot logic
│ │ └── bot.go
│ ├── config/ # Configuration management
│ │ └── config.go
│ ├── database/ # Database operations
│ │ └── database.go
│ ├── models/ # Data models
│ │ └── models.go
│ └── scheduler/ # Cron job scheduler
│ └── scheduler.go
├── problem_deduplicated.yaml # LeetCode problems data
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose configuration
└── README.md # This file
- Create a new bot with @BotFather
- Send
/newbotand follow the instructions - Save the provided token
- Add the bot to your group
- Send any message in the group
- Visit:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates - Look for
"chat":{"id":in the response - that's your Group ID
The bot uses SQLite with the following tables:
problems: Stores LeetCode problemsusers: Telegram user informationsubmissions: User submissionsdaily_challenges: Daily challenges with day counterchallenge_counter: Stores the current day number (starting from 9)
- 07:00 (Mon-Fri): Post daily challenge (starting from Day 9)
- 15:00 (Mon-Fri): Afternoon reminder
- 22:00 (Mon-Fri): Evening reminder
- Weekend: No challenges posted
Edit the problem_deduplicated.yaml file following the existing format:
# Add your problems here following the existing structure