From 5e636b485acef4178f26965af872f96c8ab35413 Mon Sep 17 00:00:00 2001 From: Dark <7890309+DarkView@users.noreply.github.com> Date: Fri, 20 Nov 2020 02:31:31 +0100 Subject: [PATCH] Allow ban to be upgraded to forceban if the member is not on the server --- .../src/plugins/ModActions/commands/BanCmd.ts | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/backend/src/plugins/ModActions/commands/BanCmd.ts b/backend/src/plugins/ModActions/commands/BanCmd.ts index abd5fb68..38658e88 100644 --- a/backend/src/plugins/ModActions/commands/BanCmd.ts +++ b/backend/src/plugins/ModActions/commands/BanCmd.ts @@ -8,6 +8,7 @@ import { formatReasonWithAttachments } from "../functions/formatReasonWithAttach import { banUserId } from "../functions/banUserId"; import { ignoreEvent } from "../functions/ignoreEvent"; import { LogType } from "../../../data/LogType"; +import { waitForReaction } from "knub/dist/helpers"; const opts = { mod: ct.member({ option: true }), @@ -36,19 +37,30 @@ export const BanCmd = modActionsCmd({ const memberToBan = await resolveMember(pluginData.client, pluginData.guild, user.id); + let forceban = false; if (!memberToBan) { const banned = await isBanned(pluginData, user.id); + if (banned) { sendErrorMessage(pluginData, msg.channel, `User is already banned`); + return; } else { - sendErrorMessage(pluginData, msg.channel, `User not found on the server`); - } + // Ask the mod if we should upgrade to a forceban as the user is not on the server + const notOnServerMsg = await msg.channel.createMessage("User not found on the server, forceban instead?"); + const reply = await waitForReaction(pluginData.client, notOnServerMsg, ["✅", "❌"], msg.author.id); - return; + notOnServerMsg.delete(); + if (!reply || reply.name === "❌") { + sendErrorMessage(pluginData, msg.channel, "User not on server, ban cancelled by moderator"); + return; + } else { + forceban = true; + } + } } - // Make sure we're allowed to ban this member - if (!canActOn(pluginData, msg.member, memberToBan)) { + // Make sure we're allowed to ban this member if they are on the server + if (!forceban && !canActOn(pluginData, msg.member, memberToBan!)) { sendErrorMessage(pluginData, msg.channel, "Cannot ban: insufficient permissions"); return; } @@ -74,7 +86,7 @@ export const BanCmd = modActionsCmd({ const deleteMessageDays = args["delete-days"] ?? pluginData.config.getForMessage(msg).ban_delete_message_days; const reason = formatReasonWithAttachments(args.reason, msg.attachments); - const banResult = await banUserId(pluginData, memberToBan.id, reason, { + const banResult = await banUserId(pluginData, user.id, reason, { contactMethods, caseArgs: { modId: mod.id, @@ -89,9 +101,14 @@ export const BanCmd = modActionsCmd({ } // Confirm the action to the moderator - let response = `Banned **${memberToBan.user.username}#${memberToBan.user.discriminator}** (Case #${banResult.case.case_number})`; + let response = ""; + if (!forceban) { + response = `Banned **${user.username}#${user.discriminator}** (Case #${banResult.case.case_number})`; + if (banResult.notifyResult.text) response += ` (${banResult.notifyResult.text})`; + } else { + response = `Member forcebanned (Case #${banResult.case.case_number})`; + } - if (banResult.notifyResult.text) response += ` (${banResult.notifyResult.text})`; sendSuccessMessage(pluginData, msg.channel, response); }, });