diff --git a/backend/src/plugins/Automod/Automod.ts b/backend/src/plugins/Automod/Automod.ts index 609cdb83..0999e22a 100644 --- a/backend/src/plugins/Automod/Automod.ts +++ b/backend/src/plugins/Automod/Automod.ts @@ -149,6 +149,7 @@ const ConfigSchema = t.type({ antiraid_levels: t.array(t.string), can_set_antiraid: t.boolean, can_view_antiraid: t.boolean, + can_exclude_antiraid: t.boolean, }); type TConfigSchema = t.TypeOf; @@ -229,6 +230,8 @@ export class AutomodPlugin extends ZeppelinPlugin) { if (config.rules) { // Loop through each rule @@ -271,12 +274,14 @@ export class AutomodPlugin extends ZeppelinPlugin=50", config: { can_view_antiraid: true, + can_exclude_antiraid: true, }, }, { @@ -312,6 +317,8 @@ export class AutomodPlugin extends ZeppelinPlugin this.onMessageCreate(msg); @@ -685,12 +692,13 @@ export class AutomodPlugin extends ZeppelinPlugin= threshold) { return result; } } else { + this.removeAntiraidExemption(member.id); return result; } } @@ -1422,6 +1430,63 @@ export class AutomodPlugin extends ZeppelinPlugin", { + aliases: ["antiraid exclude", "antiraid permit", "antiraid allow", "antiraid ignore"], + extra: { + info: { + description: "Exempts a specific user from the antiraid filter once", + }, + }, + }) + @d.permission("can_exclude_antiraid") + public async excludeFromAntiraidCmd(msg: Message, args: { user: string }) { + const success = await this.addAntiraidExemption(args.user); + if (success) { + this.sendSuccessMessage(msg.channel, "User is now exempt once for 30 minutes!"); + } else { + this.sendErrorMessage(msg.channel, "Failed to exempt user. They might already be exempt!"); + } + } + + @d.command("antiraid unexempt", "", { + aliases: ["antiraid include", "antiraid disallow", "antiraid target"], + extra: { + info: { + description: "Unexempts a specific user from the antiraid filter", + }, + }, + }) + @d.permission("can_exclude_antiraid") + public async includeInAntiraidCmd(msg: Message, args: { user: string }) { + const success = await this.removeAntiraidExemption(args.user); + if (success) { + this.sendSuccessMessage(msg.channel, "User is no longer exempt!"); + } else { + this.sendErrorMessage(msg.channel, "User was either not exempt or could not be removed from exemption list!"); + } + } + + public async addAntiraidExemption(userid: string): Promise { + if (!this.antiraidExemptions.includes(userid)) { + this.antiraidExemptions.push(userid); + setTimeout(async () => { + await this.removeAntiraidExemption(userid); + }, 30 * 60000); + return true; + } + return false; + } + + public async removeAntiraidExemption(userid: string): Promise { + for (let i = 0; i < this.antiraidExemptions.length; i++) { + if (this.antiraidExemptions[i] === userid) { + this.antiraidExemptions.splice(i, 1); + return true; + } + } + return false; + } + @d.command("antiraid") @d.permission("can_view_antiraid") public async viewAntiraidCmd(msg: Message, args: { level: string }) {