Skip to content

Commit

Permalink
poll,wyr: obey response autodeletion set via command overrides (botla…
Browse files Browse the repository at this point in the history
…bs-gg#1672)

* dcmd: add manual response marker

...designed for commands that send their responses manually as opposed to through dcmd, such as the poll command.

* poll,wyr: indicate to dcmd that responses are sent manually

This commit (combined with the previous) allows poll and wyr responses to be autodeleted after a delay via command overrides. Previously, the command system had no knowledge of responses to these commands (which are sent manually since reactions need to be added), so autodeletion did not work.
  • Loading branch information
jo3-l authored and ashishjh-bst committed Jun 27, 2024
1 parent 72b5c1d commit 2239235
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lib/dcmd/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ func (d *Data) SendFollowupMessage(reply interface{}, allowedMentions discordgo.
switch t := reply.(type) {
case Response:
return t.Send(d)
case ManualResponse:
return t.Messages, nil
case string:
if t != "" {
return SplitSendMessage(d, t, allowedMentions)
Expand Down
13 changes: 13 additions & 0 deletions lib/dcmd/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ func (t *TemporaryResponse) Send(data *Data) ([]*discordgo.Message, error) {
return msgs, nil
}

// ManualResponse is a marker indicating that the command responses have
// already sent manually; dcmd need not do anything.
type ManualResponse struct {
Messages []*discordgo.Message
}

// MarkManualResponse indicates to dcmd that the command has already responded
// to the command manually with the given messages, and that dcmd need not do
// anything further.
func MarkManualResponse(responses []*discordgo.Message) ManualResponse {
return ManualResponse{responses}
}

// SplitSendMessage uses SplitString to make sure each message is within 2k characters and splits at last newline before that (if possible)
func SplitSendMessage(data *Data, contents string, allowedMentions discordgo.AllowedMentions) ([]*discordgo.Message, error) {
result := make([]*discordgo.Message, 0, 1)
Expand Down
2 changes: 1 addition & 1 deletion stdcommands/poll/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ func createPoll(data *dcmd.Data) (interface{}, error) {
for i := range options {
common.BotSession.MessageReactionAdd(pollMsg.ChannelID, pollMsg.ID, pollReactions[i])
}
return nil, nil
return dcmd.MarkManualResponse([]*discordgo.Message{pollMsg}), nil
}
10 changes: 3 additions & 7 deletions stdcommands/wouldyourather/wouldyourather.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ var Command = &commands.YAGCommand{
}

common.BotSession.MessageReactionAdd(data.ChannelID, msg.ID, "🇦")
err = common.BotSession.MessageReactionAdd(data.ChannelID, msg.ID, "🇧")
if err != nil {
return nil, err
}

return nil, nil
common.BotSession.MessageReactionAdd(data.ChannelID, msg.ID, "🇧")
return dcmd.MarkManualResponse([]*discordgo.Message{msg}), nil
},
}
}

0 comments on commit 2239235

Please sign in to comment.