How milenakos/cat-bot works
Project type and purpose
• This is a Python‐based Discord bot (“Cat Bot”) geared toward entertainment (cat facts, mini‐games, image and audio generation).
• It’s a single‐process application that interacts with the Discord Gateway/API and persists data in a PostgreSQL database.
File structure
• Top‐level Python modules:
• bot.py, main.py – entry points for starting the bot
• database.py – functions for database logic
• catpg.py – custom asyncpg wrapper (MIT licensed)
• msg2img.py – generates images from text (likely using PIL or similar)
• config.py – loads runtime configuration from JSON files
• Static assets:
• config/*.json – per-feature configuration (aches, battlepass, catnip)
• images/… – image assets for “spawn” and “mafia” features
• fonts/*.otf – font files used by msg2img
• bwomp.mp3 – audio clip for playback features
• facts.txt – cat facts data
• Project bootstrap:
• requirements.txt / requirements-gw.txt – Python dependencies
• schema.sql – DDL for PostgreSQL schema
• No separate “frontend/backend” folders—backend only but modularized internally.
README for additional insights
• Emphasizes PostgreSQL, Python ≥3.8, discord.py (or similar gateway library), and optional “gateway proxy” fork.
• Mentions self‐hosting is hacky (i.e., minimal ops/deployment guidance).
Main components
a. Components:
• Discord Cloud (Gateway + REST API)
• Bot Application Server – single Node.js‐like process written in Python
– Event Listener & Command Dispatcher
– Feature Modules (“cogs”): catnip, battlepass, spawn, mafia, facts
– Utilities: Config Loader, msg2img (image gen), Audio Service (plays bwomp.mp3)
– Database Layer: database.py + catpg.py wrapper
• PostgreSQL Database
• Local Asset Store (fonts/, images/, facts.txt)
• External Services (Top.gg widget, Wiki link—optional for metrics/analytics)
b. Relationships & interactions:
1. Discord Gateway pushes events to Bot Application via WebSocket
2. Bot’s Dispatcher routes an event to a Feature Module
3. Feature Module may:
– Query/update PostgreSQL via catpg → database
– Read local assets (images, fonts, facts.txt)
– Call msg2img or audio routines
4. Bot replies to Discord via REST or WebSocket
5. Bot may fetch custom emojis from Discord App assets at startup
c. Architectural patterns & design principles:
• Modular feature “cog” pattern (each JSON config + handler)
• Separation of concerns:
• Config loader isolates configuration
• catpg abstracts DB connection pooling and queries
• msg2img isolates image‐generation logic
• Event-driven, asynchronous I/O (asyncio + discord.py + asyncpg)
d. Key technologies/frameworks:
• Python 3.8+
• discord.py (or custom gateway proxy fork)
• asyncpg (wrapped by catpg.py)
• PIL (for msg2img)
• PostgreSQL
• Local file I/O for static assets