Update CLAUDE.md to reflect current SQLite database architecture

- Document SQLite database system with table structures
- Update commands to match package.json scripts (start, stop, boom, etc.)
- Add comprehensive database configuration flow documentation
- Document auto-registration system for public bot distribution
- Update Docker setup details (Node 20, npm usage, persistence)
- Add guild management and soft delete system documentation
- Document hybrid configuration system (database + file fallback)
- Update architecture with all new services and components

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Chris Ham
2025-08-16 14:21:24 -07:00
parent c2962bac16
commit fd68a02503

122
CLAUDE.md
View File

@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
## Project Overview ## Project Overview
This is a Discord bot built with discord.js v14 that provides sound effects (both prefix and slash commands), text commands, fun facts, and scheduled events functionality for Discord servers. This is a modern Discord bot built with Discord.js v14 that provides sound effects (both prefix and slash commands), text commands, fun facts, and scheduled events functionality for Discord servers. The bot uses SQLite database for dynamic guild configuration management and is designed for public distribution.
## Development Commands ## Development Commands
@@ -14,16 +14,17 @@ This is a Discord bot built with discord.js v14 that provides sound effects (bot
# Install dependencies # Install dependencies
pnpm install pnpm install
# Direct Node.js execution (requires Node 22 LTS) # Local Node.js execution (requires Node 20+ LTS)
pnpm start # Production mode pnpm dev # Development mode with auto-reload
pnpm dev # Development mode with auto-reload pnpm start:prod # Production mode (local Node.js)
# Docker Compose (recommended) # Docker Compose (recommended for production)
pnpm up # Start bot with Docker Compose pnpm start # Start bot with Docker Compose
pnpm down # Stop bot pnpm stop # Stop bot
pnpm restart # Restart bot (useful after config changes) pnpm restart # Restart bot (useful after config changes)
pnpm logs # View logs pnpm logs # View logs
pnpm build # Rebuild image pnpm build # Rebuild image
pnpm boom # Quick rebuild and restart
# Direct Docker (alternative) # Direct Docker (alternative)
pnpm image:build # Build Docker image pnpm image:build # Build Docker image
@@ -34,9 +35,9 @@ pnpm image:run # Run Docker container with auto-restart
```bash ```bash
# Docker Compose approach (recommended) # Docker Compose approach (recommended)
pnpm up && pnpm logs # Start and follow logs pnpm start && pnpm logs # Start and follow logs
pnpm restart # Restart after config changes pnpm restart # Restart after config changes
pnpm build && pnpm up # Rebuild after code changes pnpm boom # Quick rebuild and restart after code changes
# Direct Docker approach # Direct Docker approach
docker stop discord-bot && docker rm discord-bot docker stop discord-bot && docker rm discord-bot
@@ -48,60 +49,91 @@ pnpm image:build && pnpm image:run
### Core Structure ### Core Structure
- **src/index.js**: Main bot entry point with Discord.js v14 client - **src/index.js**: Main bot entry point with Discord.js v14 client and event handlers
- **src/config/**: Configuration management - **src/config/**: Configuration management
- `config.js`: Config loader and validator - `config.js`: Hybrid config manager (SQLite database + file fallback)
- `intents.js`: Discord gateway intents - `intents.js`: Discord gateway intents
- **src/commands/**: - **src/commands/**:
- `prefix/`: Traditional prefix commands (!sfx, !funfact, etc.) - `prefix/`: Traditional prefix commands (!sfx, !funfact, !hamfact, !role, !dance, !join, !leave, !reboot)
- `slash/`: Slash commands (/sfx with autocomplete) - `slash/`: Modern slash commands (/sfx with autocomplete, /config with subcommands)
- **src/services/**: - **src/services/**:
- `databaseService.js`: SQLite database operations and guild management
- `voiceService.js`: Voice connections using @discordjs/voice - `voiceService.js`: Voice connections using @discordjs/voice
- `commandLoader.js`: Static/Ankhbot command loader - `commandLoader.js`: Static/Ankhbot command loader with hot-reload
- `sfxManager.js`: Sound effect file management - `sfxManager.js`: Sound effect file management and caching
- `schedulerService.js`: Scheduled events handler - `schedulerService.js`: Scheduled events handler with timezone support
- **src/utils/**: Helper functions - **src/utils/**: Helper functions (randElement, chunkSubstr, etc.)
- **config.json**: Bot configuration (copy from config.json.example) - **data/**: SQLite database directory (auto-created, mounted in Docker)
### Database System
**SQLite Database (data/ghbot.db):**
- **guilds table**: Per-server configurations with soft delete support
- **scheduled_events table**: Cron jobs with JSON schedule storage
- **bot_config table**: Global bot settings (activities, admin, blacklist)
**Configuration Flow:**
1. **Database primary**: Live configurations stored in SQLite
2. **File fallback**: config.json used for initial seeding and token storage
3. **Auto-migration**: Existing config.json guilds imported on first run
4. **Live updates**: `/config` slash commands update database directly
### Command System ### Command System
Commands are handled in priority order: Commands are handled in priority order:
1. Native commands (defined in index.js commands object) 1. **Prefix commands**: Modular commands in src/commands/prefix/
2. Static text commands (from conf/text_commands) 2. **Static text commands**: From conf/text_commands (pipe-delimited with aliases)
3. Ankhbot imported commands (from conf/ghbot.abcomg) 3. **Ankhbot commands**: From conf/ghbot.abcomg (legacy format support)
### Sound Effects System ### Sound Effects System
- Sound files stored in `sfx/` directory as .mp3 or .wav - **Dual interfaces**: Both !sfx prefix command and /sfx slash command with autocomplete
- Automatically discovered on startup and directory changes - **Auto-discovery**: Sound files in sfx/ directory (.mp3/.wav) automatically available
- Requires voice channel connection and ffmpeg (included in Docker image) - **Voice integration**: @discordjs/voice with connection pooling and cleanup
- Volume and audio passes configurable per guild - **Configuration**: Volume and allowed channels configurable per guild via database
### Guild Management
**Auto-Registration System:**
- **GuildCreate event**: New guilds get default config + welcome message
- **GuildDelete event**: Soft delete preserves settings for re-invite
- **Welcome messages**: Different messages for new vs returning guilds
- **Slash command registration**: Automatic per-guild registration
### Configuration Files ### Configuration Files
- **conf/text_commands**: Pipe-delimited text commands with alias support - **conf/text_commands**: Pipe-delimited text commands with alias support
- **conf/funfacts & conf/hamfacts**: Line-separated fact collections - **conf/funfacts & conf/hamfacts**: Line-separated fact collections with hot-reload
- **conf/snesgames.json**: SNES game database (purpose unclear from current usage) - **conf/ghbot.abcomg**: Ankhbot command database (JSON format, legacy eval support)
- **config.json**: Initial configuration and bot token (optional after seeding)
### Scheduled Events ### Scheduled Events
Configured per guild in config.json with cron-style scheduling using node-schedule. Events can: **Storage**: Database with JSON schedule format support
- Send messages to specific channels **Formats**:
- Ping specific roles - Object format: `{"hour": 7, "minute": 30, "tz": "America/Los_Angeles"}`
- Run on cron schedules - Cron format: `"0 9 * * *"`
**Features**: Timezone support, role pings, channel targeting
### Docker Setup ### Docker Setup
Uses Node 22-alpine base image with ffmpeg for audio processing. The Dockerfile installs all dependencies and runs the bot with `node src/index.js`. - **Base image**: Node 20 full Debian (for better SQLite compatibility)
- **Package manager**: npm for Docker builds (bypasses pnpm security restrictions)
- **Multi-stage**: Single-stage build for simplicity and reliability
- **Persistence**: data/ volume for SQLite database
- **Dependencies**: All audio libraries and native modules properly compiled
## Important Implementation Details ## Important Implementation Details
- Discord.js v14 with modern API patterns - **Discord.js v14** with modern API patterns and explicit intents
- @discordjs/voice for audio playback - **@discordjs/voice** for audio playback with connection pooling
- Hybrid command system: prefix commands + slash command for SFX - **SQLite database** with better-sqlite3 for persistent configuration
- /sfx slash command with autocomplete for easy sound discovery - **Hybrid command system**: Traditional prefix commands + modern slash commands
- Hot-reloads configuration files and commands without restart - **Auto-registration**: Public bot ready - automatically configures new guilds
- Supports multiple guilds with individual configurations - **Soft delete system**: Guild settings preserved when bot is removed/re-added
- Admin commands restricted by Discord user ID - **Live configuration**: `/config` slash commands for real-time settings updates
- Blacklist system for blocking specific users - **Hot-reload**: Static commands and facts reload without restart
- Proper voice connection pooling and cleanup - **Voice system**: Modern @discordjs/voice with proper cleanup and error handling
- **Admin permissions**: Configuration changes require Administrator Discord permission
- **Logging**: Comprehensive logging for commands, SFX usage, and system events
- **Error handling**: Graceful handling of missing files, permissions, and malformed data