How valehk08/adabot works
Project Type & Purpose
ADABot is a Python-based, modular Discord bot built with discord.py. It uses Google Gemini AI and a host of external APIs to deliver conversational AI, summarization, image generation, news, finance data, weather, translation, polls, and fun social interactions—while persisting context in an SQLite database.
File Structure Analysis
• bot.py
• Initializes the Discord client, loads .env/config, and registers all Cogs.
• config.py
• Reads environment variables and exposes configuration (tokens, API keys).
• cogs/
• database.py – Manages SQLite connection and context storage (users/messages).
• main_commands.py – Core AI commands (!chat, !tone, !translate, etc.).
• extra_commands.py – Summarization (!summarize), AI image generation (!generate).
• utility.py – Helper commands (!info, reminders, polls).
• uis.py – Discord UI components (menus, buttons, selects).
• .env
• Stores DISCORD_TOKEN, OPENROUTER_API_KEY, etc.
• requirements.txt
• Lists external dependencies.
Main Components & Relationships
a. User & Discord Gateway (discord.py)
– Receives user messages/events and delivers bot responses.
b. Bot Core (bot.py + config.py)
– Single Discord client instance; loads and wires up all Cogs.
c. Cogs Layer
– Each Cog is a plugin handling a group of commands or events.
– database.py Cog provides read/write context for other Cogs.
d. Domain Services
– Wrappers around external APIs:
• Google Gemini (chat, summarization, image gen, historical facts)
• NewsAPI, yfinance (stock data), Open-Meteo, Horoscope API
• Imgflip & OpenRouter (memes), translation, polls logic
e. Persistence Layer
– SQLite (DataBase.db) storing user join dates and recent messages for context.
f. External APIs
– Multiple third-party services; called via HTTP libraries (requests, newsapi, yfinance).
Architectural Patterns & Design Principles
• Plugin Architecture: discord.py Cogs isolate command sets.
• Layered Architecture:
1. Presentation – Discord Gateway
2. Application – Bot Core + Cogs
3. Domain – Service wrappers (AI, data fetchers)
4. Persistence – SQLite database
5. Integration – External APIs
• Single Responsibility: Each Cog/Service has a focused role
• Configuration via DI: config.py abstracts environment/secrets
• “Discord Gateway” (external system)
• “Bot Core” (bot.py + config)
• DatabaseCog
• MainCommandsCog
• ExtraCommandsCog
• UtilityCog
• UIsCog
• User → Discord Gateway → Bot Core → appropriate Cog → Domain Service → External API / DB → back through the same path → User
• DB Cog → SQLite DB for both read (context fetch) and write (persist messages/users)
• Blue rectangles: Discord Gateway & External APIs
• Green rectangles: Bot Core & Cogs
• Yellow rectangles: Domain Services