From 08a19eee8119ed97e337304925e91e8ade5ca24b Mon Sep 17 00:00:00 2001 From: Tiago R Date: Sun, 7 Jan 2024 20:53:27 +0000 Subject: [PATCH 1/3] fix automod cooldowns Signed-off-by: GitHub --- ...{checkAndUpdateCooldown.ts => applyCooldown.ts} | 12 +----------- .../src/plugins/Automod/functions/checkCooldown.ts | 14 ++++++++++++++ .../src/plugins/Automod/functions/runAutomod.ts | 8 ++++++-- 3 files changed, 21 insertions(+), 13 deletions(-) rename backend/src/plugins/Automod/functions/{checkAndUpdateCooldown.ts => applyCooldown.ts} (63%) create mode 100644 backend/src/plugins/Automod/functions/checkCooldown.ts diff --git a/backend/src/plugins/Automod/functions/checkAndUpdateCooldown.ts b/backend/src/plugins/Automod/functions/applyCooldown.ts similarity index 63% rename from backend/src/plugins/Automod/functions/checkAndUpdateCooldown.ts rename to backend/src/plugins/Automod/functions/applyCooldown.ts index 6338d6986..40a64acbd 100644 --- a/backend/src/plugins/Automod/functions/checkAndUpdateCooldown.ts +++ b/backend/src/plugins/Automod/functions/applyCooldown.ts @@ -2,23 +2,13 @@ import { GuildPluginData } from "knub"; import { convertDelayStringToMS } from "../../../utils"; import { AutomodContext, AutomodPluginType, TRule } from "../types"; -export function checkAndUpdateCooldown( - pluginData: GuildPluginData, - rule: TRule, - context: AutomodContext, -) { +export function applyCooldown(pluginData: GuildPluginData, rule: TRule, context: AutomodContext) { const cooldownKey = `${rule.name}-${context.user?.id}`; if (cooldownKey) { - if (pluginData.state.cooldownManager.isOnCooldown(cooldownKey)) { - return true; - } - const cooldownTime = convertDelayStringToMS(rule.cooldown, "s"); if (cooldownTime) { pluginData.state.cooldownManager.setCooldown(cooldownKey, cooldownTime); } } - - return false; } diff --git a/backend/src/plugins/Automod/functions/checkCooldown.ts b/backend/src/plugins/Automod/functions/checkCooldown.ts new file mode 100644 index 000000000..f0c665c4e --- /dev/null +++ b/backend/src/plugins/Automod/functions/checkCooldown.ts @@ -0,0 +1,14 @@ +import { GuildPluginData } from "knub"; +import { AutomodContext, AutomodPluginType, TRule } from "../types"; + +export function checkCooldown(pluginData: GuildPluginData, rule: TRule, context: AutomodContext) { + const cooldownKey = `${rule.name}-${context.user?.id}`; + + if (cooldownKey) { + if (pluginData.state.cooldownManager.isOnCooldown(cooldownKey)) { + return true; + } + } + + return false; +} diff --git a/backend/src/plugins/Automod/functions/runAutomod.ts b/backend/src/plugins/Automod/functions/runAutomod.ts index e9c2e3a74..0739fdaf8 100644 --- a/backend/src/plugins/Automod/functions/runAutomod.ts +++ b/backend/src/plugins/Automod/functions/runAutomod.ts @@ -7,7 +7,8 @@ import { CleanAction } from "../actions/clean"; import { AutomodTriggerMatchResult } from "../helpers"; import { availableTriggers } from "../triggers/availableTriggers"; import { AutomodContext, AutomodPluginType } from "../types"; -import { checkAndUpdateCooldown } from "./checkAndUpdateCooldown"; +import { applyCooldown } from "./applyCooldown"; +import { checkCooldown } from "./checkCooldown"; export async function runAutomod(pluginData: GuildPluginData, context: AutomodContext) { const userId = context.user?.id || context.member?.id || context.message?.user_id; @@ -46,7 +47,7 @@ export async function runAutomod(pluginData: GuildPluginData, } if (!rule.affects_self && userId && userId === pluginData.client.user?.id) continue; - if (rule.cooldown && checkAndUpdateCooldown(pluginData, rule, context)) { + if (rule.cooldown && checkCooldown(pluginData, rule, context)) { continue; } @@ -84,6 +85,9 @@ export async function runAutomod(pluginData: GuildPluginData, } if (matchResult) { + // Apply cooldowns + if (rule.cooldown) applyCooldown(pluginData, rule, context); + contexts = [context, ...(matchResult.extraContexts || [])]; for (const _context of contexts) { From eff3b0cd568e40915c158ad4d9cd417b4e39aa25 Mon Sep 17 00:00:00 2001 From: Tiago R Date: Sun, 7 Jan 2024 21:07:00 +0000 Subject: [PATCH 2/3] almeida fixes Signed-off-by: GitHub --- backend/src/plugins/Automod/functions/applyCooldown.ts | 8 ++------ backend/src/plugins/Automod/functions/checkCooldown.ts | 8 +------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/backend/src/plugins/Automod/functions/applyCooldown.ts b/backend/src/plugins/Automod/functions/applyCooldown.ts index 40a64acbd..387ac448c 100644 --- a/backend/src/plugins/Automod/functions/applyCooldown.ts +++ b/backend/src/plugins/Automod/functions/applyCooldown.ts @@ -5,10 +5,6 @@ import { AutomodContext, AutomodPluginType, TRule } from "../types"; export function applyCooldown(pluginData: GuildPluginData, rule: TRule, context: AutomodContext) { const cooldownKey = `${rule.name}-${context.user?.id}`; - if (cooldownKey) { - const cooldownTime = convertDelayStringToMS(rule.cooldown, "s"); - if (cooldownTime) { - pluginData.state.cooldownManager.setCooldown(cooldownKey, cooldownTime); - } - } + const cooldownTime = convertDelayStringToMS(rule.cooldown, "s"); + if (cooldownTime) pluginData.state.cooldownManager.setCooldown(cooldownKey, cooldownTime); } diff --git a/backend/src/plugins/Automod/functions/checkCooldown.ts b/backend/src/plugins/Automod/functions/checkCooldown.ts index f0c665c4e..3640c142f 100644 --- a/backend/src/plugins/Automod/functions/checkCooldown.ts +++ b/backend/src/plugins/Automod/functions/checkCooldown.ts @@ -4,11 +4,5 @@ import { AutomodContext, AutomodPluginType, TRule } from "../types"; export function checkCooldown(pluginData: GuildPluginData, rule: TRule, context: AutomodContext) { const cooldownKey = `${rule.name}-${context.user?.id}`; - if (cooldownKey) { - if (pluginData.state.cooldownManager.isOnCooldown(cooldownKey)) { - return true; - } - } - - return false; + return pluginData.state.cooldownManager.isOnCooldown(cooldownKey); } From a22e70c8fb3ca827a3ebe088a57fa218018afba7 Mon Sep 17 00:00:00 2001 From: Tiago R Date: Sun, 7 Jan 2024 21:11:47 +0000 Subject: [PATCH 3/3] https://shr2.i0.tf/82e683c8/bd310b9c-7492-44f0-aed5-af6a22a3c196.png Signed-off-by: GitHub --- backend/src/plugins/Automod/functions/runAutomod.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/plugins/Automod/functions/runAutomod.ts b/backend/src/plugins/Automod/functions/runAutomod.ts index 0739fdaf8..4ccc38dee 100644 --- a/backend/src/plugins/Automod/functions/runAutomod.ts +++ b/backend/src/plugins/Automod/functions/runAutomod.ts @@ -85,7 +85,6 @@ export async function runAutomod(pluginData: GuildPluginData, } if (matchResult) { - // Apply cooldowns if (rule.cooldown) applyCooldown(pluginData, rule, context); contexts = [context, ...(matchResult.extraContexts || [])];