From 2239235eb8e83fbfa5e15041903e1953083e3fee Mon Sep 17 00:00:00 2001 From: Joe L <56809242+jo3-l@users.noreply.github.com> Date: Wed, 19 Jun 2024 11:56:39 -0700 Subject: [PATCH] poll,wyr: obey response autodeletion set via command overrides (#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. --- lib/dcmd/data.go | 2 ++ lib/dcmd/response.go | 13 +++++++++++++ stdcommands/poll/poll.go | 2 +- stdcommands/wouldyourather/wouldyourather.go | 10 +++------- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/dcmd/data.go b/lib/dcmd/data.go index 4257562eb8..5c03fd97b2 100644 --- a/lib/dcmd/data.go +++ b/lib/dcmd/data.go @@ -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) diff --git a/lib/dcmd/response.go b/lib/dcmd/response.go index 2481121500..a67b85881a 100644 --- a/lib/dcmd/response.go +++ b/lib/dcmd/response.go @@ -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) diff --git a/stdcommands/poll/poll.go b/stdcommands/poll/poll.go index 6a3dd03d3e..6577afd1a5 100644 --- a/stdcommands/poll/poll.go +++ b/stdcommands/poll/poll.go @@ -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 } diff --git a/stdcommands/wouldyourather/wouldyourather.go b/stdcommands/wouldyourather/wouldyourather.go index 92ed5539b7..7e27e7e34a 100644 --- a/stdcommands/wouldyourather/wouldyourather.go +++ b/stdcommands/wouldyourather/wouldyourather.go @@ -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 }, -} \ No newline at end of file +}