mid day commit

This commit is contained in:
2025-12-08 13:31:47 +01:00
parent e045d0d01f
commit 06c17cc2e9
7 changed files with 245 additions and 8 deletions

View File

@@ -2,6 +2,8 @@ package relay
import (
"context"
"homestead/homestead_to_go/relay/commands"
"log"
"log/slog"
"time"
@@ -21,12 +23,40 @@ func New(cfg Config) *Bot {
}
}
func onMessageCreate(event *events.MessageCreate) {
// Ignore bot messages
if event.Message.Author.Bot {
return
}
// Check if channel is registered
if !commands.ChannelStore.IsRegistered(event.Message.ChannelID) {
return
}
// Log the message
log.Printf("[%s] %s#%s: %s",
event.Message.ChannelID,
event.Message.Author.Username,
event.Message.Author.Discriminator,
event.Message.Content,
)
// You can also log attachments, embeds, etc.
if len(event.Message.Attachments) > 0 {
log.Printf(" └─ Attachments: %d", len(event.Message.Attachments))
}
}
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...),
bot.WithEventListeners(&events.ListenerAdapter{
OnMessageCreate: onMessageCreate,
}),
)
if err != nil {
return err