From ac33a0de1eb2777d13b60da89fafa2c821424a00 Mon Sep 17 00:00:00 2001 From: Dark <7890309+DarkView@users.noreply.github.com> Date: Fri, 3 Apr 2020 17:13:08 +0200 Subject: [PATCH 1/2] Allow -clean, essentially softban in kick command --- backend/src/plugins/ModActions.ts | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/backend/src/plugins/ModActions.ts b/backend/src/plugins/ModActions.ts index 09a50784..07639a09 100644 --- a/backend/src/plugins/ModActions.ts +++ b/backend/src/plugins/ModActions.ts @@ -1098,6 +1098,7 @@ export class ModActionsPlugin extends ZeppelinPlugin { { name: "mod", type: "member" }, { name: "notify", type: "string" }, { name: "notify-channel", type: "channel" }, + { name: "clean", isSwitch: true }, ], extra: { info: { @@ -1108,7 +1109,14 @@ export class ModActionsPlugin extends ZeppelinPlugin { @d.permission("can_kick") async kickCmd( msg, - args: { user: string; reason: string; mod: Member; notify?: string; "notify-channel"?: TextChannel }, + args: { + user: string; + reason: string; + mod: Member; + notify?: string; + "notify-channel"?: TextChannel; + clean?: boolean; + }, ) { const user = await this.resolveUser(args.user); if (!user) return this.sendErrorMessage(msg.channel, `User not found`); @@ -1152,6 +1160,7 @@ export class ModActionsPlugin extends ZeppelinPlugin { } const reason = this.formatReasonWithAttachments(args.reason, msg.attachments); + const kickResult = await this.kickMember(memberToKick, reason, { contactMethods, caseArgs: { @@ -1160,6 +1169,26 @@ export class ModActionsPlugin extends ZeppelinPlugin { }, }); + if (args.clean) { + this.serverLogs.ignoreLog(LogType.MEMBER_BAN, memberToKick.id); + this.ignoreEvent(IgnoredEventType.Ban, memberToKick.id); + + try { + await memberToKick.ban(1); + } catch (e) { + this.sendErrorMessage(msg.channel, "Failed to ban the user to clean messages (-clean)"); + } + + this.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, memberToKick.id); + this.ignoreEvent(IgnoredEventType.Unban, memberToKick.id); + + try { + await this.guild.unbanMember(memberToKick.id); + } catch (e) { + this.sendErrorMessage(msg.channel, "Failed to unban the user after banning them (-clean)"); + } + } + if (kickResult.status === "failed") { msg.channel.createMessage(errorMessage(`Failed to kick user`)); return; From f2f24107ebf4fa86c8ae210522bb0df97e63c3d1 Mon Sep 17 00:00:00 2001 From: Dark <7890309+DarkView@users.noreply.github.com> Date: Sat, 4 Apr 2020 17:55:16 +0200 Subject: [PATCH 2/2] Replace softban with call to clean, also posting a deprecation warning --- backend/src/plugins/ModActions.ts | 104 ++++++++---------------------- 1 file changed, 27 insertions(+), 77 deletions(-) diff --git a/backend/src/plugins/ModActions.ts b/backend/src/plugins/ModActions.ts index 07639a09..d06e56c6 100644 --- a/backend/src/plugins/ModActions.ts +++ b/backend/src/plugins/ModActions.ts @@ -1281,92 +1281,42 @@ export class ModActionsPlugin extends ZeppelinPlugin { } @d.command("softban", " [reason:string$]", { - options: [{ name: "mod", type: "member" }], + options: [ + { name: "mod", type: "member" }, + { name: "notify", type: "string" }, + { name: "notify-channel", type: "channel" }, + ], extra: { info: { 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") - async softbanCmd(msg, args: { user: string; reason: string; mod?: Member }) { - const user = await this.resolveUser(args.user); - if (!user) return this.sendErrorMessage(msg.channel, `User not found`); - - const memberToSoftban = await this.getMember(user.id); - - if (!memberToSoftban) { - const isBanned = await this.isBanned(user.id); - if (isBanned) { - this.sendErrorMessage(msg.channel, `User is already banned`); - } else { - this.sendErrorMessage(msg.channel, `User not found on the server`); - } - - return; - } - - // 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("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, + @d.permission("can_warn") + async softbanCmd( + msg: Message, + args: { + user: string; + reason: string; + mod?: Member; + notify?: string; + "notify-channel"?: TextChannel; + }, + ) { + await this.kickCmd(msg, { + user: args.user, + mod: args.mod ? args.mod : msg.member, + reason: args.reason, + clean: true, + notify: args.notify, + "notify-channel": args["notify-channel"], }); - // Confirm the action to the moderator - this.sendSuccessMessage( - msg.channel, - `Softbanned **${memberToSoftban.user.username}#${memberToSoftban.user.discriminator}** (Case #${createdCase.case_number})`, + await msg.channel.createMessage( + "Softban will be removed in the future - please use the kick command with the `-clean` argument instead!", ); - - // Log the action - this.serverLogs.log(LogType.MEMBER_SOFTBAN, { - mod: stripObjectToScalars(mod.user), - member: stripObjectToScalars(memberToSoftban, ["user", "roles"]), - }); } @d.command("unban", " [reason:string$]", {