@@ -109,6 +109,19 @@ func ShowCoopStatusPermissionDialog(s *discordgo.Session, i *discordgo.Interacti
109109func HandleCoopStatusPermissionButton (s * discordgo.Session , i * discordgo.InteractionCreate ) {
110110 userID := bottools .GetInteractionUserID (i )
111111 customID := i .MessageComponentData ().CustomID
112+ respondAndClose := func (content string ) {
113+ err := s .InteractionRespond (i .Interaction , & discordgo.InteractionResponse {
114+ Type : discordgo .InteractionResponseUpdateMessage ,
115+ Data : & discordgo.InteractionResponseData {
116+ Content : content ,
117+ Flags : discordgo .MessageFlagsEphemeral ,
118+ Components : []discordgo.MessageComponent {},
119+ },
120+ })
121+ if err != nil {
122+ log .Println ("Error updating coop status permission dialog:" , err )
123+ }
124+ }
112125
113126 // Extract the action part after the "#"
114127 parts := strings .Split (customID , "#" )
@@ -123,46 +136,16 @@ func HandleCoopStatusPermissionButton(s *discordgo.Session, i *discordgo.Interac
123136 farmerstate .SetMiscSettingString (userID , CoopStatusPermissionKey , time .Now ().Format (time .RFC3339 ))
124137 farmerstate .SetMiscSettingString (userID , CoopStatusPermissionSpanKey , "24h" )
125138
126- // Respond with ephemeral message asking to retry
127- err := s .InteractionRespond (i .Interaction , & discordgo.InteractionResponse {
128- Type : discordgo .InteractionResponseChannelMessageWithSource ,
129- Data : & discordgo.InteractionResponseData {
130- Content : "Permission granted for 24 hours. You can now run your command again." ,
131- Flags : discordgo .MessageFlagsEphemeral ,
132- },
133- })
134- if err != nil {
135- log .Println ("Error responding to allow button:" , err )
136- }
139+ respondAndClose ("Permission granted for 24 hours. You can now run your command again." )
137140
138141 case "allow7d" :
139142 // Set the timestamp to now
140143 farmerstate .SetMiscSettingString (userID , CoopStatusPermissionKey , time .Now ().Format (time .RFC3339 ))
141144 farmerstate .SetMiscSettingString (userID , CoopStatusPermissionSpanKey , "7d" )
142145
143- // Respond with ephemeral message asking to retry
144- err := s .InteractionRespond (i .Interaction , & discordgo.InteractionResponse {
145- Type : discordgo .InteractionResponseChannelMessageWithSource ,
146- Data : & discordgo.InteractionResponseData {
147- Content : "Permission granted for 7 days. You can now run your command again." ,
148- Flags : discordgo .MessageFlagsEphemeral ,
149- },
150- })
151- if err != nil {
152- log .Println ("Error responding to allow 7d button:" , err )
153- }
146+ respondAndClose ("Permission granted for 7 days. You can now run your command again." )
154147
155148 case "close" :
156- // Respond with ephemeral close message
157- err := s .InteractionRespond (i .Interaction , & discordgo.InteractionResponse {
158- Type : discordgo .InteractionResponseChannelMessageWithSource ,
159- Data : & discordgo.InteractionResponseData {
160- Content : "Dialog closed. You can enable this permission later when you're ready." ,
161- Flags : discordgo .MessageFlagsEphemeral ,
162- },
163- })
164- if err != nil {
165- log .Println ("Error responding to close button:" , err )
166- }
149+ respondAndClose ("Dialog closed. You can enable this permission later when you're ready." )
167150 }
168151}
0 commit comments