How staciax/lattebot works
Project Type and Purpose
• Lattebot is a single‐service backend application: a Python‐based Discord bot. It connects to the Discord Gateway, listens for events (messages, interactions), and responds via commands and UI components. It uses a plugin‑style architecture (“cogs”) for modular features.
File‐Structure Analysis
• Top‑level scripts:
• pre_start.py – syncs slash commands to Discord (one‐time setup).
• launcher.py – entry point to start the bot.
• Configuration:
• .env.example → .env file for environment variables (Discord token, etc.).
• pyproject.toml, Makefile, Dockerfile, docker-compose.yaml – build/deploy scripts.
• Core application (“lattebot” package):
• core/ – bot bootstrap, configuration loader, translation, command tree management.
• cogs/ – feature modules, grouped by domain (about, admin, events, help, custom jsk/test cogs).
• ui/ – Discord UI abstraction (views, modals).
• chat_formatting.py, embeds.py, utils.py, logging.py – shared utilities.
• Tests/ – pytest tests for core components.
Key Components
a. External Services
• Discord Gateway & REST API
• (Optional) Docker host or local machine environment
b. Scripts & Processes
• pre_start.py (Command Synchronization)
• launcher.py → Bot Process
c. Bot Process Internals
• Core Layer
– Bot bootstrap (bot.py)
– Config loader (config.py)
– Translator/localization (translator.py + locales)
– Command tree manager (tree.py)
• Cogs Layer
– Individual modules (about, admin, events, help, custom)
– Each implements event handlers and slash/app commands
• UI Layer
– Modal & View abstractions
• Shared Utils
– Chat formatting, embeds, logging, general utilities
Component Interactions and Data Flow
• pre_start.py reads .env → authenticates with Discord REST → syncs slash commands
• launcher.py reads .env → instantiates Bot (core.bot) → connects to Discord Gateway
• Discord Gateway → emits events (messages, interactions) → Bot dispatch → Cog handlers
• Cog handlers → make internal calls to core utilities (translator, chat_formatting, embeds)
• UI interactions (modals, button clicks) → UI.View / UI.Modal classes → dispatched back to bot
• Bot → sends responses via Discord REST through the Gateway connection
• Logging component captures each step and writes to console/file
Architectural Patterns & Principles
• Plugin‑style modularity: each “cog” is a self‑contained feature
• Separation of concerns: core bootstrapping/config, cogs for commands/events, ui for interactive elements, utils for shared logic
• Twelve‑factor app principles: environment configuration via .env, stateless service
Technologies & Frameworks
• Python 3.13+
• uv (Astral’s task runner) for script execution
• discord.py or fork (implicitly used by core.bot)
• pytest for testing
• Docker & docker-compose for containerized deployment
Essential Elements
• Config loading once at startup, feeding into all subsystems.
• Translator/locales feeding into cogs or utilities that need localization.
• Scripts (pre_start, launcher) as separate entry‑point nodes.