Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 16 additions & 33 deletions src/boost/coop_status_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ func ShowCoopStatusPermissionDialog(s *discordgo.Session, i *discordgo.Interacti
func HandleCoopStatusPermissionButton(s *discordgo.Session, i *discordgo.InteractionCreate) {
userID := bottools.GetInteractionUserID(i)
customID := i.MessageComponentData().CustomID
respondAndClose := func(content string) {
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseUpdateMessage,
Data: &discordgo.InteractionResponseData{
Content: content,
Flags: discordgo.MessageFlagsEphemeral,
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as above: InteractionResponseUpdateMessage updates should not include Flags. Setting MessageFlagsEphemeral in an update callback can be rejected by Discord or silently ignored. Suggestion: omit Flags from the update response, while still setting Content and clearing Components.

Suggested change
Flags: discordgo.MessageFlagsEphemeral,

Copilot uses AI. Check for mistakes.
Components: []discordgo.MessageComponent{},
},
})
if err != nil {
log.Println("Error updating coop status permission dialog:", err)
}
}

// Extract the action part after the "#"
parts := strings.Split(customID, "#")
Expand All @@ -123,46 +136,16 @@ func HandleCoopStatusPermissionButton(s *discordgo.Session, i *discordgo.Interac
farmerstate.SetMiscSettingString(userID, CoopStatusPermissionKey, time.Now().Format(time.RFC3339))
farmerstate.SetMiscSettingString(userID, CoopStatusPermissionSpanKey, "24h")

// Respond with ephemeral message asking to retry
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Permission granted for 24 hours. You can now run your command again.",
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
log.Println("Error responding to allow button:", err)
}
respondAndClose("Permission granted for 24 hours. You can now run your command again.")

case "allow7d":
// Set the timestamp to now
farmerstate.SetMiscSettingString(userID, CoopStatusPermissionKey, time.Now().Format(time.RFC3339))
farmerstate.SetMiscSettingString(userID, CoopStatusPermissionSpanKey, "7d")

// Respond with ephemeral message asking to retry
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Permission granted for 7 days. You can now run your command again.",
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
log.Println("Error responding to allow 7d button:", err)
}
respondAndClose("Permission granted for 7 days. You can now run your command again.")

case "close":
// Respond with ephemeral close message
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Dialog closed. You can enable this permission later when you're ready.",
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
log.Println("Error responding to close button:", err)
}
respondAndClose("Dialog closed. You can enable this permission later when you're ready.")
}
}
46 changes: 16 additions & 30 deletions src/boost/leaderboard_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ func ShowLeaderboardPermissionDialog(s *discordgo.Session, i *discordgo.Interact
func HandleLeaderboardPermissionButton(s *discordgo.Session, i *discordgo.InteractionCreate) {
userID := bottools.GetInteractionUserID(i)
customID := i.MessageComponentData().CustomID
respondAndClose := func(content string) {
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseUpdateMessage,
Data: &discordgo.InteractionResponseData{
Content: content,
Flags: discordgo.MessageFlagsEphemeral,
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InteractionResponseUpdateMessage responses generally cannot set Flags (ephemeral is only meaningful on the initial message creation). Including Flags: MessageFlagsEphemeral here may be ignored or can cause Discord to reject the interaction with an "Invalid Form Body" error. Suggestion: remove Flags from the update response data (the message will remain ephemeral since the original dialog message was ephemeral), and only clear Components + update Content.

Suggested change
Flags: discordgo.MessageFlagsEphemeral,

Copilot uses AI. Check for mistakes.
Components: []discordgo.MessageComponent{},
},
})
if err != nil {
log.Println("Error updating leaderboard permission dialog:", err)
}
}

parts := strings.Split(customID, "#")
if len(parts) < 2 {
Expand All @@ -100,42 +113,15 @@ func HandleLeaderboardPermissionButton(s *discordgo.Session, i *discordgo.Intera
farmerstate.SetMiscSettingString(userID, LeaderboardPermissionKey, time.Now().Format(time.RFC3339))
farmerstate.SetMiscSettingString(userID, LeaderboardPermissionSpanKey, "24h")

err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Permission granted for 24 hours. Please run your command again.",
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
log.Println("Error responding to leaderboard allow24h button:", err)
}
respondAndClose("Permission granted for 24 hours. Please run your command again.")

case "allowforever":
farmerstate.SetMiscSettingString(userID, LeaderboardPermissionKey, time.Now().Format(time.RFC3339))
farmerstate.SetMiscSettingString(userID, LeaderboardPermissionSpanKey, "forever")

err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Permission granted permanently. Please run your command again.",
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
log.Println("Error responding to leaderboard allowforever button:", err)
}
respondAndClose("Permission granted permanently. Please run your command again.")

case "close":
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Dialog closed.",
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
log.Println("Error responding to leaderboard close button:", err)
}
respondAndClose("Dialog closed.")
}
}
Loading