github.com/topi314/pogo-icons@v0.0.0-20250403082451-64aa0bf0322a/pogoicons/bot.go (about) 1 package pogoicons 2 3 import ( 4 "context" 5 "io/fs" 6 "log/slog" 7 8 "github.com/disgoorg/disgo/bot" 9 "github.com/disgoorg/disgo/handler" 10 11 "github.com/topi314/pogo-icons/internal/pokeapi" 12 ) 13 14 func New(client bot.Client, pokeClient pokeapi.Client, cfg Config, version string, goVersion string, assets fs.FS, assetCfg AssetConfig) *Bot { 15 s := &Bot{ 16 cfg: cfg, 17 version: version, 18 goVersion: goVersion, 19 assets: assets, 20 assetCfg: assetCfg, 21 client: client, 22 pokeClient: pokeClient, 23 } 24 25 client.AddEventListeners(s.routes()) 26 27 return s 28 } 29 30 type Bot struct { 31 cfg Config 32 version string 33 goVersion string 34 assets fs.FS 35 assetCfg AssetConfig 36 client bot.Client 37 pokeClient pokeapi.Client 38 } 39 40 func (b *Bot) Start() { 41 if b.cfg.Bot.SyncCommands { 42 go func() { 43 slog.Info("Syncing commands") 44 commands, err := b.commands() 45 if err != nil { 46 b.client.Logger().Error("failed to sync commands", err) 47 return 48 } 49 if err = handler.SyncCommands(b.client, commands, b.cfg.Bot.GuildIDs); err != nil { 50 b.client.Logger().Error("failed to sync commands", err) 51 } 52 }() 53 } 54 55 if err := b.client.OpenGateway(context.Background()); err != nil { 56 b.client.Logger().Error("failed to open gateway", err) 57 return 58 } 59 }