How ligen131/sunbot works
Main Components
• Bot Core: The central entry points are found in files like src/index.ts, src/bot.ts, and the configuration through config/config.json.
• Message Handling & Plugin Manager: The src/Message folder contains the core message handling logic (src/Message/message.ts, send.ts, storage.ts) as well as the plugin infrastructure (src/Message/Plugins with subdirectories for each plugin such as DingDong, repeater, and fromapi). This shows an extensible architecture where commands trigger different responses.
• Plugins: Each plugin (e.g., DingDong, repeater, fromapi) is implemented as a separate module within the Plugin directory, emphasizing a loose coupling between core bot functionality and individual commands/features.
• Database Layer: The src/db folder (with file db.ts) indicates a dedicated module for database interaction. This layer is used by plugins that require persistence, like the repeater.
• Status Page: The src/status directory (including server.ts and index.html) provides a monitoring interface, likely built on Express, running on a configurable port (default http://localhost:4721).
• Utility Modules: The src/utils folder contains common helper functions (logs.ts, common.ts) that support debugging, logging, or other cross-cutting concerns.
• Configuration & Dependencies: The config folder holds JSON configuration files (with an example provided), and the package.json lists dependencies such as Wechaty, Express, and MySQL libraries.
Relationships and Data Flow
• A connection from certain plugins (e.g., the repeater) to the Database module, illustrating that these plugins perform database operations.
• Status Page component (Express server) as an independently running service that can be launched alongside the core bot, and indicate its communication channel with the Bot Core for status updates.
• Configuration flow by showing how the Bot Core reads settings from the config file.
Architectural Patterns and Design Principles
• Separation of Concerns: Clearly separate business logic (message command handling), plugin functionalities, external communication (status page), and persistence (database).
• Dependency Injection / Loose Coupling: The distinct modules (e.g., plugins, db, and status server) should communicate via well-defined interfaces to allow easy extension or replacement.