3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-06-08 00:05:01 +00:00
zeppelin/backend/src/plugins/ModActions/commands/forceban/ForceBanMsgCmd.ts
Dragory 45e3fe2ef0
chore: esm imports
This will make merging this into 'next' much easier.
2024-08-11 21:58:52 +03:00

60 lines
2 KiB
TypeScript

import { commandTypeHelpers as ct } from "../../../../commandTypes.js";
import { canActOn, hasPermission } from "../../../../pluginUtils.js";
import { resolveMember, resolveUser } from "../../../../utils.js";
import { isBanned } from "../../functions/isBanned.js";
import { modActionsMsgCmd } from "../../types.js";
import { actualForceBanCmd } from "./actualForceBanCmd.js";
const opts = {
mod: ct.member({ option: true }),
};
export const ForceBanMsgCmd = modActionsMsgCmd({
trigger: "forceban",
permission: "can_ban",
description: "Force-ban the specified user, even if they aren't on the server",
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.id) {
pluginData.state.common.sendErrorMessage(msg, `User not found`);
return;
}
// If the user exists as a guild member, make sure we can act on them first
const member = await resolveMember(pluginData.client, pluginData.guild, user.id);
if (member && !canActOn(pluginData, msg.member, member)) {
pluginData.state.common.sendErrorMessage(msg, "Cannot forceban this user: insufficient permissions");
return;
}
// Make sure the user isn't already banned
const banned = await isBanned(pluginData, user.id);
if (banned) {
pluginData.state.common.sendErrorMessage(msg, `User is already banned`);
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;
}
actualForceBanCmd(pluginData, msg, msg.author.id, user, args.reason, [...msg.attachments.values()], mod);
},
});