How eriappvrc/translatebot works
Project Type & Purpose
• This is a backend service (Node.js micro-service) that connects to Discord as a bot, listens for events and slash commands, uses the DeepL API for translation, and persists data in SQLite.
• Key use-cases: real-time auto-translation, slash-command configuration, statistics, and administrative maintenance.
Main Components
• Discord Gateway/API
• DeepL Translation API
b. Bot Service (group in a large rectangle labeled “TranslationBot”)
1. Entry Point
• index.js (Event dispatcher & bot initialization)
2. Command Registration
• deploy-commands.js (Registers slash commands with Discord)
3. Command Handlers
• commands/*.js (translate, translate-setup, translate-channel, translate-role, translate-stats, translate-admin, translate-help, translate-quickstart, translate-rules)
4. Utilities
• translation.js (DeepL API wrapper & caching logic)
• database.js (SQLite open, read/write config & stats)
• database-fixed.js (DB repair utility)
c. Data Store
• translate_bot.sqlite (SQLite file on disk)
d. Configuration
• .env (Discord token, DeepL key, DB path, etc.)
• package.json / package-lock.json (Node dependencies)
Relationships & Data Flows
1. Bot reads .env → initialize clients (Discord.js, DB, DeepL).
2. deploy-commands.js registers slash commands via Discord REST.
3. index.js logs in and opens Gateway WebSocket.
• Runtime Flow:
• Slash Command Handling:
a. Discord → (slash command event) → index.js
b. index.js routes to the corresponding commands/*.js handler
c. Handler calls database.js for config or stats
d. For translation: handler calls translation.js → DeepL API → returns text
e. Handler writes logs/stats to SQLite → replies to Discord
• Message Create Auto-Translate:
a. Discord → (messageCreate event) → index.js
b. index.js checks channel/user config via database.js
c. If eligible, calls translation.js → DeepL → caches results
d. Saves translation history in SQLite → posts translated message
• Error & Maintenance:
• database-fixed.js invoked manually for DB repair
• translate-admin commands trigger database.js cleanup/backup
Architectural Patterns & Principles
• Modular Command Pattern: each slash command lives in its own module under src/commands.
• Single Responsibility: index.js only dispatches events, deploy-commands.js only registers commands, translation.js only handles API integration.
• Layered: Presentation (Discord events) → Application (command handlers) → Infrastructure (utils & DB) → External (DeepL).
Final Checklist
[ ] All major components (Discord Gateway, Bot Core, Commands, Utils, SQLite, DeepL) are present
[ ] Groupings reflect the file-system structure (src/commands, src/utils)
[ ] Labels include key technologies (Discord.js v14, Node.js v18+, SQLite, DeepL API)