diff --git a/backend/src/plugins/ModActions/commands/addcase/AddCaseSlashCmd.ts b/backend/src/plugins/ModActions/commands/addcase/AddCaseSlashCmd.ts index c83a6b42..2fdaf6c8 100644 --- a/backend/src/plugins/ModActions/commands/addcase/AddCaseSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/addcase/AddCaseSlashCmd.ts @@ -11,7 +11,7 @@ const opts = [ slashOptions.user({ name: "mod", description: "The moderator to add this case as", required: false }), ...generateAttachmentSlashOptions(NUMBER_ATTACHMENTS_CASE_CREATION, { name: "attachment", - description: "An attachment to add to the reason of the case", + description: "An attachment to add to the reason", }), ]; diff --git a/backend/src/plugins/ModActions/commands/ban/BanSlashCmd.ts b/backend/src/plugins/ModActions/commands/ban/BanSlashCmd.ts index dd86a546..cae32c55 100644 --- a/backend/src/plugins/ModActions/commands/ban/BanSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/ban/BanSlashCmd.ts @@ -34,7 +34,7 @@ const opts = [ }), ...generateAttachmentSlashOptions(NUMBER_ATTACHMENTS_CASE_CREATION, { name: "attachment", - description: "An attachment to add to the reason of the ban", + description: "An attachment to add to the reason", }), ]; diff --git a/backend/src/plugins/ModActions/commands/forceban/ForceBanSlashCmd.ts b/backend/src/plugins/ModActions/commands/forceban/ForceBanSlashCmd.ts index c246982e..57de4a0d 100644 --- a/backend/src/plugins/ModActions/commands/forceban/ForceBanSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/forceban/ForceBanSlashCmd.ts @@ -11,7 +11,7 @@ const opts = [ slashOptions.user({ name: "mod", description: "The moderator to ban as", required: false }), ...generateAttachmentSlashOptions(NUMBER_ATTACHMENTS_CASE_CREATION, { name: "attachment", - description: "An attachment to add to the reason of the ban", + description: "An attachment to add to the reason", }), ]; diff --git a/backend/src/plugins/ModActions/commands/forcemute/ForceMuteSlashCmd.ts b/backend/src/plugins/ModActions/commands/forcemute/ForceMuteSlashCmd.ts index a306fc4a..7bb65b73 100644 --- a/backend/src/plugins/ModActions/commands/forcemute/ForceMuteSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/forcemute/ForceMuteSlashCmd.ts @@ -29,7 +29,7 @@ const opts = [ }), ...generateAttachmentSlashOptions(NUMBER_ATTACHMENTS_CASE_CREATION, { name: "attachment", - description: "An attachment to add to the reason of the mute", + description: "An attachment to add to the reason", }), ]; diff --git a/backend/src/plugins/ModActions/commands/forceunmute/ForceUnmuteSlashCmd.ts b/backend/src/plugins/ModActions/commands/forceunmute/ForceUnmuteSlashCmd.ts index 6bf6ca90..5d93ef00 100644 --- a/backend/src/plugins/ModActions/commands/forceunmute/ForceUnmuteSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/forceunmute/ForceUnmuteSlashCmd.ts @@ -12,7 +12,7 @@ const opts = [ slashOptions.user({ name: "mod", description: "The moderator to unmute as", required: false }), ...generateAttachmentSlashOptions(NUMBER_ATTACHMENTS_CASE_CREATION, { name: "attachment", - description: "An attachment to add to the reason of the unmute", + description: "An attachment to add to the reason", }), ]; diff --git a/backend/src/plugins/ModActions/commands/kick/KickSlashCmd.ts b/backend/src/plugins/ModActions/commands/kick/KickSlashCmd.ts index 961445ec..98c46452 100644 --- a/backend/src/plugins/ModActions/commands/kick/KickSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/kick/KickSlashCmd.ts @@ -33,7 +33,7 @@ const opts = [ }), ...generateAttachmentSlashOptions(NUMBER_ATTACHMENTS_CASE_CREATION, { name: "attachment", - description: "An attachment to add to the reason of the kick", + description: "An attachment to add to the reason", }), ]; diff --git a/backend/src/plugins/ModActions/commands/massban/MassBanMsgCmd.ts b/backend/src/plugins/ModActions/commands/massban/MassBanMsgCmd.ts index d607224a..d2f72c70 100644 --- a/backend/src/plugins/ModActions/commands/massban/MassBanMsgCmd.ts +++ b/backend/src/plugins/ModActions/commands/massban/MassBanMsgCmd.ts @@ -1,4 +1,7 @@ +import { waitForReply } from "knub/helpers"; import { commandTypeHelpers as ct } from "../../../../commandTypes"; +import { getContextChannel, sendContextResponse } from "../../../../pluginUtils"; +import { CommonPlugin } from "../../../Common/CommonPlugin"; import { actualMassBanCmd } from "../../functions/actualCommands/actualMassBanCmd"; import { modActionsMsgCmd } from "../../types"; @@ -14,6 +17,17 @@ export const MassBanMsgCmd = modActionsMsgCmd({ ], async run({ pluginData, message: msg, args }) { - actualMassBanCmd(pluginData, msg, args.userIds, msg.member); + // Ask for ban reason (cleaner this way instead of trying to cram it into the args) + sendContextResponse(msg, "Ban reason? `cancel` to cancel"); + const banReasonReply = await waitForReply(pluginData.client, await getContextChannel(msg), msg.author.id); + + if (!banReasonReply || !banReasonReply.content || banReasonReply.content.toLowerCase().trim() === "cancel") { + pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Cancelled"); + return; + } + + actualMassBanCmd(pluginData, msg, args.userIds, msg.member, banReasonReply.content, [ + ...banReasonReply.attachments.values(), + ]); }, }); diff --git a/backend/src/plugins/ModActions/commands/massban/MassBanSlashCmd.ts b/backend/src/plugins/ModActions/commands/massban/MassBanSlashCmd.ts index 74f9ba91..6905e0b1 100644 --- a/backend/src/plugins/ModActions/commands/massban/MassBanSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/massban/MassBanSlashCmd.ts @@ -1,5 +1,16 @@ import { slashOptions } from "knub"; +import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions"; +import { CommonPlugin } from "../../../Common/CommonPlugin"; import { actualMassBanCmd } from "../../functions/actualCommands/actualMassBanCmd"; +import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants"; + +const opts = [ + slashOptions.string({ name: "reason", description: "The reason", required: false }), + ...generateAttachmentSlashOptions(NUMBER_ATTACHMENTS_CASE_CREATION, { + name: "attachment", + description: "An attachment to add to the reason", + }), +]; export const MassBanSlashCmd = { name: "massban", @@ -7,9 +18,30 @@ export const MassBanSlashCmd = { description: "Mass-ban a list of user IDs", allowDms: false, - signature: [slashOptions.string({ name: "user-ids", description: "The list of user IDs to ban", required: true })], + signature: [ + slashOptions.string({ name: "user-ids", description: "The list of user IDs to ban", required: true }), + + ...opts, + ], async run({ interaction, options, pluginData }) { - actualMassBanCmd(pluginData, interaction, options["user-ids"].split(/[\s,\r\n]+/), interaction.member); + const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment"); + + if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) { + pluginData + .getPlugin(CommonPlugin) + .sendErrorMessage(interaction, "Text or attachment required", undefined, undefined, true); + + return; + } + + actualMassBanCmd( + pluginData, + interaction, + options["user-ids"].split(/[\s,\r\n]+/), + interaction.member, + options.reason || "", + attachments, + ); }, }; diff --git a/backend/src/plugins/ModActions/commands/massmute/MassMuteMsgCmd.ts b/backend/src/plugins/ModActions/commands/massmute/MassMuteMsgCmd.ts index a09a5f26..713e89dd 100644 --- a/backend/src/plugins/ModActions/commands/massmute/MassMuteMsgCmd.ts +++ b/backend/src/plugins/ModActions/commands/massmute/MassMuteMsgCmd.ts @@ -1,4 +1,7 @@ +import { waitForReply } from "knub/helpers"; import { commandTypeHelpers as ct } from "../../../../commandTypes"; +import { getContextChannel, sendContextResponse } from "../../../../pluginUtils"; +import { CommonPlugin } from "../../../Common/CommonPlugin"; import { actualMassMuteCmd } from "../../functions/actualCommands/actualMassMuteCmd"; import { modActionsMsgCmd } from "../../types"; @@ -14,6 +17,20 @@ export const MassMuteMsgCmd = modActionsMsgCmd({ ], async run({ pluginData, message: msg, args }) { - actualMassMuteCmd(pluginData, msg, args.userIds, msg.member); + // Ask for mute reason + sendContextResponse(msg, "Mute reason? `cancel` to cancel"); + const muteReasonReceived = await waitForReply(pluginData.client, await getContextChannel(msg), msg.author.id); + if ( + !muteReasonReceived || + !muteReasonReceived.content || + muteReasonReceived.content.toLowerCase().trim() === "cancel" + ) { + pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Cancelled"); + return; + } + + actualMassMuteCmd(pluginData, msg, args.userIds, msg.member, muteReasonReceived.content, [ + ...muteReasonReceived.attachments.values(), + ]); }, }); diff --git a/backend/src/plugins/ModActions/commands/massmute/MassMuteSlashCmd.ts b/backend/src/plugins/ModActions/commands/massmute/MassMuteSlashCmd.ts index 1650b174..da58647d 100644 --- a/backend/src/plugins/ModActions/commands/massmute/MassMuteSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/massmute/MassMuteSlashCmd.ts @@ -1,5 +1,16 @@ import { slashOptions } from "knub"; +import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions"; +import { CommonPlugin } from "../../../Common/CommonPlugin"; import { actualMassMuteCmd } from "../../functions/actualCommands/actualMassMuteCmd"; +import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants"; + +const opts = [ + slashOptions.string({ name: "reason", description: "The reason", required: false }), + ...generateAttachmentSlashOptions(NUMBER_ATTACHMENTS_CASE_CREATION, { + name: "attachment", + description: "An attachment to add to the reason", + }), +]; export const MassMuteSlashSlashCmd = { name: "massmute", @@ -7,9 +18,30 @@ export const MassMuteSlashSlashCmd = { description: "Mass-mute a list of user IDs", allowDms: false, - signature: [slashOptions.string({ name: "user-ids", description: "The list of user IDs to mute", required: true })], + signature: [ + slashOptions.string({ name: "user-ids", description: "The list of user IDs to mute", required: true }), + + ...opts, + ], async run({ interaction, options, pluginData }) { - actualMassMuteCmd(pluginData, interaction, options["user-ids"].split(/[\s,\r\n]+/), interaction.member); + const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment"); + + if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) { + pluginData + .getPlugin(CommonPlugin) + .sendErrorMessage(interaction, "Text or attachment required", undefined, undefined, true); + + return; + } + + actualMassMuteCmd( + pluginData, + interaction, + options["user-ids"].split(/[\s,\r\n]+/), + interaction.member, + options.reason || "", + attachments, + ); }, }; diff --git a/backend/src/plugins/ModActions/commands/massunban/MassUnbanMsgCmd.ts b/backend/src/plugins/ModActions/commands/massunban/MassUnbanMsgCmd.ts index 72713ad5..121be1cb 100644 --- a/backend/src/plugins/ModActions/commands/massunban/MassUnbanMsgCmd.ts +++ b/backend/src/plugins/ModActions/commands/massunban/MassUnbanMsgCmd.ts @@ -1,5 +1,8 @@ +import { waitForReply } from "knub/helpers"; import { commandTypeHelpers as ct } from "../../../../commandTypes"; -import { actualMassBanCmd } from "../../functions/actualCommands/actualMassBanCmd"; +import { getContextChannel, sendContextResponse } from "../../../../pluginUtils"; +import { CommonPlugin } from "../../../Common/CommonPlugin"; +import { actualMassUnbanCmd } from "../../functions/actualCommands/actualMassUnbanCmd"; import { modActionsMsgCmd } from "../../types"; export const MassUnbanMsgCmd = modActionsMsgCmd({ @@ -14,6 +17,16 @@ export const MassUnbanMsgCmd = modActionsMsgCmd({ ], async run({ pluginData, message: msg, args }) { - actualMassBanCmd(pluginData, msg, args.userIds, msg.member); + // Ask for unban reason (cleaner this way instead of trying to cram it into the args) + sendContextResponse(msg, "Unban reason? `cancel` to cancel"); + const unbanReasonReply = await waitForReply(pluginData.client, await getContextChannel(msg), msg.author.id); + if (!unbanReasonReply || !unbanReasonReply.content || unbanReasonReply.content.toLowerCase().trim() === "cancel") { + pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Cancelled"); + return; + } + + actualMassUnbanCmd(pluginData, msg, args.userIds, msg.member, unbanReasonReply.content, [ + ...unbanReasonReply.attachments.values(), + ]); }, }); diff --git a/backend/src/plugins/ModActions/commands/massunban/MassUnbanSlashCmd.ts b/backend/src/plugins/ModActions/commands/massunban/MassUnbanSlashCmd.ts index 15f6ca6a..ded26357 100644 --- a/backend/src/plugins/ModActions/commands/massunban/MassUnbanSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/massunban/MassUnbanSlashCmd.ts @@ -1,5 +1,16 @@ import { slashOptions } from "knub"; +import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions"; +import { CommonPlugin } from "../../../Common/CommonPlugin"; import { actualMassUnbanCmd } from "../../functions/actualCommands/actualMassUnbanCmd"; +import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants"; + +const opts = [ + slashOptions.string({ name: "reason", description: "The reason", required: false }), + ...generateAttachmentSlashOptions(NUMBER_ATTACHMENTS_CASE_CREATION, { + name: "attachment", + description: "An attachment to add to the reason", + }), +]; export const MassUnbanSlashCmd = { name: "massunban", @@ -7,9 +18,30 @@ export const MassUnbanSlashCmd = { description: "Mass-unban a list of user IDs", allowDms: false, - signature: [slashOptions.string({ name: "user-ids", description: "The list of user IDs to unban", required: true })], + signature: [ + slashOptions.string({ name: "user-ids", description: "The list of user IDs to unban", required: true }), + + ...opts, + ], async run({ interaction, options, pluginData }) { - actualMassUnbanCmd(pluginData, interaction, options["user-ids"].split(/[\s,\r\n]+/), interaction.member); + const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment"); + + if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) { + pluginData + .getPlugin(CommonPlugin) + .sendErrorMessage(interaction, "Text or attachment required", undefined, undefined, true); + + return; + } + + actualMassUnbanCmd( + pluginData, + interaction, + options["user-ids"].split(/[\s,\r\n]+/), + interaction.member, + options.reason || "", + attachments, + ); }, }; diff --git a/backend/src/plugins/ModActions/commands/mute/MuteSlashCmd.ts b/backend/src/plugins/ModActions/commands/mute/MuteSlashCmd.ts index b3fb3f01..37b11b52 100644 --- a/backend/src/plugins/ModActions/commands/mute/MuteSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/mute/MuteSlashCmd.ts @@ -31,7 +31,7 @@ const opts = [ }), ...generateAttachmentSlashOptions(NUMBER_ATTACHMENTS_CASE_CREATION, { name: "attachment", - description: "An attachment to add to the reason of the mute", + description: "An attachment to add to the reason", }), ]; diff --git a/backend/src/plugins/ModActions/commands/unban/UnbanSlashCmd.ts b/backend/src/plugins/ModActions/commands/unban/UnbanSlashCmd.ts index abc969de..58be63b2 100644 --- a/backend/src/plugins/ModActions/commands/unban/UnbanSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/unban/UnbanSlashCmd.ts @@ -10,7 +10,7 @@ const opts = [ slashOptions.user({ name: "mod", description: "The moderator to unban as", required: false }), ...generateAttachmentSlashOptions(NUMBER_ATTACHMENTS_CASE_CREATION, { name: "attachment", - description: "An attachment to add to the reason of the unban", + description: "An attachment to add to the reason", }), ]; diff --git a/backend/src/plugins/ModActions/commands/unmute/UnmuteSlashCmd.ts b/backend/src/plugins/ModActions/commands/unmute/UnmuteSlashCmd.ts index 5186e86b..41ec3eac 100644 --- a/backend/src/plugins/ModActions/commands/unmute/UnmuteSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/unmute/UnmuteSlashCmd.ts @@ -15,7 +15,7 @@ const opts = [ slashOptions.user({ name: "mod", description: "The moderator to unmute as", required: false }), ...generateAttachmentSlashOptions(NUMBER_ATTACHMENTS_CASE_CREATION, { name: "attachment", - description: "An attachment to add to the reason of the unmute", + description: "An attachment to add to the reason", }), ]; diff --git a/backend/src/plugins/ModActions/commands/warn/WarnSlashCmd.ts b/backend/src/plugins/ModActions/commands/warn/WarnSlashCmd.ts index 43f796f2..920326a5 100644 --- a/backend/src/plugins/ModActions/commands/warn/WarnSlashCmd.ts +++ b/backend/src/plugins/ModActions/commands/warn/WarnSlashCmd.ts @@ -29,7 +29,7 @@ const opts = [ }), ...generateAttachmentSlashOptions(NUMBER_ATTACHMENTS_CASE_CREATION, { name: "attachment", - description: "An attachment to add to the reason of the warn", + description: "An attachment to add to the reason", }), ]; diff --git a/backend/src/plugins/ModActions/functions/actualCommands/actualMassBanCmd.ts b/backend/src/plugins/ModActions/functions/actualCommands/actualMassBanCmd.ts index 2b35c51a..f1c4953c 100644 --- a/backend/src/plugins/ModActions/functions/actualCommands/actualMassBanCmd.ts +++ b/backend/src/plugins/ModActions/functions/actualCommands/actualMassBanCmd.ts @@ -1,6 +1,5 @@ -import { ChatInputCommandInteraction, GuildMember, Message, Snowflake } from "discord.js"; +import { Attachment, ChatInputCommandInteraction, GuildMember, Message, Snowflake } from "discord.js"; import { GuildPluginData } from "knub"; -import { waitForReply } from "knub/helpers"; import { CaseTypes } from "../../../../data/CaseTypes"; import { LogType } from "../../../../data/LogType"; import { humanizeDurationShort } from "../../../../humanizeDurationShort"; @@ -19,6 +18,8 @@ export async function actualMassBanCmd( context: Message | ChatInputCommandInteraction, userIds: string[], author: GuildMember, + reason: string, + attachments: Attachment[], ) { // Limit to 100 users at once (arbitrary?) if (userIds.length > 100) { @@ -26,25 +27,12 @@ export async function actualMassBanCmd( return; } - // Ask for ban reason (cleaner this way instead of trying to cram it into the args) - sendContextResponse(context, "Ban reason? `cancel` to cancel"); - const banReasonReply = await waitForReply(pluginData.client, await getContextChannel(context), author.id); - - if (!banReasonReply || !banReasonReply.content || banReasonReply.content.toLowerCase().trim() === "cancel") { - pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "Cancelled"); + if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) { return; } - if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, banReasonReply.content)) { - return; - } - - const banReason = await formatReasonWithMessageLinkForAttachments(pluginData, banReasonReply.content, context, [ - ...banReasonReply.attachments.values(), - ]); - const banReasonWithAttachments = formatReasonWithAttachments(banReasonReply.content, [ - ...banReasonReply.attachments.values(), - ]); + const banReason = await formatReasonWithMessageLinkForAttachments(pluginData, reason, context, attachments); + const banReasonWithAttachments = formatReasonWithAttachments(reason, attachments); // Verify we can act on each of the users specified for (const userId of userIds) { @@ -64,7 +52,7 @@ export async function actualMassBanCmd( pluginData.state.massbanQueue.length === 0 ? "Banning..." : `Massban queued. Waiting for previous massban to finish (max wait ${maxWaitTimeFormatted}).`; - const loadingMsg = await sendContextResponse(context, initialLoadingText); + const loadingMsg = await sendContextResponse(context, { content: initialLoadingText, ephemeral: true }); const waitTimeStart = performance.now(); const waitingInterval = setInterval(() => { @@ -78,11 +66,20 @@ export async function actualMassBanCmd( clearInterval(waitingInterval); if (pluginData.state.unloaded) { - void loadingMsg.delete().catch(noop); + if (isContextInteraction(context)) { + void context.deleteReply().catch(noop); + } else { + void loadingMsg.delete().catch(noop); + } + return; } - void loadingMsg.edit("Banning...").catch(noop); + if (isContextInteraction(context)) { + void context.editReply("Banning...").catch(noop); + } else { + void loadingMsg.edit("Banning...").catch(noop); + } // Ban each user and count failed bans (if any) const startTime = performance.now(); @@ -124,15 +121,23 @@ export async function actualMassBanCmd( // Send a status update every 10 bans if ((i + 1) % 10 === 0) { - loadingMsg.edit(`Banning... ${i + 1}/${userIds.length}`).catch(noop); + const newLoadingMessageContent = `Banning... ${i + 1}/${userIds.length}`; + + if (isContextInteraction(context)) { + void context.editReply(newLoadingMessageContent).catch(noop); + } else { + loadingMsg.edit(newLoadingMessageContent).catch(noop); + } } } const totalTime = performance.now() - startTime; const formattedTimeTaken = humanizeDurationShort(totalTime, { round: true }); - // Clear loading indicator - loadingMsg.delete().catch(noop); + if (!isContextInteraction(context)) { + // Clear loading indicator + loadingMsg.delete().catch(noop); + } const successfulBanCount = userIds.length - failedBans.length; if (successfulBanCount === 0) { diff --git a/backend/src/plugins/ModActions/functions/actualCommands/actualMassMuteCmd.ts b/backend/src/plugins/ModActions/functions/actualCommands/actualMassMuteCmd.ts index 2d8086cb..53a82421 100644 --- a/backend/src/plugins/ModActions/functions/actualCommands/actualMassMuteCmd.ts +++ b/backend/src/plugins/ModActions/functions/actualCommands/actualMassMuteCmd.ts @@ -1,9 +1,8 @@ -import { ChatInputCommandInteraction, GuildMember, Message, Snowflake } from "discord.js"; +import { Attachment, ChatInputCommandInteraction, GuildMember, Message, Snowflake } from "discord.js"; import { GuildPluginData } from "knub"; -import { waitForReply } from "knub/helpers"; import { LogType } from "../../../../data/LogType"; import { logger } from "../../../../logger"; -import { canActOn, getContextChannel, sendContextResponse } from "../../../../pluginUtils"; +import { canActOn, isContextInteraction, sendContextResponse } from "../../../../pluginUtils"; import { CommonPlugin } from "../../../Common/CommonPlugin"; import { LogsPlugin } from "../../../Logs/LogsPlugin"; import { MutesPlugin } from "../../../Mutes/MutesPlugin"; @@ -16,6 +15,8 @@ export async function actualMassMuteCmd( context: Message | ChatInputCommandInteraction, userIds: string[], author: GuildMember, + reason: string, + attachments: Attachment[], ) { // Limit to 100 users at once (arbitrary?) if (userIds.length > 100) { @@ -23,28 +24,12 @@ export async function actualMassMuteCmd( return; } - // Ask for mute reason - sendContextResponse(context, "Mute reason? `cancel` to cancel"); - const muteReasonReceived = await waitForReply(pluginData.client, await getContextChannel(context), author.id); - if ( - !muteReasonReceived || - !muteReasonReceived.content || - muteReasonReceived.content.toLowerCase().trim() === "cancel" - ) { - pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "Cancelled"); + if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) { return; } - if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, muteReasonReceived.content)) { - return; - } - - const muteReason = await formatReasonWithMessageLinkForAttachments(pluginData, muteReasonReceived.content, context, [ - ...muteReasonReceived.attachments.values(), - ]); - const muteReasonWithAttachments = formatReasonWithAttachments(muteReasonReceived.content, [ - ...muteReasonReceived.attachments.values(), - ]); + const muteReason = await formatReasonWithMessageLinkForAttachments(pluginData, reason, context, attachments); + const muteReasonWithAttachments = formatReasonWithAttachments(reason, attachments); // Verify we can act upon all users for (const userId of userIds) { @@ -65,7 +50,7 @@ export async function actualMassMuteCmd( }); // Show loading indicator - const loadingMsg = await sendContextResponse(context, "Muting..."); + const loadingMsg = await sendContextResponse(context, { content: "Muting...", ephemeral: true }); // Mute everyone and count fails const modId = author.id; @@ -84,8 +69,10 @@ export async function actualMassMuteCmd( } } - // Clear loading indicator - loadingMsg.delete(); + if (!isContextInteraction(context)) { + // Clear loading indicator + loadingMsg.delete(); + } const successfulMuteCount = userIds.length - failedMutes.length; if (successfulMuteCount === 0) { diff --git a/backend/src/plugins/ModActions/functions/actualCommands/actualMassUnbanCmd.ts b/backend/src/plugins/ModActions/functions/actualCommands/actualMassUnbanCmd.ts index a980445c..8cf1b4ac 100644 --- a/backend/src/plugins/ModActions/functions/actualCommands/actualMassUnbanCmd.ts +++ b/backend/src/plugins/ModActions/functions/actualCommands/actualMassUnbanCmd.ts @@ -1,10 +1,9 @@ -import { ChatInputCommandInteraction, GuildMember, Message, Snowflake } from "discord.js"; +import { Attachment, ChatInputCommandInteraction, GuildMember, Message, Snowflake } from "discord.js"; import { GuildPluginData } from "knub"; -import { waitForReply } from "knub/helpers"; import { CaseTypes } from "../../../../data/CaseTypes"; import { LogType } from "../../../../data/LogType"; -import { getContextChannel, sendContextResponse } from "../../../../pluginUtils"; -import { MINUTES } from "../../../../utils"; +import { isContextInteraction, sendContextResponse } from "../../../../pluginUtils"; +import { MINUTES, noop } from "../../../../utils"; import { CasesPlugin } from "../../../Cases/CasesPlugin"; import { CommonPlugin } from "../../../Common/CommonPlugin"; import { LogsPlugin } from "../../../Logs/LogsPlugin"; @@ -19,6 +18,8 @@ export async function actualMassUnbanCmd( context: Message | ChatInputCommandInteraction, userIds: string[], author: GuildMember, + reason: string, + attachments: Attachment[], ) { // Limit to 100 users at once (arbitrary?) if (userIds.length > 100) { @@ -26,21 +27,11 @@ export async function actualMassUnbanCmd( return; } - // Ask for unban reason (cleaner this way instead of trying to cram it into the args) - sendContextResponse(context, "Unban reason? `cancel` to cancel"); - const unbanReasonReply = await waitForReply(pluginData.client, await getContextChannel(context), author.id); - if (!unbanReasonReply || !unbanReasonReply.content || unbanReasonReply.content.toLowerCase().trim() === "cancel") { - pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "Cancelled"); + if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) { return; } - if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, unbanReasonReply.content)) { - return; - } - - const unbanReason = await formatReasonWithMessageLinkForAttachments(pluginData, unbanReasonReply.content, context, [ - ...unbanReasonReply.attachments.values(), - ]); + const unbanReason = await formatReasonWithMessageLinkForAttachments(pluginData, reason, context, attachments); // Ignore automatic unban cases and logs for these users // We'll create our own cases below and post a single "mass unbanned" log instead @@ -51,7 +42,7 @@ export async function actualMassUnbanCmd( }); // Show a loading indicator since this can take a while - const loadingMsg = await sendContextResponse(context, "Unbanning..."); + const loadingMsg = await sendContextResponse(context, { content: "Unbanning...", ephemeral: true }); // Unban each user and count failed unbans (if any) const failedUnbans: Array<{ userId: string; reason: UnbanFailReasons }> = []; @@ -77,8 +68,10 @@ export async function actualMassUnbanCmd( } } - // Clear loading indicator - loadingMsg.delete(); + if (!isContextInteraction(context)) { + // Clear loading indicator + loadingMsg.delete().catch(noop); + } const successfulUnbanCount = userIds.length - failedUnbans.length; if (successfulUnbanCount === 0) {