Skip to content

Development Setup

Garot Conklin edited this page Dec 8, 2024 · 1 revision

Development Setup

Overview

This guide provides step-by-step instructions for setting up the fleXRPL Discord Bot development environment.

Prerequisites

Required Software

  • Python 3.11+
  • Git
  • Docker (optional, for containerized development)
  • ngrok (for local webhook testing)

Required Accounts

  • GitHub Account
  • Discord Developer Account
  • Railway.app Account (for deployment)

Initial Setup

1. Clone Repository

git clone https://github.com/fleXRPL/flexrpl-discord-bot.git
cd flexrpl-discord-bot

2. Python Environment

# Create virtual environment
python -m venv venv

# Activate virtual environment
# On Unix/macOS:
source venv/bin/activate
# On Windows:
.\venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt
pip install -r requirements-dev.txt

3. Environment Configuration

# Copy example environment file
cp .env.example .env

# Edit .env with your configuration:
DISCORD_BOT_TOKEN=your_bot_token
GITHUB_WEBHOOK_SECRET=your_webhook_secret
ENVIRONMENT=development

Discord Bot Setup

1. Create Discord Application

  1. Visit Discord Developer Portal
  2. Click "New Application"
  3. Configure basic settings:
    • Name: fleXRPL Bot (Dev)
    • Description: Development instance of fleXRPL Bot
    • Icon: Upload bot avatar

2. Bot Configuration

  1. Navigate to "Bot" section
  2. Click "Add Bot"
  3. Configure bot settings:
    • Public Bot: Disabled (during development)
    • Presence Intent: Enabled
    • Server Members Intent: Enabled
    • Message Content Intent: Enabled

3. Get Bot Token

  1. Click "Reset Token"
  2. Copy token to .env file:
    DISCORD_BOT_TOKEN=your_token_here
    

Development Tools

Code Quality Tools

# Install development tools
pip install black flake8 isort pytest pytest-asyncio pytest-cov

# Format code
black .

# Sort imports
isort .

# Run linter
flake8

Pre-commit Hooks

# Install pre-commit
pip install pre-commit

# Install git hooks
pre-commit install

Testing Setup

1. Configure Test Environment

# Create test configuration
cp tests/config.example.py tests/config.py

# Edit test configuration with test bot token and test guild ID

2. Run Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=src

# Run specific test file
pytest tests/test_bot.py

Local Development

Running the Bot

# Start the bot
python src/bot/main.py

Webhook Testing

# Start ngrok
ngrok http 8000

# Configure GitHub webhook with ngrok URL

IDE Configuration

VSCode Settings

{
    "python.linting.enabled": true,
    "python.linting.flake8Enabled": true,
    "python.formatting.provider": "black",
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
        "source.organizeImports": true
    }
}

PyCharm Settings

  • Enable Black formatter
  • Configure Flake8 linter
  • Set up pytest as test runner

Docker Development (Optional)

Build Container

# Build development container
docker build -f Dockerfile.dev -t flexrpl-bot-dev .

# Run container
docker run -it --env-file .env flexrpl-bot-dev

Common Issues

Troubleshooting

  1. Bot Token Issues

    • Verify token in .env
    • Check Discord Developer Portal
    • Regenerate token if needed
  2. Dependency Conflicts

    • Clear virtual environment
    • Reinstall dependencies
    • Check version compatibility
  3. Permission Issues

    • Verify bot permissions
    • Check Discord server roles
    • Review OAuth2 scopes

Development Workflow

Best Practices

  1. Create feature branch
  2. Write tests first
  3. Implement feature
  4. Run quality checks
  5. Submit pull request

Git Workflow

# Create feature branch
git checkout -b feature/new-feature

# Make changes and commit
git add .
git commit -m "feat: add new feature"

# Push changes
git push origin feature/new-feature

Additional Resources

Documentation

Community


This documentation is maintained by the fleXRP team.

Clone this wiki locally