Merge branch 'DarkView-kickCleanArg'

This commit is contained in:
Dragory 2020-05-22 20:57:42 +03:00
commit 974a02ac86
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -1102,6 +1102,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
{ name: "mod", type: "member" }, { name: "mod", type: "member" },
{ name: "notify", type: "string" }, { name: "notify", type: "string" },
{ name: "notify-channel", type: "channel" }, { name: "notify-channel", type: "channel" },
{ name: "clean", isSwitch: true },
], ],
extra: { extra: {
info: { info: {
@ -1112,7 +1113,14 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
@d.permission("can_kick") @d.permission("can_kick")
async kickCmd( async kickCmd(
msg, 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); const user = await this.resolveUser(args.user);
if (!user) return this.sendErrorMessage(msg.channel, `User not found`); if (!user) return this.sendErrorMessage(msg.channel, `User not found`);
@ -1156,6 +1164,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
} }
const reason = this.formatReasonWithAttachments(args.reason, msg.attachments); const reason = this.formatReasonWithAttachments(args.reason, msg.attachments);
const kickResult = await this.kickMember(memberToKick, reason, { const kickResult = await this.kickMember(memberToKick, reason, {
contactMethods, contactMethods,
caseArgs: { caseArgs: {
@ -1164,6 +1173,26 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
}, },
}); });
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") { if (kickResult.status === "failed") {
msg.channel.createMessage(errorMessage(`Failed to kick user`)); msg.channel.createMessage(errorMessage(`Failed to kick user`));
return; return;
@ -1266,92 +1295,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_kick")
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$]", {