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:
122
CLAUDE.md
122
CLAUDE.md
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
||||
|
||||
## 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
|
||||
|
||||
@@ -14,16 +14,17 @@ This is a Discord bot built with discord.js v14 that provides sound effects (bot
|
||||
# Install dependencies
|
||||
pnpm install
|
||||
|
||||
# Direct Node.js execution (requires Node 22 LTS)
|
||||
pnpm start # Production mode
|
||||
pnpm dev # Development mode with auto-reload
|
||||
# Local Node.js execution (requires Node 20+ LTS)
|
||||
pnpm dev # Development mode with auto-reload
|
||||
pnpm start:prod # Production mode (local Node.js)
|
||||
|
||||
# Docker Compose (recommended)
|
||||
pnpm up # Start bot with Docker Compose
|
||||
pnpm down # Stop bot
|
||||
pnpm restart # Restart bot (useful after config changes)
|
||||
pnpm logs # View logs
|
||||
pnpm build # Rebuild image
|
||||
# Docker Compose (recommended for production)
|
||||
pnpm start # Start bot with Docker Compose
|
||||
pnpm stop # Stop bot
|
||||
pnpm restart # Restart bot (useful after config changes)
|
||||
pnpm logs # View logs
|
||||
pnpm build # Rebuild image
|
||||
pnpm boom # Quick rebuild and restart
|
||||
|
||||
# Direct Docker (alternative)
|
||||
pnpm image:build # Build Docker image
|
||||
@@ -34,9 +35,9 @@ pnpm image:run # Run Docker container with auto-restart
|
||||
|
||||
```bash
|
||||
# Docker Compose approach (recommended)
|
||||
pnpm up && pnpm logs # Start and follow logs
|
||||
pnpm restart # Restart after config changes
|
||||
pnpm build && pnpm up # Rebuild after code changes
|
||||
pnpm start && pnpm logs # Start and follow logs
|
||||
pnpm restart # Restart after config changes
|
||||
pnpm boom # Quick rebuild and restart after code changes
|
||||
|
||||
# Direct Docker approach
|
||||
docker stop discord-bot && docker rm discord-bot
|
||||
@@ -48,60 +49,91 @@ pnpm image:build && pnpm image:run
|
||||
|
||||
### 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
|
||||
- `config.js`: Config loader and validator
|
||||
- `config.js`: Hybrid config manager (SQLite database + file fallback)
|
||||
- `intents.js`: Discord gateway intents
|
||||
- **src/commands/**:
|
||||
- `prefix/`: Traditional prefix commands (!sfx, !funfact, etc.)
|
||||
- `slash/`: Slash commands (/sfx with autocomplete)
|
||||
- `prefix/`: Traditional prefix commands (!sfx, !funfact, !hamfact, !role, !dance, !join, !leave, !reboot)
|
||||
- `slash/`: Modern slash commands (/sfx with autocomplete, /config with subcommands)
|
||||
- **src/services/**:
|
||||
- `databaseService.js`: SQLite database operations and guild management
|
||||
- `voiceService.js`: Voice connections using @discordjs/voice
|
||||
- `commandLoader.js`: Static/Ankhbot command loader
|
||||
- `sfxManager.js`: Sound effect file management
|
||||
- `schedulerService.js`: Scheduled events handler
|
||||
- **src/utils/**: Helper functions
|
||||
- **config.json**: Bot configuration (copy from config.json.example)
|
||||
- `commandLoader.js`: Static/Ankhbot command loader with hot-reload
|
||||
- `sfxManager.js`: Sound effect file management and caching
|
||||
- `schedulerService.js`: Scheduled events handler with timezone support
|
||||
- **src/utils/**: Helper functions (randElement, chunkSubstr, etc.)
|
||||
- **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
|
||||
|
||||
Commands are handled in priority order:
|
||||
1. Native commands (defined in index.js commands object)
|
||||
2. Static text commands (from conf/text_commands)
|
||||
3. Ankhbot imported commands (from conf/ghbot.abcomg)
|
||||
1. **Prefix commands**: Modular commands in src/commands/prefix/
|
||||
2. **Static text commands**: From conf/text_commands (pipe-delimited with aliases)
|
||||
3. **Ankhbot commands**: From conf/ghbot.abcomg (legacy format support)
|
||||
|
||||
### Sound Effects System
|
||||
|
||||
- Sound files stored in `sfx/` directory as .mp3 or .wav
|
||||
- Automatically discovered on startup and directory changes
|
||||
- Requires voice channel connection and ffmpeg (included in Docker image)
|
||||
- Volume and audio passes configurable per guild
|
||||
- **Dual interfaces**: Both !sfx prefix command and /sfx slash command with autocomplete
|
||||
- **Auto-discovery**: Sound files in sfx/ directory (.mp3/.wav) automatically available
|
||||
- **Voice integration**: @discordjs/voice with connection pooling and cleanup
|
||||
- **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
|
||||
|
||||
- **conf/text_commands**: Pipe-delimited text commands with alias support
|
||||
- **conf/funfacts & conf/hamfacts**: Line-separated fact collections
|
||||
- **conf/snesgames.json**: SNES game database (purpose unclear from current usage)
|
||||
- **conf/funfacts & conf/hamfacts**: Line-separated fact collections with hot-reload
|
||||
- **conf/ghbot.abcomg**: Ankhbot command database (JSON format, legacy eval support)
|
||||
- **config.json**: Initial configuration and bot token (optional after seeding)
|
||||
|
||||
### Scheduled Events
|
||||
|
||||
Configured per guild in config.json with cron-style scheduling using node-schedule. Events can:
|
||||
- Send messages to specific channels
|
||||
- Ping specific roles
|
||||
- Run on cron schedules
|
||||
**Storage**: Database with JSON schedule format support
|
||||
**Formats**:
|
||||
- Object format: `{"hour": 7, "minute": 30, "tz": "America/Los_Angeles"}`
|
||||
- Cron format: `"0 9 * * *"`
|
||||
**Features**: Timezone support, role pings, channel targeting
|
||||
|
||||
### 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
|
||||
|
||||
- Discord.js v14 with modern API patterns
|
||||
- @discordjs/voice for audio playback
|
||||
- Hybrid command system: prefix commands + slash command for SFX
|
||||
- /sfx slash command with autocomplete for easy sound discovery
|
||||
- Hot-reloads configuration files and commands without restart
|
||||
- Supports multiple guilds with individual configurations
|
||||
- Admin commands restricted by Discord user ID
|
||||
- Blacklist system for blocking specific users
|
||||
- Proper voice connection pooling and cleanup
|
||||
- **Discord.js v14** with modern API patterns and explicit intents
|
||||
- **@discordjs/voice** for audio playback with connection pooling
|
||||
- **SQLite database** with better-sqlite3 for persistent configuration
|
||||
- **Hybrid command system**: Traditional prefix commands + modern slash commands
|
||||
- **Auto-registration**: Public bot ready - automatically configures new guilds
|
||||
- **Soft delete system**: Guild settings preserved when bot is removed/re-added
|
||||
- **Live configuration**: `/config` slash commands for real-time settings updates
|
||||
- **Hot-reload**: Static commands and facts reload without restart
|
||||
- **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
|
||||
Reference in New Issue
Block a user