2020-10-01 01:43:38 +03:00
|
|
|
import { modActionsCmd, IgnoredEventType } from "../types";
|
2020-07-24 02:25:33 +02:00
|
|
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
|
|
|
import { canActOn, sendErrorMessage, hasPermission, sendSuccessMessage } from "../../../pluginUtils";
|
|
|
|
import { resolveUser, resolveMember } from "../../../utils";
|
|
|
|
import { isBanned } from "../functions/isBanned";
|
|
|
|
import { readContactMethodsFromArgs } from "../functions/readContactMethodsFromArgs";
|
|
|
|
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
|
|
|
import { banUserId } from "../functions/banUserId";
|
|
|
|
import { ignoreEvent } from "../functions/ignoreEvent";
|
2020-10-01 01:43:38 +03:00
|
|
|
import { LogType } from "../../../data/LogType";
|
2020-11-20 02:31:31 +01:00
|
|
|
import { waitForReaction } from "knub/dist/helpers";
|
2020-07-24 02:25:33 +02:00
|
|
|
|
|
|
|
const opts = {
|
|
|
|
mod: ct.member({ option: true }),
|
|
|
|
notify: ct.string({ option: true }),
|
|
|
|
"notify-channel": ct.textChannel({ option: true }),
|
2020-07-30 12:19:17 +03:00
|
|
|
"delete-days": ct.number({ option: true, shortcut: "d" }),
|
2020-07-24 02:25:33 +02:00
|
|
|
};
|
|
|
|
|
2020-10-01 01:43:38 +03:00
|
|
|
export const BanCmd = modActionsCmd({
|
2020-07-24 02:25:33 +02:00
|
|
|
trigger: "ban",
|
|
|
|
permission: "can_ban",
|
|
|
|
description: "Ban the specified member",
|
|
|
|
|
|
|
|
signature: [
|
|
|
|
{
|
|
|
|
user: ct.string(),
|
|
|
|
reason: ct.string({ required: false, catchAll: true }),
|
|
|
|
|
|
|
|
...opts,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
|
|
|
async run({ pluginData, message: msg, args }) {
|
|
|
|
const user = await resolveUser(pluginData.client, args.user);
|
2020-12-17 04:12:49 +02:00
|
|
|
if (!user.id) {
|
|
|
|
return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
|
|
|
}
|
2020-07-24 02:25:33 +02:00
|
|
|
|
|
|
|
const memberToBan = await resolveMember(pluginData.client, pluginData.guild, user.id);
|
|
|
|
|
2020-11-20 02:31:31 +01:00
|
|
|
let forceban = false;
|
2020-07-24 02:25:33 +02:00
|
|
|
if (!memberToBan) {
|
|
|
|
const banned = await isBanned(pluginData, user.id);
|
2020-11-20 02:31:31 +01:00
|
|
|
|
2020-07-24 02:25:33 +02:00
|
|
|
if (banned) {
|
|
|
|
sendErrorMessage(pluginData, msg.channel, `User is already banned`);
|
2020-11-20 02:31:31 +01:00
|
|
|
return;
|
2020-07-24 02:25:33 +02:00
|
|
|
} else {
|
2020-11-20 02:31:31 +01:00
|
|
|
// 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);
|
|
|
|
|
|
|
|
notOnServerMsg.delete();
|
|
|
|
if (!reply || reply.name === "❌") {
|
|
|
|
sendErrorMessage(pluginData, msg.channel, "User not on server, ban cancelled by moderator");
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
forceban = true;
|
|
|
|
}
|
2020-07-24 02:25:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 02:31:31 +01:00
|
|
|
// Make sure we're allowed to ban this member if they are on the server
|
|
|
|
if (!forceban && !canActOn(pluginData, msg.member, memberToBan!)) {
|
2020-07-24 02:25:33 +02:00
|
|
|
sendErrorMessage(pluginData, msg.channel, "Cannot ban: insufficient permissions");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The moderator who did the action is the message author or, if used, the specified -mod
|
|
|
|
let mod = msg.member;
|
|
|
|
if (args.mod) {
|
|
|
|
if (!hasPermission(pluginData, "can_act_as_other", { message: msg, channelId: msg.channel.id })) {
|
|
|
|
sendErrorMessage(pluginData, msg.channel, "No permission for -mod");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mod = args.mod;
|
|
|
|
}
|
|
|
|
|
|
|
|
let contactMethods;
|
|
|
|
try {
|
|
|
|
contactMethods = readContactMethodsFromArgs(args);
|
|
|
|
} catch (e) {
|
|
|
|
sendErrorMessage(pluginData, msg.channel, e.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const deleteMessageDays = args["delete-days"] ?? pluginData.config.getForMessage(msg).ban_delete_message_days;
|
|
|
|
const reason = formatReasonWithAttachments(args.reason, msg.attachments);
|
2020-11-20 02:31:31 +01:00
|
|
|
const banResult = await banUserId(pluginData, user.id, reason, {
|
2020-07-24 02:25:33 +02:00
|
|
|
contactMethods,
|
|
|
|
caseArgs: {
|
|
|
|
modId: mod.id,
|
2020-11-09 20:03:57 +02:00
|
|
|
ppId: mod.id !== msg.author.id ? msg.author.id : undefined,
|
2020-07-24 02:25:33 +02:00
|
|
|
},
|
|
|
|
deleteMessageDays,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (banResult.status === "failed") {
|
|
|
|
sendErrorMessage(pluginData, msg.channel, `Failed to ban member`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Confirm the action to the moderator
|
2020-11-20 02:31:31 +01:00
|
|
|
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})`;
|
|
|
|
}
|
2020-07-24 02:25:33 +02:00
|
|
|
|
|
|
|
sendSuccessMessage(pluginData, msg.channel, response);
|
|
|
|
},
|
|
|
|
});
|