A sophisticated Discord bot that provides AI-powered conversations through different personas. Built with Rust, Serenity, and OpenAI integration.
- Multiple Personas: Switch between different AI personalities (Muppet Expert, Chef, Teacher, Analyst)
- User Preferences: Each user can set their default persona
- Rate Limiting: Prevents API abuse with configurable rate limits
- Database Storage: SQLite database for user preferences and usage statistics
- Comprehensive Logging: Detailed logging with configurable levels
- Error Handling: Robust error handling throughout the application
!ping
- Test bot responsiveness/help
- Show help message with all commands/personas
- List available personas and show current persona/set_persona <name>
- Set your default persona/hey <message>
- Chat with your current persona/explain <message>
- Get an explanation/simple <message>
- Get a simple explanation with analogies/steps <message>
- Break something into steps/recipe <food>
- Get a recipe for the specified food
- muppet - Enthusiastic Muppet expert (default)
- chef - Passionate cooking expert
- teacher - Patient teacher who explains things clearly
- analyst - Step-by-step analyst who breaks down complex processes
- Rust (latest stable version)
- Discord Bot Token
- OpenAI API Key
-
Clone the repository:
git clone <repository-url> cd persona
-
Copy the environment file and fill in your credentials:
cp .env.example .env
-
Edit
.env
with your actual tokens:DISCORD_MUPPET_FRIEND=your_discord_bot_token_here OPENAI_API_KEY=your_openai_api_key_here
-
Build and run the bot:
cargo run --bin bot
- Go to Discord Developer Portal
- Create a new application
- Go to the "Bot" section and create a bot
- Copy the token and add it to your
.env
file - Under "Privileged Gateway Intents", enable "Message Content Intent"
- Use the OAuth2 URL generator to invite the bot to your server with appropriate permissions
- Go to OpenAI Platform
- Create a new API key
- Add it to your
.env
file
DISCORD_MUPPET_FRIEND
- Your Discord bot token (required)OPENAI_API_KEY
- Your OpenAI API key (required)DATABASE_PATH
- Path to SQLite database file (optional, defaults to "persona.db")LOG_LEVEL
- Logging level (optional, defaults to "info")
error
- Only errorswarn
- Warnings and errorsinfo
- General information, warnings, and errorsdebug
- Debug information and abovetrace
- All logging information
The bot is structured with the following modules:
config.rs
- Configuration managementdatabase.rs
- SQLite database operationspersonas.rs
- Persona definitions and managementcommands.rs
- Command handling logicrate_limiter.rs
- Rate limiting functionalitybin/bot.rs
- Main bot entry point
The bot uses SQLite with the following tables:
user_preferences
- Stores user's default persona settingsusage_stats
- Tracks command usage for analytics
The bot implements rate limiting to prevent abuse:
- 10 requests per minute per user
- Automatic backoff and user notification when limits are exceeded
The bot includes an audio transcription script (scripts/audio.sh
) that uses OpenAI's Whisper API:
./scripts/audio.sh <path-to-audio-file>
# Build the project
cargo build
# Build in release mode
cargo build --release
# Run the bot
cargo run --bin bot
# Run tests (when implemented)
cargo test
To add a new persona, edit src/personas.rs
and add a new entry to the PersonaManager::new()
function:
personas.insert("your_persona".to_string(), Persona {
name: "Your Persona Name".to_string(),
system_prompt: "Your persona's system prompt here.".to_string(),
description: "Brief description of your persona".to_string(),
});
This project is open source. Please check the license file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request