How y-exe/sugiyama-bot works
Project Type and Purpose
• This is a Python-based Discord Bot (“杉山啓太Bot”) that runs as a single deployable application.
• Purpose: provide miscellaneous utility and entertainment commands (chat summarization, voice conversion via RVC/VoiceVox, image generation, watermarking, games, weather, currency conversion, URL shortening, etc.) within Discord servers.
File Structure Analysis
• Top level:
• main.py – entry point and command dispatcher
• requirements.txt – Python dependencies (discord.py, python-dotenv, pillow, aiohttp, numpy, pydub, google-generativeai, etc.)
• assets/
– fonts/ (MochiyPopOne-Regular.ttf, NotoSerifJP-Bold.otf)
– watermark_templates/ (PNG templates)
• Runtime-generated files (described in README, not in repo):
• .env – environment variables (API keys)
• bot_settings.json, game_points.json, weather_city_codes.json
• audio/ (input/output temp folders)
• RVC_Project/ (external voice-conversion submodule via git clone)
Key Insights from README
• Bot uses discord.py v2.x and Python 3.10
• Interacts with multiple external services/APIs:
• Discord Gateway (command and event stream)
• Google Gemini API (AI summarization, weather city ID inference)
• VoiceVox API (text-to-speech)
• RVC CLI (local inference for voice conversion)
• Pillow (image/font rendering)
• Various third-party web APIs (weather.tsukumijima, x.gd, currency exchange, 5000兆円 image generator)
a. Main Components
• Discord Gateway (WebSocket + REST)
• Bot Application (main.py)
– Command Processor (dispatches slash and prefix-free commands)
– Feature Modules:
· AI Summarizer
· Voice Conversion (VoiceVox + RVC CLI)
· Image/Text Generation (Pillow, watermark fusion)
· Games Engine (othello, janken, dice)
· Utility Clients (weather, rate, shorturl)
– File Manager (reads/writes JSON state files, loads assets/fonts, temp audio files)
• External Services:
– Google Gemini API
– VoiceVox API
– RVC CLI (local subprocess)
– Third-party Web APIs
• File System / Data Store:
– assets/, fonts/, watermark_templates/, audio/
– JSON files for settings, points, cache
b. Relationships and Data Flow
• Discord Gateway → Bot Application: receives events (messages, slash commands)
• Bot Application → Discord REST API: sends responses (text, embeds, files)
• Bot Application → External API clients: HTTP requests to Gemini, VoiceVox, weather, rate, shorturl, 5000choyen
• Bot Application → RVC CLI: subprocess call for voice conversion
• Bot Application → File System: load fonts/assets, read/write JSON, write temp audio
• Bot Application ↔ Users: command issuance and bot responses via Discord
c. Architectural Patterns & Principles
• Single-process monolith structured in modules
• Separation of concerns: one handler per feature
• Externalize configuration via .env and JSON files
• Use of asynchronous I/O (aiohttp, discord.py async)
• Pluggable asset pipeline (fonts, templates loaded at runtime)
d. Key Technologies/Frameworks
• Python 3.10, discord.py v2.x
• python-dotenv
• Pillow for image generation
• aiohttp for HTTP clients
• numpy, pydub for audio processing
• subprocess + local RVC CLI for voice conversion
• Google-generativeai client