diff --git a/backend/src/plugins/Automod/Automod.ts b/backend/src/plugins/Automod/Automod.ts index cb777e72..fd458c3d 100644 --- a/backend/src/plugins/Automod/Automod.ts +++ b/backend/src/plugins/Automod/Automod.ts @@ -1148,6 +1148,8 @@ export class AutomodPlugin extends ZeppelinPlugin { muteTime: number = null, reason: string = null, muteOptions: MuteOptions = {}, + removeRolesOnMuteOverride: boolean | string[] = null, + restoreRolesOnMuteOverride: boolean | string[] = null, ): Promise { const lock = await this.locks.acquire(`mute-${userId}`); @@ -178,26 +180,28 @@ export class MutesPlugin extends ZeppelinPlugin { // remove and store any roles to be removed/restored const currentUserRoles = member.roles; const memberOptions: MemberOptions = {}; + const removeRoles = removeRolesOnMuteOverride ?? config.remove_roles_on_mute; + const restoreRoles = restoreRolesOnMuteOverride ?? config.restore_roles_on_mute; let rolesToRestore = []; // remove roles - if (!Array.isArray(config.remove_roles_on_mute)) { - if (config.remove_roles_on_mute) { + if (!Array.isArray(removeRoles)) { + if (removeRoles) { memberOptions.roles = []; await member.edit(memberOptions); } } else { - memberOptions.roles = currentUserRoles.filter(x => !(config.remove_roles_on_mute).includes(x)); + memberOptions.roles = currentUserRoles.filter(x => !(removeRoles).includes(x)); await member.edit(memberOptions); } // set roles to be restored - if (!Array.isArray(config.restore_roles_on_mute)) { - if (config.restore_roles_on_mute) { + if (!Array.isArray(restoreRoles)) { + if (restoreRoles) { rolesToRestore = currentUserRoles; } } else { - rolesToRestore = currentUserRoles.filter(x => (config.restore_roles_on_mute).includes(x)); + rolesToRestore = currentUserRoles.filter(x => (restoreRoles).includes(x)); } // Apply mute role if it's missing diff --git a/backend/src/plugins/Spam.ts b/backend/src/plugins/Spam.ts index 9ff3d11d..8619ba1f 100644 --- a/backend/src/plugins/Spam.ts +++ b/backend/src/plugins/Spam.ts @@ -29,6 +29,8 @@ const BaseSingleSpamConfig = t.type({ count: t.number, mute: tNullable(t.boolean), mute_time: tNullable(t.number), + remove_roles_on_mute: tNullable(t.union([t.boolean, t.array(t.string)])), + restore_roles_on_mute: tNullable(t.union([t.boolean, t.array(t.string)])), clean: tNullable(t.boolean), }); type TBaseSingleSpamConfig = t.TypeOf; @@ -257,12 +259,19 @@ export class SpamPlugin extends ZeppelinPlugin { const muteTime = spamConfig.mute_time ? convertDelayStringToMS(spamConfig.mute_time.toString()) : 120 * 1000; - muteResult = await mutesPlugin.muteUser(member.id, muteTime, "Automatic spam detection", { - caseArgs: { - modId: this.bot.user.id, - postInCaseLogOverride: false, + muteResult = await mutesPlugin.muteUser( + member.id, + muteTime, + "Automatic spam detection", + { + caseArgs: { + modId: this.bot.user.id, + postInCaseLogOverride: false, + }, }, - }); + spamConfig.remove_roles_on_mute, + spamConfig.restore_roles_on_mute, + ); } // Get the offending message IDs @@ -379,12 +388,19 @@ export class SpamPlugin extends ZeppelinPlugin { if (spamConfig.mute && member) { const mutesPlugin = this.getPlugin("mutes"); const muteTime = spamConfig.mute_time ? convertDelayStringToMS(spamConfig.mute_time.toString()) : 120 * 1000; - await mutesPlugin.muteUser(member.id, muteTime, "Automatic spam detection", { - caseArgs: { - modId: this.bot.user.id, - extraNotes: [`Details: ${details}`], + await mutesPlugin.muteUser( + member.id, + muteTime, + "Automatic spam detection", + { + caseArgs: { + modId: this.bot.user.id, + extraNotes: [`Details: ${details}`], + }, }, - }); + spamConfig.remove_roles_on_mute, + spamConfig.restore_roles_on_mute, + ); } else { // If we're not muting the user, just add a note on them const casesPlugin = this.getPlugin("cases");