mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-06 18:47:20 +00:00
fix automod cooldowns
Signed-off-by: GitHub <noreply@github.com>
This commit is contained in:
parent
8a4a2d3647
commit
08a19eee81
3 changed files with 21 additions and 13 deletions
|
@ -2,23 +2,13 @@ import { GuildPluginData } from "knub";
|
|||
import { convertDelayStringToMS } from "../../../utils";
|
||||
import { AutomodContext, AutomodPluginType, TRule } from "../types";
|
||||
|
||||
export function checkAndUpdateCooldown(
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
rule: TRule,
|
||||
context: AutomodContext,
|
||||
) {
|
||||
export function applyCooldown(pluginData: GuildPluginData<AutomodPluginType>, 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;
|
||||
}
|
14
backend/src/plugins/Automod/functions/checkCooldown.ts
Normal file
14
backend/src/plugins/Automod/functions/checkCooldown.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { GuildPluginData } from "knub";
|
||||
import { AutomodContext, AutomodPluginType, TRule } from "../types";
|
||||
|
||||
export function checkCooldown(pluginData: GuildPluginData<AutomodPluginType>, rule: TRule, context: AutomodContext) {
|
||||
const cooldownKey = `${rule.name}-${context.user?.id}`;
|
||||
|
||||
if (cooldownKey) {
|
||||
if (pluginData.state.cooldownManager.isOnCooldown(cooldownKey)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
|
@ -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<AutomodPluginType>, context: AutomodContext) {
|
||||
const userId = context.user?.id || context.member?.id || context.message?.user_id;
|
||||
|
@ -46,7 +47,7 @@ export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>,
|
|||
}
|
||||
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<AutomodPluginType>,
|
|||
}
|
||||
|
||||
if (matchResult) {
|
||||
// Apply cooldowns
|
||||
if (rule.cooldown) applyCooldown(pluginData, rule, context);
|
||||
|
||||
contexts = [context, ...(matchResult.extraContexts || [])];
|
||||
|
||||
for (const _context of contexts) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue