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).
This commit is contained in:
31
lib/bot.go
Normal file
31
lib/bot.go
Normal file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user