2021-06-30 04:56:56 +02:00
|
|
|
import { Snowflake } from "discord.js";
|
2021-07-25 14:32:08 +02:00
|
|
|
import { userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
|
2020-07-24 02:25:33 +02:00
|
|
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
2021-06-06 23:51:32 +02:00
|
|
|
import { CaseTypes } from "../../../data/CaseTypes";
|
|
|
|
import { LogType } from "../../../data/LogType";
|
|
|
|
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
|
|
|
import { hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
2021-07-21 22:14:09 +02:00
|
|
|
import { resolveUser } from "../../../utils";
|
2020-07-24 02:25:33 +02:00
|
|
|
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
|
|
|
import { ignoreEvent } from "../functions/ignoreEvent";
|
2021-06-06 23:51:32 +02:00
|
|
|
import { IgnoredEventType, modActionsCmd } from "../types";
|
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",
|
2021-05-06 19:13:06 +01:00
|
|
|
permission: "can_unban",
|
2020-07-24 02:25:33 +02:00
|
|
|
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);
|
2020-12-17 04:12:49 +02:00
|
|
|
if (!user.id) {
|
2021-01-17 21:21:18 +02:00
|
|
|
sendErrorMessage(pluginData, msg.channel, `User not found`);
|
|
|
|
return;
|
2020-12-17 04:12:49 +02:00
|
|
|
}
|
2020-07-24 02:25:33 +02:00
|
|
|
|
|
|
|
// The moderator who did the action is the message author or, if used, the specified -mod
|
|
|
|
let mod = msg.member;
|
|
|
|
if (args.mod) {
|
2021-05-23 14:35:16 +03:00
|
|
|
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg, channelId: msg.channel.id }))) {
|
2021-04-02 14:43:52 +01:00
|
|
|
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
|
2020-07-24 02:25:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mod = args.mod;
|
|
|
|
}
|
|
|
|
|
|
|
|
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, user.id);
|
2021-06-02 04:07:50 +02:00
|
|
|
const reason = formatReasonWithAttachments(args.reason, msg.attachments.array());
|
2020-07-24 02:25:33 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
ignoreEvent(pluginData, IgnoredEventType.Unban, user.id);
|
2021-06-30 04:56:56 +02:00
|
|
|
await pluginData.guild.bans.remove(user.id as Snowflake, reason != null ? encodeURIComponent(reason) : undefined);
|
2021-05-06 19:23:47 +01:00
|
|
|
} catch {
|
2020-07-24 02:25:33 +02:00
|
|
|
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,
|
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
|
|
|
});
|
2021-01-28 00:20:55 +01:00
|
|
|
// Delete the tempban, if one exists
|
|
|
|
pluginData.state.tempbans.clear(user.id);
|
2020-07-24 02:25:33 +02:00
|
|
|
|
|
|
|
// Confirm the action
|
|
|
|
sendSuccessMessage(pluginData, msg.channel, `Member unbanned (Case #${createdCase.case_number})`);
|
|
|
|
|
|
|
|
// Log the action
|
|
|
|
pluginData.state.serverLogs.log(LogType.MEMBER_UNBAN, {
|
2021-07-21 22:14:09 +02:00
|
|
|
mod: userToConfigAccessibleUser(mod.user),
|
2020-07-24 02:25:33 +02:00
|
|
|
userId: user.id,
|
2020-08-02 02:30:01 +02:00
|
|
|
caseNumber: createdCase.case_number,
|
2020-07-24 02:25:33 +02:00
|
|
|
reason,
|
|
|
|
});
|
2021-04-29 02:22:39 +03:00
|
|
|
|
|
|
|
pluginData.state.events.emit("unban", user.id);
|
2020-07-24 02:25:33 +02:00
|
|
|
},
|
|
|
|
});
|