This document outlines the comprehensive rewrite of the Discord Super Pal of the Week bot, including core functionality testing and code quality improvements.
- Slash command
/superpal @user- Current super pal promotes another user - Legacy command
!spotw @user- Same functionality with older syntax - Validates that new super pal doesn't already have the role
- Automatically removes role from previous super pal
- Runs every Sunday at noon (bot's timezone)
- Randomly selects a new super pal from non-bot members
- Avoids duplicate selections (re-rolls if same person chosen)
- Automatically removes old super pal and promotes new one
!spinthewheelcommand triggers external wheel bot- Listens for wheel bot's result message
- Automatically promotes the winner chosen by the wheel
/surprise <description>- Slash command version!surprise <description>- Legacy command version- Generates 4 images based on text prompt
- Handles safety rejections and billing errors gracefully
!cacaw- Sends 50 party parrot emojis!meow- Sends 50 party cat emojis!karatechop- Randomly moves a voice channel user to AFK!commands- Lists all available commands
- GPT-3.5 powered conversational assistant
- Can check if members are super pal
- Thread-based conversation management
- Module-level docstrings for all files
- Function/method docstrings with Args, Returns, and Raises sections
- Inline comments for complex logic
- Type hints throughout the codebase
- Try-catch blocks around all major operations
- Graceful degradation when features are unavailable
- Comprehensive error logging
- User-friendly error messages
- Separated concerns into helper functions
- Reduced code duplication
- Consistent naming conventions
- Logical grouping of related functionality
- Helper functions
get_env()andget_env_int()for environment variables - Proper validation of required vs optional configuration
- Clear error messages for missing configuration
- Console logging in addition to file logging
- All magic strings moved to constants
- Configurable values (emoji count, image size, etc.)
- Single source of truth for role/channel names
- Better error handling for OpenAI API failures
- Validation of input parameters
- Improved timeout handling for GPT assistant
- More robust image generation with detailed error messages
- Fixed karatechop bug - variable was used before being defined
- Helper functions for common operations
- Better guild/channel/role retrieval with null checks
- Improved event handlers with exception handling
- More descriptive logging throughout
Created comprehensive test suite with 30+ tests covering:
tests/__init__.py- Test package initializationtests/conftest.py- Pytest fixtures and configurationtests/test_static.py- Tests for static content moduletests/test_env.py- Tests for environment configurationtests/test_ai.py- Tests for AI integrationtests/test_bot.py- Tests for bot commands and eventspytest.ini- Pytest configurationrequirements-dev.txt- Development dependencies
- Static content validation
- Environment variable loading and validation
- AI image generation (success and error cases)
- GPT assistant functionality
- Role promotion logic
- Weekly task scheduling
- Spin the wheel integration
- Fun commands (cacaw, meow, karatechop)
- Error handling scenarios
-
karatechop command (line 227 in old bot.py)
- Fixed:
chopped_memberwas referenced before being assigned - Now properly defines variable before use
- Fixed:
-
Environment variable fallbacks (env.py)
- Fixed: Improved handling of optional environment variables
- Now uses proper defaults for EMOJI_GUILD_ID and ART_CHANNEL_ID
-
OpenAI image generation (ai.py line 124)
- Fixed: Removed incorrect
awaitkeyword beforeAsyncOpenAI() - Fixed: Changed
response['data']toresponse.datafor proper API access
- Fixed: Removed incorrect
-
Better role checking
- Added null checks for guild, channel, and role lookups
- Prevents crashes when configuration is incorrect
# Install development dependencies
pip install -r requirements-dev.txt
# Run all tests
pytest
# Run with coverage
pytest --cov=src tests/
# Run specific test file
pytest tests/test_bot.py -v# Install dependencies
pip install -r requirements.txt
# Set environment variables (or use .env file)
export SUPERPAL_TOKEN="your_bot_token"
export GUILD_ID="your_guild_id"
export CHANNEL_ID="your_channel_id"
export OPENAI_API_KEY="your_openai_key"
# Run the bot
python3 src/bot.pyAll existing commands and functionality remain intact:
- All slash commands work as before
- All legacy
!commands work as before - Same Discord permissions required
- Same environment variables (with better error handling)
- Add database support - Store super pal history
- Add configuration file - YAML/JSON config in addition to env vars
- Add metrics/analytics - Track command usage
- Add automated testing CI/CD - Run tests on every commit
- Add command cooldowns - Prevent spam
- Add more comprehensive logging - Structured logging with log levels
- Consider migrating to discord.py 2.0 patterns - Use modern async patterns
src/bot.py- Complete rewrite with improvementssrc/superpal/env.py- Added helper functions and better validationsrc/superpal/static.py- Added constants and documentationsrc/superpal/ai.py- Improved error handling and documentationrequirements-dev.txt- New file for test dependenciespytest.ini- New file for test configurationtests/*- New comprehensive test suite
src/bot_old.py- Backup of original implementation- All other project files unchanged