From b6915671ca2f731e9393d9a4ff5c931733d2b693 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sat, 22 May 2021 13:27:45 +0300 Subject: [PATCH] Add progress indicator to !massban. Tweak log/event ignoring to be more reliable for massbans. --- .../plugins/ModActions/commands/MassBanCmd.ts | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/backend/src/plugins/ModActions/commands/MassBanCmd.ts b/backend/src/plugins/ModActions/commands/MassBanCmd.ts index b43994b4..17209038 100644 --- a/backend/src/plugins/ModActions/commands/MassBanCmd.ts +++ b/backend/src/plugins/ModActions/commands/MassBanCmd.ts @@ -1,7 +1,7 @@ import { modActionsCmd, IgnoredEventType } from "../types"; import { commandTypeHelpers as ct } from "../../../commandTypes"; import { canActOn, sendErrorMessage, hasPermission, sendSuccessMessage } from "../../../pluginUtils"; -import { resolveUser, resolveMember, stripObjectToScalars } from "../../../utils"; +import { resolveUser, resolveMember, stripObjectToScalars, noop } from "../../../utils"; import { isBanned } from "../functions/isBanned"; import { readContactMethodsFromArgs } from "../functions/readContactMethodsFromArgs"; import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments"; @@ -50,22 +50,19 @@ export const MassbanCmd = modActionsCmd({ } } - // Ignore automatic ban cases and logs for these users - // We'll create our own cases below and post a single "mass banned" log instead - args.userIds.forEach(userId => { - // Use longer timeouts since this can take a while - ignoreEvent(pluginData, IgnoredEventType.Ban, userId, 120 * 1000); - pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_BAN, userId, 120 * 1000); - }); - // Show a loading indicator since this can take a while const loadingMsg = await msg.channel.createMessage("Banning..."); // Ban each user and count failed bans (if any) const failedBans: string[] = []; const casesPlugin = pluginData.getPlugin(CasesPlugin); - for (const userId of args.userIds) { + for (const [i, userId] of args.userIds.entries()) { try { + // Ignore automatic ban cases and logs + // We create our own cases below and post a single "mass banned" log instead + ignoreEvent(pluginData, IgnoredEventType.Ban, userId, 120 * 1000); + pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_BAN, userId, 120 * 1000); + await pluginData.guild.banMember(userId, 1, banReason != null ? encodeURIComponent(banReason) : undefined); await casesPlugin.createCase({ @@ -80,10 +77,15 @@ export const MassbanCmd = modActionsCmd({ } catch { failedBans.push(userId); } + + // Send a status update every 10 bans + if ((i + 1) % 10 === 0) { + loadingMsg.edit(`Banning... ${i + 1}/${args.userIds.length}`).catch(noop); + } } // Clear loading indicator - loadingMsg.delete(); + loadingMsg.delete().catch(noop); const successfulBanCount = args.userIds.length - failedBans.length; if (successfulBanCount === 0) {