Merge pull request #127 from DarkView/banForcebanUpgrade

Allow ban to be upgraded to forceban if the member is not on the server
This commit is contained in:
Miikka 2020-12-12 22:13:17 +02:00 committed by GitHub
commit f8248c65a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
},
});