From e003afab6df5155b64a741aeca0c3e8f4b55dc84 Mon Sep 17 00:00:00 2001 From: ION606 Date: Tue, 8 Apr 2025 10:59:37 -0400 Subject: [PATCH] fixed a bug --- Bot/Commands/reactionrole.go | 44 ++++++++++++++++++++---------------- Bot/Helpers/helpers.go | 11 +++++++++ 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/Bot/Commands/reactionrole.go b/Bot/Commands/reactionrole.go index 1633aaa..50ebb41 100644 --- a/Bot/Commands/reactionrole.go +++ b/Bot/Commands/reactionrole.go @@ -167,25 +167,32 @@ func HandleReactionRole(s *discordgo.Session, i *discordgo.InteractionCreate) { } options := i.ApplicationCommandData().Options - count := int(options[0].IntValue()) - // Determine style based on the additional option; default to primary. - style := "primary" - if len(options) > 1 { - styleOpt := options[1] - if val := styleOpt.StringValue(); val != "" { - style = val - } - } + // Extract count (required - type Integer) + countOpt := helpers.GetOption(options, "count") + if countOpt == nil { + helpers.HandleError(s, i, fmt.Errorf("missing count option")) + return + } + count := int(countOpt.IntValue()) - targetMsgID := "" - if len(options) > 2 { - opt := options[2] - if val := opt.StringValue(); val != "" { - targetMsgID = val - reactionRoleTarget[i.Member.User.ID] = targetMsgID - } - } + // Determine style based on the "style" option; default to "primary" + style := "primary" + if opt := helpers.GetOption(options, "style"); opt != nil { + if val := opt.StringValue(); val != "" { + style = val + } + } + + // Extract target message ID from the "message_id" option if available. + targetMsgID := "" + if opt := helpers.GetOption(options, "message_id"); opt != nil { + if val := opt.StringValue(); val != "" { + targetMsgID = val + // Store the target message ID keyed by the user's ID. + reactionRoleTarget[i.Member.User.ID] = targetMsgID + } + } // Build modal components: for each pair, add two text inputs (each in its own action row). modalComponents := []discordgo.MessageComponent{} @@ -265,9 +272,8 @@ func HandleReactionRoleModalSubmit(s *discordgo.Session, i *discordgo.Interactio btnStyle := mapStyle(styleStr) - log.Default().Println(targetMsgID, targetChannelID) - data := i.ModalSubmitData() + // There will be two action rows per pair. count := len(data.Components) / 2 var buttons []discordgo.MessageComponent diff --git a/Bot/Helpers/helpers.go b/Bot/Helpers/helpers.go index 93d9688..da310d6 100644 --- a/Bot/Helpers/helpers.go +++ b/Bot/Helpers/helpers.go @@ -2,8 +2,19 @@ package helpers import ( "fmt" + + "github.com/bwmarrin/discordgo" ) func CreateMessageLink(guildID, channelID, messageID string) string { return fmt.Sprintf("https://discord.com/channels/%s/%s/%s", guildID, channelID, messageID) } + +func GetOption(options []*discordgo.ApplicationCommandInteractionDataOption, name string) *discordgo.ApplicationCommandInteractionDataOption { + for _, opt := range options { + if opt.Name == name { + return opt + } + } + return nil +}