-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.go
64 lines (57 loc) · 1.54 KB
/
bot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package dbot
import (
"context"
"log/slog"
"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/cache"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/disgo/gateway"
"github.com/disgoorg/paginator"
)
func New(logger *slog.Logger, version string, config Config) *Bot {
return &Bot{
Logger: logger,
Config: config,
Paginator: paginator.New(),
Version: version,
}
}
type Bot struct {
Logger *slog.Logger
Client bot.Client
Paginator *paginator.Manager
Config Config
Version string
}
func (b *Bot) SetupBot(listeners ...bot.EventListener) {
var err error
b.Client, err = disgo.New(b.Config.Token,
bot.WithLogger(b.Logger),
bot.WithGatewayConfigOpts(gateway.WithIntents(
gateway.IntentGuilds,
gateway.IntentGuildMessages,
gateway.IntentMessageContent,
gateway.IntentGuildVoiceStates,
gateway.IntentGuildPresences,
)),
bot.WithCacheConfigOpts(cache.WithCaches(
cache.FlagGuilds,
cache.FlagVoiceStates,
cache.FlagChannels,
cache.FlagPresences,
)),
bot.WithEventListeners(b.Paginator),
bot.WithEventListeners(listeners...),
)
if err != nil {
b.Logger.Error("Failed to setup bot", slog.Any("error", err))
}
}
func (b *Bot) OnReady(_ *events.Ready) {
b.Logger.Info("Butler ready")
if err := b.Client.SetPresence(context.TODO(), gateway.WithListeningActivity("you"), gateway.WithOnlineStatus(discord.OnlineStatusOnline)); err != nil {
b.Logger.Error("Failed to set presence", slog.Any("error", err))
}
}