refactor(discordbot): introduce Session interface for testability

Extract a Session interface from *discordgo.Session so DiscordBot methods
can be tested with a mock — no live Discord connection required. Add
AddHandler, RegisterCommands, and UserID methods to DiscordBot so
external callers (main.go, sys_channel_server.go) no longer reach
through bot.Session directly. Rewrite tests with a mockSession,
raising discordbot coverage from 12.5% to 66.7%.
This commit is contained in:
Houmgaor
2026-02-27 11:45:20 +01:00
parent 4e8c4b4e92
commit d38fef08bb
4 changed files with 315 additions and 373 deletions

View File

@@ -63,8 +63,7 @@ func setupDiscordBot(config *cfg.Config, logger *zap.Logger) *discordbot.Discord
preventClose(config, fmt.Sprintf("Discord: Failed to start, %s", err.Error()))
}
_, err = bot.Session.ApplicationCommandBulkOverwrite(bot.Session.State.User.ID, "", discordbot.Commands)
if err != nil {
if err = bot.RegisterCommands(); err != nil {
preventClose(config, fmt.Sprintf("Discord: Failed to start, %s", err.Error()))
}