Refactor: remove unused cogs and services, simplify architecture

- Remove admin.py and search.py cogs
- Remove searxng.py service and rate_limiter.py utility
- Update bot.py, ai_chat.py, config.py, and ai_service.py
- Update documentation and docker-compose.yml
This commit is contained in:
2026-01-11 18:41:23 +01:00
parent 0607b05e3b
commit b05fa034a6
14 changed files with 182 additions and 801 deletions

206
README.md
View File

@@ -1,89 +1,128 @@
# Daemon Boyfriend
# Discord AI Bot
A Discord bot for the MSC group with multi-provider AI chat and SearXNG web search.
A customizable Discord bot that responds to @mentions with AI-generated responses. Supports multiple AI providers.
## Features
- **Multi-Provider AI Chat**: Supports OpenAI, OpenRouter, and Anthropic (Claude)
- **Mention-based Chat**: Just @mention the bot to chat
- **Web Search**: Privacy-respecting search via SearXNG
- **Multi-Provider AI**: Supports OpenAI, OpenRouter, and Anthropic (Claude)
- **Fully Customizable**: Configure bot name, personality, and behavior
- **Conversation Memory**: Remembers context per user
- **Rate Limiting**: Prevents abuse
## Commands
| Command | Description |
|---------|-------------|
| `@Daemon Boyfriend <message>` | Chat with the bot |
| `/chat <message>` | Chat via slash command |
| `/search <query>` | Search the web |
| `/image <query>` | Search for images |
| `/clear` | Clear your conversation history |
| `/status` | Show bot status |
| `/help` | Show all commands |
- **Easy Deployment**: Docker support included
## Quick Start
### Prerequisites
### 1. Clone the repository
- Python 3.11+
- Discord bot token ([Discord Developer Portal](https://discord.com/developers/applications))
- AI provider API key (OpenAI, OpenRouter, or Anthropic)
- SearXNG instance (optional, for search)
### Installation
1. Clone the repository:
```bash
git clone https://github.com/your-username/Daemon-Boyfriend.git
cd Daemon-Boyfriend
git clone https://github.com/your-username/discord-ai-bot.git
cd discord-ai-bot
```
2. Create a virtual environment:
```bash
python -m venv .venv
source .venv/bin/activate # Linux/Mac
# or: .venv\Scripts\activate # Windows
```
### 2. Configure the bot
3. Install dependencies:
```bash
pip install -r requirements.txt
```
4. Configure the bot:
```bash
cp .env.example .env
# Edit .env with your tokens
```
5. Run the bot:
Edit `.env` with your settings (see [Configuration](#configuration) below).
### 3. Run with Docker
```bash
docker compose up -d
```
Or run locally:
```bash
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python -m daemon_boyfriend
```
## Configuration
Edit `.env` to configure the bot:
All configuration is done via environment variables in `.env`.
### Required Settings
| Variable | Description |
|----------|-------------|
| `DISCORD_TOKEN` | Your Discord bot token |
| `AI_PROVIDER` | `openai`, `openrouter`, or `anthropic` |
| `OPENAI_API_KEY` | OpenAI API key (if using OpenAI) |
| `OPENROUTER_API_KEY` | OpenRouter API key (if using OpenRouter) |
| `ANTHROPIC_API_KEY` | Anthropic API key (if using Anthropic) |
### Bot Identity
| Variable | Default | Description |
|----------|---------|-------------|
| `BOT_NAME` | `AI Bot` | The bot's display name (used in responses) |
| `BOT_PERSONALITY` | `helpful and friendly` | Personality traits for the AI |
| `BOT_DESCRIPTION` | `I'm an AI assistant...` | Shown when mentioned without a message |
| `BOT_STATUS` | `for mentions` | Status message (shown as "Watching ...") |
| `SYSTEM_PROMPT` | (auto-generated) | Custom system prompt (overrides default) |
### AI Settings
| Variable | Default | Description |
|----------|---------|-------------|
| `AI_MODEL` | `gpt-4o` | Model to use |
| `AI_MAX_TOKENS` | `1024` | Maximum response length |
| `AI_TEMPERATURE` | `0.7` | Response creativity (0.0-2.0) |
| `MAX_CONVERSATION_HISTORY` | `20` | Messages to remember per user |
### Example Configurations
**Friendly Assistant:**
```env
# Required
DISCORD_TOKEN=your_bot_token
# AI Provider (choose one)
AI_PROVIDER=openai # or: openrouter, anthropic
AI_MODEL=gpt-4o
# API Keys (set the one you use)
OPENAI_API_KEY=sk-xxx
OPENROUTER_API_KEY=sk-or-xxx
ANTHROPIC_API_KEY=sk-ant-xxx
# SearXNG (optional)
SEARXNG_BASE_URL=http://localhost:8080
BOT_NAME=Helper Bot
BOT_PERSONALITY=friendly, helpful, and encouraging
BOT_DESCRIPTION=I'm here to help! Ask me anything.
BOT_STATUS=ready to help
```
### AI Providers
**Technical Expert:**
```env
BOT_NAME=TechBot
BOT_PERSONALITY=knowledgeable, precise, and technical
BOT_DESCRIPTION=I'm a technical assistant. Ask me about programming, DevOps, or technology.
BOT_STATUS=for tech questions
```
**Custom System Prompt:**
```env
BOT_NAME=GameMaster
SYSTEM_PROMPT=You are GameMaster, a Dungeon Master for text-based RPG adventures. Stay in character, describe scenes vividly, and guide players through exciting quests. Use Discord markdown for emphasis.
```
## Discord Setup
1. Go to [Discord Developer Portal](https://discord.com/developers/applications)
2. Create a new application
3. Go to **Bot** and create a bot
4. Enable these **Privileged Gateway Intents**:
- Server Members Intent
- Message Content Intent
5. Copy the bot token to your `.env` file
6. Go to **OAuth2****URL Generator**:
- Select scope: `bot`
- Select permissions: `Send Messages`, `Read Message History`, `View Channels`
7. Use the generated URL to invite the bot to your server
## Usage
Mention the bot in any channel:
```
@YourBot what's the weather like?
@YourBot explain quantum computing
@YourBot help me write a poem
```
## AI Providers
| Provider | Models | Notes |
|----------|--------|-------|
@@ -91,53 +130,18 @@ SEARXNG_BASE_URL=http://localhost:8080
| OpenRouter | 100+ models | Access to Llama, Mistral, Claude, etc. |
| Anthropic | claude-3-5-sonnet, claude-3-opus | Direct Claude API |
## Docker Deployment
### With Docker Compose (includes SearXNG)
```bash
cp .env.example .env
# Edit .env with your tokens
docker-compose up -d
```
### Bot Only (external SearXNG)
```bash
docker build -t daemon-boyfriend .
docker run -d --env-file .env daemon-boyfriend
```
## Development
### Project Structure
## Project Structure
```
src/daemon_boyfriend/
├── bot.py # Main bot class
├── config.py # Configuration
├── cogs/ # Command modules
── ai_chat.py # Chat commands
│ ├── search.py # Search commands
── admin.py # Admin commands
├── services/ # External integrations
── ai_service.py # AI provider factory
│ ├── providers/ # AI providers
│ ├── searxng.py # SearXNG client
│ └── conversation.py # Chat history
└── utils/ # Utilities
├── logging.py
├── rate_limiter.py
└── error_handler.py
```
### Running in Development
Set `DISCORD_GUILD_ID` in `.env` for faster command sync during development:
```env
DISCORD_GUILD_ID=123456789012345678
├── cogs/
── ai_chat.py # Mention handler
└── services/
── ai_service.py # AI provider factory
├── providers/ # AI providers
── conversation.py # Chat history
```
## License