From 408f1b9c30019ff4b3e5ab5c2d62ff51e2c8ebc7 Mon Sep 17 00:00:00 2001 From: Lily Bergonzat Date: Mon, 26 Feb 2024 22:05:25 +0100 Subject: [PATCH] Added slash command deferral to avoid timeouts --- backend/src/pluginUtils.ts | 8 +++++++- backend/src/plugins/Common/CommonPlugin.ts | 4 ++-- .../ModActions/commands/addcase/AddCaseSlashCmd.ts | 1 + .../src/plugins/ModActions/commands/ban/BanSlashCmd.ts | 1 + .../src/plugins/ModActions/commands/case/CaseSlashCmd.ts | 1 + .../plugins/ModActions/commands/cases/CasesSlashCmd.ts | 2 ++ .../ModActions/commands/deletecase/DeleteCaseSlashCmd.ts | 2 ++ .../ModActions/commands/forceban/ForceBanSlashCmd.ts | 1 + .../ModActions/commands/forcemute/ForceMuteSlashCmd.ts | 1 + .../commands/forceunmute/ForceUnmuteSlashCmd.ts | 1 + .../ModActions/commands/hidecase/HideCaseSlashCmd.ts | 1 + .../src/plugins/ModActions/commands/kick/KickSlashCmd.ts | 1 + .../ModActions/commands/massban/MassBanSlashCmd.ts | 1 + .../ModActions/commands/massmute/MassMuteSlashCmd.ts | 1 + .../ModActions/commands/massunban/MassUnbanSlashCmd.ts | 1 + .../src/plugins/ModActions/commands/mute/MuteSlashCmd.ts | 1 + .../src/plugins/ModActions/commands/note/NoteSlashCmd.ts | 1 + .../plugins/ModActions/commands/unban/UnbanSlashCmd.ts | 1 + .../ModActions/commands/unhidecase/UnhideCaseSlashCmd.ts | 1 + .../plugins/ModActions/commands/unmute/UnmuteSlashCmd.ts | 1 + .../plugins/ModActions/commands/update/UpdateSlashCmd.ts | 2 ++ .../src/plugins/ModActions/commands/warn/WarnSlashCmd.ts | 1 + 22 files changed, 32 insertions(+), 3 deletions(-) diff --git a/backend/src/pluginUtils.ts b/backend/src/pluginUtils.ts index 9e7f9783..b49c4665 100644 --- a/backend/src/pluginUtils.ts +++ b/backend/src/pluginUtils.ts @@ -86,7 +86,13 @@ export async function sendContextResponse( if (isContextInteraction(context)) { const options = { ...(typeof response === "string" ? { content: response } : response), fetchReply: true }; - return (context.replied ? context.followUp(options) : context.reply(options)) as Promise; + return ( + context.replied + ? context.followUp(options) + : context.deferred + ? context.editReply(options) + : context.reply(options) + ) as Promise; } if (typeof response !== "string" && "ephemeral" in response) { diff --git a/backend/src/plugins/Common/CommonPlugin.ts b/backend/src/plugins/Common/CommonPlugin.ts index 7f9c2204..92c58b63 100644 --- a/backend/src/plugins/Common/CommonPlugin.ts +++ b/backend/src/plugins/Common/CommonPlugin.ts @@ -76,7 +76,7 @@ export const CommonPlugin = zeppelinGuildPlugin()({ }); } - const replyMethod = context.replied ? "editReply" : "reply"; + const replyMethod = context.replied || context.deferred ? "editReply" : "reply"; return context[replyMethod]({ content: formattedBody, @@ -127,7 +127,7 @@ export const CommonPlugin = zeppelinGuildPlugin()({ }); } - const replyMethod = context.replied ? "editReply" : "reply"; + const replyMethod = context.replied || context.deferred ? "editReply" : "reply"; return context[replyMethod]({ content: formattedBody, diff --git a/backend/src/plugins/ModActions/commands/addcase/AddCaseSlashCmd.ts b/backend/src/plugins/ModActions/commands/addcase/AddCaseSlashCmd.ts index 2fdaf6c8..c8ee903e 100644 --- a/backend/src/plugins/ModActions/commands/addcase/AddCaseSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/addcase/AddCaseSlashCmd.ts @@ -34,6 +34,7 @@ export const AddCaseSlashCmd = { ], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment"); // The moderator who did the action is the message author or, if used, the specified -mod diff --git a/backend/src/plugins/ModActions/commands/ban/BanSlashCmd.ts b/backend/src/plugins/ModActions/commands/ban/BanSlashCmd.ts index cae32c55..c1b0ebcd 100644 --- a/backend/src/plugins/ModActions/commands/ban/BanSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/ban/BanSlashCmd.ts @@ -47,6 +47,7 @@ export const BanSlashCmd = { signature: [slashOptions.user({ name: "user", description: "The user to ban", required: true }), ...opts], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment"); if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) { diff --git a/backend/src/plugins/ModActions/commands/case/CaseSlashCmd.ts b/backend/src/plugins/ModActions/commands/case/CaseSlashCmd.ts index 98219e3f..3394c086 100644 --- a/backend/src/plugins/ModActions/commands/case/CaseSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/case/CaseSlashCmd.ts @@ -18,6 +18,7 @@ export const CaseSlashCmd = { ], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); actualCaseCmd(pluginData, interaction, interaction.user.id, options["case-number"], options.show); }, }; diff --git a/backend/src/plugins/ModActions/commands/cases/CasesSlashCmd.ts b/backend/src/plugins/ModActions/commands/cases/CasesSlashCmd.ts index 3e720917..07a457ff 100644 --- a/backend/src/plugins/ModActions/commands/cases/CasesSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/cases/CasesSlashCmd.ts @@ -30,6 +30,8 @@ export const CasesSlashCmd = { signature: [...opts], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); + return actualCasesCmd( pluginData, interaction, diff --git a/backend/src/plugins/ModActions/commands/deletecase/DeleteCaseSlashCmd.ts b/backend/src/plugins/ModActions/commands/deletecase/DeleteCaseSlashCmd.ts index e087e3a4..89004847 100644 --- a/backend/src/plugins/ModActions/commands/deletecase/DeleteCaseSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/deletecase/DeleteCaseSlashCmd.ts @@ -16,6 +16,8 @@ export const DeleteCaseSlashCmd = { ], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); + actualDeleteCaseCmd( pluginData, interaction, diff --git a/backend/src/plugins/ModActions/commands/forceban/ForceBanSlashCmd.ts b/backend/src/plugins/ModActions/commands/forceban/ForceBanSlashCmd.ts index 57de4a0d..059ff2de 100644 --- a/backend/src/plugins/ModActions/commands/forceban/ForceBanSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/forceban/ForceBanSlashCmd.ts @@ -24,6 +24,7 @@ export const ForceBanSlashCmd = { signature: [slashOptions.user({ name: "user", description: "The user to ban", required: true }), ...opts], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment"); if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) { diff --git a/backend/src/plugins/ModActions/commands/forcemute/ForceMuteSlashCmd.ts b/backend/src/plugins/ModActions/commands/forcemute/ForceMuteSlashCmd.ts index 7bb65b73..6f7fa2ca 100644 --- a/backend/src/plugins/ModActions/commands/forcemute/ForceMuteSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/forcemute/ForceMuteSlashCmd.ts @@ -42,6 +42,7 @@ export const ForceMuteSlashCmd = { signature: [slashOptions.user({ name: "user", description: "The user to mute", required: true }), ...opts], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment"); if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) { diff --git a/backend/src/plugins/ModActions/commands/forceunmute/ForceUnmuteSlashCmd.ts b/backend/src/plugins/ModActions/commands/forceunmute/ForceUnmuteSlashCmd.ts index 5d93ef00..8ea323fe 100644 --- a/backend/src/plugins/ModActions/commands/forceunmute/ForceUnmuteSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/forceunmute/ForceUnmuteSlashCmd.ts @@ -25,6 +25,7 @@ export const ForceUnmuteSlashCmd = { signature: [slashOptions.user({ name: "user", description: "The user to unmute", required: true }), ...opts], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment"); if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) { diff --git a/backend/src/plugins/ModActions/commands/hidecase/HideCaseSlashCmd.ts b/backend/src/plugins/ModActions/commands/hidecase/HideCaseSlashCmd.ts index c324b250..95f48580 100644 --- a/backend/src/plugins/ModActions/commands/hidecase/HideCaseSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/hidecase/HideCaseSlashCmd.ts @@ -12,6 +12,7 @@ export const HideCaseSlashCmd = { ], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); actualHideCaseCmd(pluginData, interaction, options["case-number"].split(/[\s,]+/).map(Number)); }, }; diff --git a/backend/src/plugins/ModActions/commands/kick/KickSlashCmd.ts b/backend/src/plugins/ModActions/commands/kick/KickSlashCmd.ts index 98c46452..ce0a659b 100644 --- a/backend/src/plugins/ModActions/commands/kick/KickSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/kick/KickSlashCmd.ts @@ -46,6 +46,7 @@ export const KickSlashCmd = { signature: [slashOptions.user({ name: "user", description: "The user to kick", required: true }), ...opts], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment"); if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) { diff --git a/backend/src/plugins/ModActions/commands/massban/MassBanSlashCmd.ts b/backend/src/plugins/ModActions/commands/massban/MassBanSlashCmd.ts index 6905e0b1..ab8ea1d1 100644 --- a/backend/src/plugins/ModActions/commands/massban/MassBanSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/massban/MassBanSlashCmd.ts @@ -25,6 +25,7 @@ export const MassBanSlashCmd = { ], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment"); if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) { diff --git a/backend/src/plugins/ModActions/commands/massmute/MassMuteSlashCmd.ts b/backend/src/plugins/ModActions/commands/massmute/MassMuteSlashCmd.ts index da58647d..6f2c18ba 100644 --- a/backend/src/plugins/ModActions/commands/massmute/MassMuteSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/massmute/MassMuteSlashCmd.ts @@ -25,6 +25,7 @@ export const MassMuteSlashSlashCmd = { ], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment"); if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) { diff --git a/backend/src/plugins/ModActions/commands/massunban/MassUnbanSlashCmd.ts b/backend/src/plugins/ModActions/commands/massunban/MassUnbanSlashCmd.ts index ded26357..da079dfd 100644 --- a/backend/src/plugins/ModActions/commands/massunban/MassUnbanSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/massunban/MassUnbanSlashCmd.ts @@ -25,6 +25,7 @@ export const MassUnbanSlashCmd = { ], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment"); if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) { diff --git a/backend/src/plugins/ModActions/commands/mute/MuteSlashCmd.ts b/backend/src/plugins/ModActions/commands/mute/MuteSlashCmd.ts index 37b11b52..f20585a9 100644 --- a/backend/src/plugins/ModActions/commands/mute/MuteSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/mute/MuteSlashCmd.ts @@ -44,6 +44,7 @@ export const MuteSlashCmd = { signature: [slashOptions.user({ name: "user", description: "The user to mute", required: true }), ...opts], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment"); const memberToMute = await resolveMember(pluginData.client, pluginData.guild, options.user.id); diff --git a/backend/src/plugins/ModActions/commands/note/NoteSlashCmd.ts b/backend/src/plugins/ModActions/commands/note/NoteSlashCmd.ts index 9647d861..edcf60e9 100644 --- a/backend/src/plugins/ModActions/commands/note/NoteSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/note/NoteSlashCmd.ts @@ -21,6 +21,7 @@ export const NoteSlashCmd = { signature: [slashOptions.user({ name: "user", description: "The user to add a note to", required: true }), ...opts], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment"); if ((!options.note || options.note.trim() === "") && attachments.length < 1) { diff --git a/backend/src/plugins/ModActions/commands/unban/UnbanSlashCmd.ts b/backend/src/plugins/ModActions/commands/unban/UnbanSlashCmd.ts index 58be63b2..1a8a2181 100644 --- a/backend/src/plugins/ModActions/commands/unban/UnbanSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/unban/UnbanSlashCmd.ts @@ -23,6 +23,7 @@ export const UnbanSlashCmd = { signature: [slashOptions.user({ name: "user", description: "The user to unban", required: true }), ...opts], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment"); if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) { diff --git a/backend/src/plugins/ModActions/commands/unhidecase/UnhideCaseSlashCmd.ts b/backend/src/plugins/ModActions/commands/unhidecase/UnhideCaseSlashCmd.ts index d0a66d7c..92d3c0fb 100644 --- a/backend/src/plugins/ModActions/commands/unhidecase/UnhideCaseSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/unhidecase/UnhideCaseSlashCmd.ts @@ -12,6 +12,7 @@ export const UnhideCaseSlashCmd = { ], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); actualUnhideCaseCmd(pluginData, interaction, options["case-number"].split(/[\s,]+/).map(Number)); }, }; diff --git a/backend/src/plugins/ModActions/commands/unmute/UnmuteSlashCmd.ts b/backend/src/plugins/ModActions/commands/unmute/UnmuteSlashCmd.ts index 41ec3eac..df57fa05 100644 --- a/backend/src/plugins/ModActions/commands/unmute/UnmuteSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/unmute/UnmuteSlashCmd.ts @@ -28,6 +28,7 @@ export const UnmuteSlashCmd = { signature: [slashOptions.user({ name: "user", description: "The user to unmute", required: true }), ...opts], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment"); if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) { diff --git a/backend/src/plugins/ModActions/commands/update/UpdateSlashCmd.ts b/backend/src/plugins/ModActions/commands/update/UpdateSlashCmd.ts index 4f6fdae2..a1a6cabf 100644 --- a/backend/src/plugins/ModActions/commands/update/UpdateSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/update/UpdateSlashCmd.ts @@ -21,6 +21,8 @@ export const UpdateSlashCmd = { signature: [...opts], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); + await updateCase( pluginData, interaction, diff --git a/backend/src/plugins/ModActions/commands/warn/WarnSlashCmd.ts b/backend/src/plugins/ModActions/commands/warn/WarnSlashCmd.ts index 920326a5..7295551b 100644 --- a/backend/src/plugins/ModActions/commands/warn/WarnSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/warn/WarnSlashCmd.ts @@ -42,6 +42,7 @@ export const WarnSlashCmd = { signature: [slashOptions.user({ name: "user", description: "The user to warn", required: true }), ...opts], async run({ interaction, options, pluginData }) { + await interaction.deferReply({ ephemeral: true }); const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment"); if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) {