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 { sendErrorMessage, hasPermission, sendSuccessMessage } from "../../../pluginUtils";
|
|
|
|
import { resolveUser, stripObjectToScalars } from "../../../utils";
|
|
|
|
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
2020-10-01 01:43:38 +03:00
|
|
|
import { LogType } from "../../../data/LogType";
|
2020-07-24 02:25:33 +02:00
|
|
|
import { ignoreEvent } from "../functions/ignoreEvent";
|
2020-10-01 01:43:38 +03:00
|
|
|
import { CaseTypes } from "../../../data/CaseTypes";
|
|
|
|
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
2020-07-24 02:25:33 +02:00
|
|
|
|
|
|
|
const opts = {
|
|
|
|
mod: ct.member({ option: true }),
|
|
|
|
};
|
|
|
|
|
2020-10-01 01:43:38 +03:00
|
|
|
export const UnbanCmd = modActionsCmd({
|
2020-07-24 02:25:33 +02:00
|
|
|
trigger: "unban",
|
|
|
|
permission: "can_ban",
|
|
|
|
description: "Unban 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);
|
|
|
|
if (!user) return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, user.id);
|
2020-07-27 18:29:30 +01:00
|
|
|
const reason = formatReasonWithAttachments(args.reason, msg.attachments);
|
2020-07-24 02:25:33 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
ignoreEvent(pluginData, IgnoredEventType.Unban, user.id);
|
2020-08-05 02:54:02 +03:00
|
|
|
await pluginData.guild.unbanMember(user.id, reason != null ? encodeURIComponent(reason) : undefined);
|
2020-07-24 02:25:33 +02:00
|
|
|
} catch (e) {
|
|
|
|
sendErrorMessage(pluginData, msg.channel, "Failed to unban member; are you sure they're banned?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a case
|
|
|
|
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
|
|
|
const createdCase = await casesPlugin.createCase({
|
|
|
|
userId: user.id,
|
|
|
|
modId: mod.id,
|
|
|
|
type: CaseTypes.Unban,
|
|
|
|
reason,
|
|
|
|
ppId: mod.id !== msg.author.id ? msg.author.id : null,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Confirm the action
|
|
|
|
sendSuccessMessage(pluginData, msg.channel, `Member unbanned (Case #${createdCase.case_number})`);
|
|
|
|
|
|
|
|
// Log the action
|
|
|
|
pluginData.state.serverLogs.log(LogType.MEMBER_UNBAN, {
|
|
|
|
mod: stripObjectToScalars(mod.user),
|
|
|
|
userId: user.id,
|
2020-08-02 02:30:01 +02:00
|
|
|
caseNumber: createdCase.case_number,
|
2020-07-24 02:25:33 +02:00
|
|
|
reason,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|