Skip to main content

A Discord bot that monitors channels and publishes content to social media

Project description

discopilot

CI codecov PyPI version License: Apache 2.0 Python 3.9+

A Discord bot that monitors channels and publishes content to social media platforms.

Features

  • 🤖 Monitor Discord channels for specific emoji reactions
  • 📢 Publish messages to Twitter (X) and other social media platforms
  • 🔄 Smart rate limiting to prevent API throttling
  • 🧙‍♂️ Named after Hedwig from Harry Potter - your magical messenger

Installation

From PyPI

pip install discopilot

From Source

git clone https://github.com/twinko-ai/discopilot.git
cd discopilot
uv venv .venv
source .venv/bin/activate
uv pip install -e .

Configuration

DiscoPilot requires a configuration file to run. You can set up your configuration in one of these ways:

  1. Automatic setup:

    discopilot-setup
    

    This will create a configuration file at ~/.config/discopilot/config.yaml.

  2. Manual setup:

    • Copy the example configuration from examples/config.example.yaml
    • Place it in one of these locations:
      • The current working directory as config.yaml
      • Your home directory at ~/.config/discopilot/config.yaml
    • Edit the file with your Discord token and other settings
  3. Environment variable:

    • Set the DISCOPILOT_CONFIG environment variable to the path of your config file
    export DISCOPILOT_CONFIG=/path/to/your/config.yaml
    

Configuration Options

Option Description Required
discord.token Your Discord bot token Yes
discord.server_ids List of server IDs the bot should listen to (empty = all servers) No
admin_ids List of Discord user IDs that can trigger publishing Yes
triggers.emoji The emoji that triggers publishing No (default: 📢)
twitter.api_key Twitter API key Yes (for Twitter)
twitter.api_secret Twitter API secret Yes (for Twitter)
twitter.access_token Twitter access token Yes (for Twitter)
twitter.access_secret Twitter access token secret Yes (for Twitter)
twitter.bearer_token Twitter bearer token Yes (for Twitter)

Usage

  1. Invite your bot to your Discord server using the OAuth2 URL from the Discord Developer Portal.

  2. Send a message in any channel where the bot has access.

  3. React to the message with the configured emoji (default: 📢). Note: Only users listed in admin_ids can trigger publishing.

  4. The bot will publish the message to configured social media platforms and reply with the results.

Running on a Server (24/7)

Using Systemd (Linux)

  1. Create a systemd service file:

    sudo nano /etc/systemd/system/discopilot.service
    
  2. Add the following content (adjust paths as needed):

    [Unit]
    Description=DiscoPilot Discord Bot
    After=network.target
    
    [Service]
    User=yourusername
    WorkingDirectory=/path/to/working/directory
    ExecStart=/path/to/python -m discopilot.scripts.run_bot
    Restart=always
    RestartSec=10
    StandardOutput=syslog
    StandardError=syslog
    SyslogIdentifier=discopilot
    
    [Install]
    WantedBy=multi-user.target
    
  3. Enable and start the service:

    sudo systemctl daemon-reload
    sudo systemctl enable discopilot
    sudo systemctl start discopilot
    

Using Docker

  1. Create a Dockerfile:

    FROM python:3.11-slim
    
    WORKDIR /app
    
    COPY . .
    RUN pip install -e .
    
    CMD ["python", "-m", "discopilot.scripts.run_bot"]
    
  2. Build and run:

    docker build -t discopilot .
    docker run -d --name discopilot --restart unless-stopped \
      -v /path/to/config.yaml:/root/.config/discopilot/config.yaml discopilot
    

Extending

Adding New Social Media Platforms

  1. Create a new publisher class in discopilot/publishers/
  2. Implement the publish() and check_rate_limit() methods
  3. Add your publisher to the bot's setup_publishers() method

Development

Running Tests

# Install development dependencies
uv pip install -e ".[dev]"

# Run tests
pytest

# Run with coverage
pytest --cov=discopilot

Deployment

AWS Lightsail Deployment

To deploy DiscoPilot on AWS Lightsail:

  1. Go to the AWS Lightsail console
  2. Click "Create instance"
  3. Choose a location (AWS Region) close to you
  4. Select "Linux/Unix" platform
  5. Choose "Ubuntu 24.04 LTS" as the blueprint
  6. Click "Add launch script" and paste the content of scripts/deployment/lightsail_launch.sh
  7. Use default SSH key or create a new one
  8. Enable automatic snapshots
  9. Select network type
  10. Select the instance plan like $5/month
  11. Name your instance (e.g., "discopilot")
  12. Click "Create instance"

After the instance is created:

  1. Connect to your instance via SSH
  2. Update the configuration file:
    edit-config
    
    or
    sudo nano /home/botuser/.config/discopilot/config.yaml
    
  3. Start the service:
    sudo systemctl start discopilot
    

Maintenance Commands

The following commands are available after deployment:

  • update-bot: Pull the latest code from GitHub, update scripts, reinstall dependencies, and restart the bot
  • restart-bot: Restart the bot without updating
  • bot-logs: View the bot's logs in real-time
  • edit-config: Edit the bot configuration file

Manual Script Usage

If you prefer to run the scripts directly instead of using the aliases:

  • /usr/local/bin/update_discopilot.sh: Update the bot from GitHub and restart
  • /usr/local/bin/restart_discopilot.sh: Restart the bot without updating
  • /usr/local/bin/run_discopilot.sh: Run the bot manually (used by the systemd service)
  • /usr/local/bin/update-discopilot-scripts.sh: Update the scripts in /usr/local/bin with the latest versions from the repository

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

discopilot-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

discopilot-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file discopilot-0.1.0.tar.gz.

File metadata

  • Download URL: discopilot-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for discopilot-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7ead4d6f5c3db391bbd69cf6048bfe4ddd253d2a42e055de03f0b5c81ff1c117
MD5 a68f4f36d89a31e6b5b2143d608e8016
BLAKE2b-256 10aca44a69f07197785cb946850cb93331d562a33dafe9fb821c609063f4c18e

See more details on using hashes here.

File details

Details for the file discopilot-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: discopilot-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for discopilot-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 697897b0ae2cd414332674a902719550798c53ad8604941b1c8acd444915c360
MD5 c4d2a917a4ef398b8cf4d157467fc28c
BLAKE2b-256 5d6340e4437f68b89e7f7178c50a1ef6d8c391af6b87e8cfc776f771c41a7e24

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page