From ac523cba730331f58e745690d98b653bf7a21a40 Mon Sep 17 00:00:00 2001 From: "Gustavo L de Mello (Guz)" Date: Thu, 21 Nov 2024 21:23:09 -0300 Subject: [PATCH] feat(lib): new bot abstraction library following the idea from [Comicverse's library package](https://forge.capytal.company/capytalcode/project-comicverse/src/branch/main/lib), a new package inside the "lib" folder was created, to make a abstraction over the discordgo package. The idea is to follow something similar to the http package with it's router with Handle functions and with inspirations from the package [Disgolf](https://github.com/FedorLap2006/disgolf). --- lib/bot.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/bot.go diff --git a/lib/bot.go b/lib/bot.go new file mode 100644 index 0000000..ac4d4b0 --- /dev/null +++ b/lib/bot.go @@ -0,0 +1,31 @@ +package bot + +import ( + "github.com/bwmarrin/discordgo" +) + +type Bot struct { + session *discordgo.Session +} + +func New(token string) (*Bot, error) { + s, err := discordgo.New("Bot " + token) + if err != nil { + return nil, err + } + + s.Identify.Intents = discordgo.MakeIntent(discordgo.IntentsAllWithoutPrivileged) + + return &Bot{ + session: s, + commands: []Command{}, + }, nil +} + +func (b *Bot) Start() error { + if err := b.session.Open(); err != nil { + return err + } + + return nil +}