How decryptu/decryptgpt works
Project Type & Purpose
• DecryptGPT is a modular, back-end Discord bot built on Node.js.
• It uses Discord.js to connect to the Discord Gateway and OpenAI’s API suite (GPT-4o/4.1/o3, Whisper, GPT-Image) for chat, transcription, image generation/editing, and document processing.
• It is an open-source tool designed for medical-focused, French-language academic assistance in Discord.
Key Architectural Components
A. Discord Gateway Client
• index.js: Bootstraps the bot, loads environment/config, logs in to Discord via Discord.js (WebSocket).
B. Event Handling Layer
• events/*.js: Listeners for ‘ready’, ‘interactionCreate’, ‘messageCreate’.
• Routes incoming Gateway events to command handlers or message responders.
C. Command Handling Layer
• commands/*.js: Implements slash commands (/gpt-mode, /gpt-model, /image-gpt, /image-edit).
• Registered at startup (scripts/delete-commands.js can reset registration).
D. Business Logic / Utility Layer
• utils/*.js: Helpers for building conversation logs, splitting messages, error handling, transcribing voice (Whisper), generating/editing images, processing documents (PDF, CSV, Excel), reacting with emojis, etc.
E. External API Clients
• OpenAI REST calls: ChatCompletions, ImageGeneration, ImageEditing, Whisper
F. Configuration & Scripts
• .env / config.example.js / channels.mjs: Bot credentials, channel IDs, default settings (model, token limits).
• scripts/delete-commands.js: CLI for maintenance.
Interactions & Data Flow
1. Bot startup (index.js)
• Load .env & config, register slash commands via Discord REST.
2. User Interaction
• User triggers a slash command or sends a message/voice.
• Discord Gateway pushes an event → event handler → command or message responder.
3. Command Execution
• Command handler invokes relevant util:
• For chat: buildConversationLog → call OpenAI Chat API → respond.
• For voice: transcribeVoiceMessage (Whisper) → process as text.
• For image gen/edit: createGptImage / editImage util → call GPT-Image API → upload back to Discord.
• For document: extractFileContent → analyze via Chat API.
4. Bot Response
• Process API response → utils/splitMessage if needed → Discord.js reply/edit.
5. Error Handling
• Centralized via utils/handleApiErrors & handleInteractionError → logs and safe user feedback.
Architectural Patterns & Principles
• Event-Driven: Decoupled event listeners and handlers.
• Modular: commands and events live in their own folders—easy to add or remove features.
• Single Responsibility: Each util does one task (transcription, image creation, file extraction).
• Configuration-Driven: Behavior controlled by config.js and environment variables—facilitates different deployments (dev vs prod).
• Extensible CLI Scripts: scripts/ folder for administrative tasks.