basic setup, /ping added

This commit is contained in:
2025-11-30 10:58:16 +01:00
parent 781a499a6c
commit e045d0d01f
9 changed files with 296 additions and 0 deletions

48
relay/bot.go Normal file
View 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))
}
}