Skip to content

TheCodeVerseHub/CodeBuddy

Repository files navigation

CodeBuddy Discord Bot

A feature-rich Discord bot designed to enhance coding communities with interactive quizzes, leaderboards, and engagement features.

Features

Interactive Coding Quiz System

  • Automated Questions: Receives coding quiz questions every 20 minutes
  • Multiple Choice Format: Simple a/b/c answer format
  • Bonus Questions: Random 10% chance for double points
  • Real-time Feedback: Instant responses to correct/incorrect answers
  • Streak System: Track consecutive correct answers

Comprehensive Leaderboards

  • Overall Leaderboard (/codeleaderboard): Top performers by total points
  • Weekly Leaderboard (/codeweek): Weekly champions with automatic Monday resets
  • Streak Leaderboard (/codestreak): Best current and all-time streaks

Personal Statistics

  • Individual Stats (/codestats): Personal performance metrics
  • Visual Flex Cards (/codeflex): Beautiful profile cards with stats
  • Rank Tracking: See your position and points to next rank

Visual Elements

  • Custom gradient text effects
  • Hexagonal avatar displays
  • Rich Discord embeds
  • Professional stat cards

Commands

Command Description Usage
/codeleaderboard Show top 10 players by total points /codeleaderboard
/codeweek Display weekly leaderboard (resets Mondays) /codeweek
/codestreak Show current and best streak leaders /codestreak
/codestats View your personal statistics /codestats
/codeflex Generate a visual profile card /codeflex
/help Get help and command information /help

How to Play

  1. Join the Quiz: Wait for questions to appear in the designated channel
  2. Answer Quickly: Type a, b, or c to answer
  3. Build Streaks: Answer consecutively to build your streak
  4. Compete Weekly: Participate in weekly competitions
  5. Check Stats: Use commands to track your progress

Setup & Installation

Prerequisites

  • Python 3.8+
  • Discord Bot Token
  • Discord Server with appropriate permissions

Installation Steps

  1. Clone the Repository

    git clone https://github.com/TheCodeVerseHub/CodeBuddy.git
    cd CodeBuddy
  2. Create Virtual Environment

    python -m venv .venv
    source .venv/bin/activate  # Linux/Mac
    # or
    .venv\Scripts\activate     # Windows
  3. Install Dependencies

    pip install -r requirements.txt
  4. Environment Configuration Create a .env file in the root directory:

    DISCORD_BOT_TOKEN=your_bot_token_here
    QUESTION_CHANNEL_ID=your_channel_id_here
  5. Run the Bot

    python main.py

Environment Variables

Variable Description Required
DISCORD_BOT_TOKEN Your Discord bot token from Discord Developer Portal
QUESTION_CHANNEL_ID Channel ID where quiz questions will be posted

Architecture

Project Structure

codebuddyserver/
├── main.py                 # Bot entry point and configuration
├── database.py             # Database operations and management
├── codingquestions.py      # Question bank and retrieval
├── requirements.txt        # Python dependencies
├── .env                    # Environment variables (create this)
├── cogs/
│   ├── quiz_cog.py         # Quiz functionality and main leaderboard
│   ├── flex_cog.py         # Visual profile cards
│   ├── leaderboard_cog.py  # Weekly and streak leaderboards
│   └── __pycache__/        # Python cache files
├── assets/
│   └── fonts/              # Custom fonts for visual elements
└── __pycache__/            # Python cache files

Technology Stack

  • Discord.py 2.6+: Modern Discord API wrapper with slash command support
  • SQLite + aiosqlite: Lightweight async database for user data
  • Pillow (PIL): Image processing for flex cards
  • Python-dotenv: Environment variable management

Database Schema

leaderboard Table

  • user_id (INTEGER): Discord user ID
  • correct_answers (INTEGER): Total correct answers
  • streak (INTEGER): Current streak
  • best_streak (INTEGER): All-time best streak
  • last_answer_date (TEXT): Date of last activity

weekly_leaderboard Table

  • user_id (INTEGER): Discord user ID
  • correct_answers (INTEGER): Weekly correct answers
  • week_start (TEXT): Week start date (Monday)

Features in Detail

Quiz System

  • Automatic Posting: Questions appear every 20 minutes
  • Fair Play: Users can only answer once per question
  • Bonus System: 10% chance for double points
  • Streak Mechanics: Reset on wrong answers, continue on correct ones

Leaderboard Types

  1. Overall: All-time performance ranking
  2. Weekly: Current week performance (Monday-Sunday)
  3. Streak: Current streaks and personal bests

Visual Elements

  • Gradient Text: Beautiful color transitions
  • Hexagonal Avatars: Unique profile picture framing
  • Rich Embeds: Professional Discord message formatting
  • Progress Indicators: Visual representation of stats

Configuration

Bot Permissions Required

  • Send Messages
  • Use Slash Commands
  • Embed Links
  • Read Message History
  • Add Reactions

Customization Options

  • Question Timer: Modify interval in quiz_cog.py (@tasks.loop(minutes=20))
  • Bonus Chance: Adjust probability in quiz logic
  • Visual Themes: Customize colors in flex card generation
  • Database: Easily extendable for additional features

Performance Features

Optimization

  • Async Database Operations: Non-blocking database queries
  • Cached User Lookups: Efficient Discord user resolution
  • Immediate Response Pattern: Prevents Discord interaction timeouts
  • Memory Efficient: Minimal resource usage

Reliability

  • Error Handling: Comprehensive exception management
  • Auto-reconnection: Automatic restart on connection issues
  • Data Validation: Input sanitization and validation
  • Graceful Degradation: Continues operation if non-critical features fail

Contributing

We welcome contributions! Here's how to get started:

  1. Fork the Repository
  2. Create Feature Branch: git checkout -b feature/amazing-feature
  3. Commit Changes: git commit -m 'Add amazing feature'
  4. Push to Branch: git push origin feature/amazing-feature
  5. Open Pull Request

Development Guidelines

  • Follow existing code style and patterns
  • Add appropriate error handling
  • Test features thoroughly before submitting
  • Update documentation as needed

License

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

Troubleshooting

Common Issues

Bot not responding to commands:

  • Verify bot permissions in Discord server
  • Check if slash commands are synced (/help should appear)
  • Ensure bot token is correct in .env

Questions not posting:

  • Verify QUESTION_CHANNEL_ID is correct
  • Check bot has send message permissions in target channel
  • Review console for error messages

Database errors:

  • Ensure write permissions in project directory
  • Check for corrupted database file
  • Restart bot to reinitialize database

Debug Mode

Enable debug logging by adding print statements or using Python's logging module for detailed troubleshooting.

Roadmap

  • Custom question categories
  • Team-based competitions
  • Achievement system
  • Web dashboard for statistics
  • Integration with coding platforms
  • Multi-server support
  • Advanced analytics

Support


Made with by TheCodeVerseHub

Enhance your coding community with CodeBuddy - where learning meets competition!

About

A discord bot That shares helpful programming questions every 20 mins.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •