How lowlevelsubmarine/tronic works
Project type and purpose
• Tronic is a backend‐only, event‐driven Discord bot written in Java (with a gradual migration to Kotlin).
• It connects to the Discord Gateway via JDA, listens for user events (messages, button clicks, voice updates), processes commands and button interactions, manages a music queue (YouTube, Spotify, etc.), persists state per guild/user, and logs events.
File structure
• Top‐level: Gradle build files, CI/CD workflows (.github), design assets (logos, mockups).
• src/main/java/com/tronic:
• actions, arguments – abstraction for request handlers and argument parsing
• bot/core – bootstrapping (ConfigProvider, Core, Tronic entrypoint, Updater)
• bot/commands & bot/buttons – command/button definitions, handlers, validators
• bot/listeners – JDA event listeners (message, button, voice updates, ready)
• bot/music – MusicManager, player abstractions, playlist/queue items
• bot/music/sources – TrackProvider implementations for LavaPlayer, YouTube, Spotify, URL, etc.
• bot/storage – JSON/Kotlin storage for guild/user settings
• bot/statistics – collecting and serializing usage stats
• bot/io, tools, logger – logging, utility classes, I/O wrappers
• src/test – unit tests for the logger
README for additional insights
• Simplicity, easy button controls, autocorrection, queueing various music sources.
• CI pipeline builds a fat JAR, configuration via JSON file, GPL v3 license.
Main components
a. Discord Gateway (JDA client)
b. Core Application
• Tronic (main)
• ConfigProvider & ReleaseConfig
• Updater (auto‐release)
c. Event Dispatch Layer
• Listeners (CommandListener, ButtonListener, VoiceUpdateListener, ReadyListener, etc.)
d. Processing Layer
• CommandHandler & Command classes
• ButtonHandler & Button classes
• Argument parsing (Argument, Arguments, type‐specific arguments)
• HyperchannelManager, ShortcutResolver, QuestionHandler
e. Service Layer
• MusicManager + Player + AudioPlayerSendHandler
• TrackProvider implementations (YouTube, Spotify, URL, LavaPlayer)
• StatisticsHandler + Serializer + GraphRenderer
f. Persistence Layer
• Storage interface + StorageGlue
• GuildStorage, UserStorage, StaticStorage (JSON‐backed)
g. Utilities and Logging
• Logger + TronicMessage
• Tools (FileUtils, GsonUtils, JDAUtils, Markdown, etc.)
h. External Services
• Discord API (Gateway, Voice WebSocket, REST API)
• YouTube/Spotify APIs or scraping libraries
i. CI/CD Pipeline
• GitHub Actions workflows, Dependabot integration
Relationships and data flow
• Discord Gateway emits events → Listeners pick up events → Dispatch to appropriate Handler (command or button) → Handler invokes Actions (business logic) → Actions coordinate with Service Layer (MusicManager, StatisticsHandler, Storage) → Responses sent back via JDA to Discord (messages, embeds, voice frames).
• TrackProviders fetch/stream audio from external APIs → Audio frames sent through AudioPlayerSendHandler into Discord voice connection.
• Updater checks GitHub tags/releases → triggers CI/CD to build and publish new JAR.
Architectural patterns and design principles
• Layered (Presentation/Event → Processing → Services → Persistence)
• Command Pattern for encapsulating each bot command
• Strategy Pattern for interchangeable TrackProvider implementations
• Observer/Event‐Driven via JDA Listeners
• Dependency Inversion: core classes depend on abstractions (Storage, TrackProvider interfaces)
• Single Responsibility: each package/folder has clearly delineated concern