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).
32 lines
478 B
Go
32 lines
478 B
Go
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
|
|
}
|