added reactionrole command

This commit is contained in:
2025-04-07 12:27:19 -04:00
parent 6006c78e5b
commit e6a6d0a5f5
4 changed files with 335 additions and 16 deletions
+35 -15
View File
@@ -5,6 +5,7 @@ import (
"log"
"os"
"os/signal"
"strings"
commands "ion606_bot/Bot/Commands"
@@ -15,15 +16,16 @@ var BotToken string
// commandHandlers maps command names to their interaction handler functions.
var commandHandlers = map[string]func(*discordgo.Session, *discordgo.InteractionCreate){
"meow": commands.HandleMeow,
"purr": commands.HandlePurr,
"boop": commands.HandleBoop,
"hug": commands.HandleHug,
"cuddle": commands.HandleCuddle,
"snuggle": commands.HandleSnuggle,
"catfact": commands.HandleCatfact,
"animalgif": commands.HandleAnimalGif,
"action": commands.HandleAction,
"meow": commands.HandleMeow,
"purr": commands.HandlePurr,
"boop": commands.HandleBoop,
"hug": commands.HandleHug,
"cuddle": commands.HandleCuddle,
"snuggle": commands.HandleSnuggle,
"catfact": commands.HandleCatfact,
"animalgif": commands.HandleAnimalGif,
"action": commands.HandleAction,
"reactionrole": commands.HandleReactionRole,
}
// Run starts the Discord bot session and listens for both message and slash command events.
@@ -61,14 +63,32 @@ func newMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID {
return
}
}
func handleInteractionCreate(s *discordgo.Session, i *discordgo.InteractionCreate) {
name := i.ApplicationCommandData().Name
if handler, found := commandHandlers[name]; found {
handler(s, i)
} else {
log.Printf("No handler found for command: %v", name)
// Check for modal submissions first.
if i.Type == discordgo.InteractionModalSubmit {
if strings.HasPrefix(i.ModalSubmitData().CustomID, "reactionrole_modal:") {
commands.HandleReactionRoleModalSubmit(s, i)
return
}
}
// Then check for message components (buttons).
if i.Type == discordgo.InteractionMessageComponent {
if strings.HasPrefix(i.MessageComponentData().CustomID, "rr:") {
commands.HandleReactionRoleButton(s, i)
return
}
}
// Finally, process application commands.
if i.Type == discordgo.InteractionApplicationCommand {
name := i.ApplicationCommandData().Name
if handler, found := commandHandlers[name]; found {
handler(s, i)
} else {
log.Printf("No handler found for command: %v", name)
}
}
}