Replace softban with call to clean, also posting a deprecation warning

This commit is contained in:
Dark 2020-04-04 17:55:16 +02:00
parent ac33a0de1e
commit f2f24107eb

View file

@ -1281,92 +1281,42 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
} }
@d.command("softban", "<user:string> [reason:string$]", { @d.command("softban", "<user:string> [reason:string$]", {
options: [{ name: "mod", type: "member" }], options: [
{ name: "mod", type: "member" },
{ name: "notify", type: "string" },
{ name: "notify-channel", type: "channel" },
],
extra: { extra: {
info: { info: {
description: description:
'"Softban" the specified user by banning and immediately unbanning them. Effectively a kick with message deletions.', '"Softban" the specified user by banning and immediately unbanning them. Effectively a kick with message deletions.' +
"This command will be removed in the future, please use kick with the `-clean` argument instead",
}, },
}, },
}) })
@d.permission("can_ban") @d.permission("can_warn")
async softbanCmd(msg, args: { user: string; reason: string; mod?: Member }) { async softbanCmd(
const user = await this.resolveUser(args.user); msg: Message,
if (!user) return this.sendErrorMessage(msg.channel, `User not found`); args: {
user: string;
const memberToSoftban = await this.getMember(user.id); reason: string;
mod?: Member;
if (!memberToSoftban) { notify?: string;
const isBanned = await this.isBanned(user.id); "notify-channel"?: TextChannel;
if (isBanned) { },
this.sendErrorMessage(msg.channel, `User is already banned`); ) {
} else { await this.kickCmd(msg, {
this.sendErrorMessage(msg.channel, `User not found on the server`); user: args.user,
} mod: args.mod ? args.mod : msg.member,
reason: args.reason,
return; clean: true,
} notify: args.notify,
"notify-channel": args["notify-channel"],
// Make sure we're allowed to ban this member
if (!this.canActOn(msg.member, memberToSoftban)) {
this.sendErrorMessage(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 (!this.hasPermission("can_act_as_other", { message: msg })) {
this.sendErrorMessage(msg.channel, "No permission for -mod");
return;
}
mod = args.mod;
}
const reason = this.formatReasonWithAttachments(args.reason, msg.attachments);
// Softban the user = ban, and immediately unban
this.serverLogs.ignoreLog(LogType.MEMBER_BAN, memberToSoftban.id);
this.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, memberToSoftban.id);
this.ignoreEvent(IgnoredEventType.Ban, memberToSoftban.id);
this.ignoreEvent(IgnoredEventType.Unban, memberToSoftban.id);
try {
await memberToSoftban.ban(1);
} catch (e) {
msg.channel.create(errorMessage("Failed to softban the user"));
return;
}
try {
await this.guild.unbanMember(memberToSoftban.id);
} catch (e) {
msg.channel.create(errorMessage("Failed to unban the user after softbanning them"));
return;
}
// Create a case for this action
const casesPlugin = this.getPlugin<CasesPlugin>("cases");
const createdCase = await casesPlugin.createCase({
userId: memberToSoftban.id,
modId: mod.id,
type: CaseTypes.Softban,
reason,
ppId: mod.id !== msg.author.id ? msg.author.id : null,
}); });
// Confirm the action to the moderator await msg.channel.createMessage(
this.sendSuccessMessage( "Softban will be removed in the future - please use the kick command with the `-clean` argument instead!",
msg.channel,
`Softbanned **${memberToSoftban.user.username}#${memberToSoftban.user.discriminator}** (Case #${createdCase.case_number})`,
); );
// Log the action
this.serverLogs.log(LogType.MEMBER_SOFTBAN, {
mod: stripObjectToScalars(mod.user),
member: stripObjectToScalars(memberToSoftban, ["user", "roles"]),
});
} }
@d.command("unban", "<user:string> [reason:string$]", { @d.command("unban", "<user:string> [reason:string$]", {