Skip to content

jeffcampbell/quote-bot

Repository files navigation

Discord Quote Bot

A modern Discord bot that creates memes, engages in conversations using OpenAI, and generates Magic: The Gathering cards with AI-powered art.

Features

  • Meme Generation: React with 😂 to any message to create a meme using Imgflip API
  • AI Conversations: Mention the bot or DM it for intelligent conversations powered by OpenAI
  • MTG Card Creation: Use !card <description> to generate custom Magic: The Gathering cards with art
  • Mood System: Set server-specific bot personalities with !mood <mood>

Requirements

  • Python 3.9+
  • Discord Bot Token
  • OpenAI API Key
  • Imgflip Account (optional, for meme generation)

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd quote-bot
  2. Install dependencies:

    pip install -r requirements.txt
  3. Configure environment variables:

    cp .env.example .env

    Edit .env and fill in your credentials:

    • DISCORD_BOT_TOKEN: Your Discord bot token
    • OPENAI_API_KEY: Your OpenAI API key
    • IMGFLIP_USERNAME: Your Imgflip username (optional)
    • IMGFLIP_PASSWORD: Your Imgflip password (optional)
  4. Run the bot:

    python main.py

Raspberry Pi Setup

This bot is optimized for Raspberry Pi 3 and ARM processors:

  1. Install Python 3.9+:

    sudo apt update
    sudo apt install python3.9 python3.9-pip python3.9-venv
  2. Create virtual environment:

    python3.9 -m venv venv
    source venv/bin/activate
  3. Install dependencies (may take longer on ARM):

    pip install --upgrade pip
    pip install -r requirements.txt
  4. Create systemd service for auto-start:

    sudo nano /etc/systemd/system/quote-bot.service

    Add:

    [Unit]
    Description=Discord Quote Bot
    After=network.target
    
    [Service]
    Type=simple
    User=pi
    WorkingDirectory=/home/pi/quote-bot
    Environment=PATH=/home/pi/quote-bot/venv/bin
    ExecStart=/home/pi/quote-bot/venv/bin/python main.py
    Restart=always
    RestartSec=10
    
    [Install]
    WantedBy=multi-user.target

    Enable and start:

    sudo systemctl enable quote-bot.service
    sudo systemctl start quote-bot.service

Usage

Basic Commands

  • Meme Generation: React with 😂 to any text message
  • General Chat: Mention the bot (@BotName) or send a DM
  • Set Mood: @BotName !mood <personality> (e.g., "!mood sarcastic and witty")
  • Generate MTG Card: @BotName !card <description> (e.g., "!card a small goblin warrior")

Examples

@QuoteBot !mood friendly and helpful
@QuoteBot !card a legendary dragon that breathes fire and controls the weather
@QuoteBot What's the weather like today?

Project Structure

quote-bot/
├── main.py              # Entry point
├── config.py            # Configuration management
├── bot.py               # Main Discord bot class
├── database.py          # Database operations
├── meme_generator.py    # Imgflip meme generation
├── openai_service.py    # OpenAI API integration
├── card_formatter.py    # MTG card ASCII formatting
├── tests/               # Unit tests
├── requirements.txt     # Python dependencies
├── .env.example         # Environment variables template
└── README.md           # This file

Development

Running Tests

# Install test dependencies
pip install -r requirements.txt

# Run all tests
pytest

# Run specific test file
pytest tests/test_database.py

# Run with coverage
pytest --cov=. tests/

Code Style

The project follows Python best practices:

  • Type hints for better code documentation
  • Async/await for Discord.py compatibility
  • Proper error handling and logging
  • Modular design for maintainability

Adding Features

  1. Create new modules in the root directory
  2. Add corresponding tests in tests/
  3. Update configuration in config.py if needed
  4. Import and integrate in bot.py

Troubleshooting

Common Issues

  1. Import errors: Ensure all dependencies are installed with pip install -r requirements.txt
  2. Permission errors: Bot needs proper Discord permissions (Send Messages, Read Message History, Add Reactions)
  3. API errors: Check that API keys are valid and have sufficient credits/quota
  4. Database errors: Ensure write permissions in the bot directory

Logs

Check logs for debugging:

tail -f logs.log

For systemd service on Raspberry Pi:

sudo journalctl -u quote-bot.service -f

Discord Permissions

The bot requires these permissions:

  • Send Messages
  • Read Message History
  • Add Reactions
  • Use Slash Commands (future)
  • Attach Files
  • Embed Links

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all tests pass
  5. Submit a pull request

License

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

Support

For issues and questions:

  1. Check the troubleshooting section
  2. Review the logs
  3. Create an issue on GitHub with relevant log excerpts

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published