basic setup, /ping added
This commit is contained in:
48
relay/bot.go
Normal file
48
relay/bot.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package relay
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"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(cfg Config) *Bot {
|
||||
return &Bot{
|
||||
Cfg: cfg,
|
||||
Paginator: paginator.New(),
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Bot) SetupBot(listeners ...bot.EventListener) error {
|
||||
client, err := disgo.New(b.Cfg.Bot.Token,
|
||||
bot.WithGatewayConfigOpts(gateway.WithIntents(gateway.IntentGuilds, gateway.IntentGuildMessages, gateway.IntentMessageContent)),
|
||||
bot.WithCacheConfigOpts(cache.WithCaches(cache.FlagGuilds)),
|
||||
bot.WithEventListeners(b.Paginator),
|
||||
bot.WithEventListeners(listeners...),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b.Client = client
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Bot) OnReady(_ *events.Ready) {
|
||||
slog.Info(b.Cfg.Bot.Name + " ready.")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
if err := b.Client.SetPresence(ctx, gateway.WithListeningActivity("you"), gateway.WithOnlineStatus(discord.OnlineStatusOnline)); err != nil {
|
||||
slog.Error("Failed to set presence", slog.Any("err", err))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user