How flashgnash/ordis works
Project type and purpose
• Ordis is a single-service Discord bot written in Rust.
• It exposes slash commands, context menu actions, event handlers, and integrates with a PostgreSQL database and external APIs (OpenAI/GPT and DALL·E).
File structure for high-level components
• src/main.rs: entrypoint, connects to Discord gateway, registers commands.
• src/admin, src/games, src/llm, src/rpg, src/voice: command- and event-handling modules.
• src/db + migrations/: Diesel ORM layer for PostgreSQL.
• http_client.rs: wrapper for HTTP calls (used by LLM integrations).
• resources/: static files (emojis, dictionaries).
README for architecture hints
• Uses OpenAI tokens and DALL·E for LLM features.
• Requires database setup via Diesel.
• Maintains state (characters, spells, mana) persistently in Postgres.
• Responds to Discord events and REST calls.
Main components
a. Discord Platform
• Gateway (WebSocket) for real-time events.
• REST API for slash commands.
b. Ordis Bot Service (Rust)
• Command Router / Event Loop (main.rs).
• Module Layer:
• Admin Module (auto_react, auto_threads, nickname, colour_picker)
• Games Module (Wordle, Russian Roulette)
• LLM Module (content_filter, translator, reply_handler)
• RPG Module (Mir event handlers, stat block, spells)
• Voice Module (music streaming)
• Database Layer (db.rs + db/{characters, users, models, schema}.rs)
• HTTP Client (http_client.rs)
• Shared Utilities (base.rs, common.rs, dictionary.rs, dice.rs)
• Static Resources Loader (resources/dictionary_*.txt, resources/emojis)
c. PostgreSQL Database
• Tables: users, characters, stat_blocks, spells, messages references.
• Handled via Diesel (diesel.toml, migrations/).
d. External APIs
• OpenAI API (chat completion for parsing, image generation).
• Discord REST for images, embeds.
Relationships and interactions
• Discord Gateway → Bot Service (receives events: slash command invoked, message reactions)
• Bot Service → Discord REST (register commands, send replies, context menu actions)
• Bot Service → PostgreSQL (read/write user, character, mana, spell data)
• Bot Service reads from local resources (dictionaries and emojis) for spell checks, emoji responses.
Architectural patterns and principles
• Modular decomposition: each feature (admin, games, llm, rpg, voice) isolated under src/
• Layered design: CLI/Event Loop → Modules → Data Access → Persistence
• Single process / monolith service, externalizing state to DB and 3rd-party APIs
• Use of Diesel migrations for schema evolution
Technologies, frameworks, and libraries
• Rust language, Cargo/Nix for build
• Serenity or Twilight (implied) for Discord integration
• Diesel ORM for PostgreSQL
• tokio (async runtime)
• reqwest or similar via http_client.rs
• OpenAI REST API (GPT models, DALL·E)
• Nix/flakes for reproducible dev environment
Essential elements
• Notes on runtime (async/tokio), build (Cargo/Nix), and persistence (Diesel).