3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-13 21:35:02 +00:00
zeppelin/backend/src/plugins/ModActions/commands/ban/BanMsgCmd.ts
2024-05-12 21:34:17 +02:00

75 lines
2 KiB
TypeScript

import { commandTypeHelpers as ct } from "../../../../commandTypes";
import { hasPermission } from "../../../../pluginUtils";
import { UserNotificationMethod, resolveUser } from "../../../../utils";
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs";
import { modActionsMsgCmd } from "../../types";
import { actualBanCmd } from "./actualBanCmd";
const opts = {
mod: ct.member({ option: true }),
notify: ct.string({ option: true }),
"notify-channel": ct.textChannel({ option: true }),
"delete-days": ct.number({ option: true, shortcut: "d" }),
};
export const BanMsgCmd = modActionsMsgCmd({
trigger: "ban",
permission: "can_ban",
description: "Ban or Tempban the specified member",
signature: [
{
user: ct.string(),
time: ct.delay(),
reason: ct.string({ required: false, catchAll: true }),
...opts,
},
{
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.id) {
pluginData.state.common.sendErrorMessage(msg, `User not found`);
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 (!(await hasPermission(pluginData, "can_act_as_other", { message: msg }))) {
pluginData.state.common.sendErrorMessage(msg, "You don't have permission to use -mod");
return;
}
mod = args.mod;
}
let contactMethods: UserNotificationMethod[] | undefined;
try {
contactMethods = readContactMethodsFromArgs(args) ?? undefined;
} catch (e) {
pluginData.state.common.sendErrorMessage(msg, e.message);
return;
}
actualBanCmd(
pluginData,
msg,
user,
args["time"] ? args["time"] : null,
args.reason || "",
[...msg.attachments.values()],
msg.member,
mod,
contactMethods,
);
},
});