mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-07 02:57: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 { convertDelayStringToMS } from "../../../utils";
|
||||||
import { AutomodContext, AutomodPluginType, TRule } from "../types";
|
import { AutomodContext, AutomodPluginType, TRule } from "../types";
|
||||||
|
|
||||||
export function checkAndUpdateCooldown(
|
export function applyCooldown(pluginData: GuildPluginData<AutomodPluginType>, rule: TRule, context: AutomodContext) {
|
||||||
pluginData: GuildPluginData<AutomodPluginType>,
|
|
||||||
rule: TRule,
|
|
||||||
context: AutomodContext,
|
|
||||||
) {
|
|
||||||
const cooldownKey = `${rule.name}-${context.user?.id}`;
|
const cooldownKey = `${rule.name}-${context.user?.id}`;
|
||||||
|
|
||||||
if (cooldownKey) {
|
if (cooldownKey) {
|
||||||
if (pluginData.state.cooldownManager.isOnCooldown(cooldownKey)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const cooldownTime = convertDelayStringToMS(rule.cooldown, "s");
|
const cooldownTime = convertDelayStringToMS(rule.cooldown, "s");
|
||||||
if (cooldownTime) {
|
if (cooldownTime) {
|
||||||
pluginData.state.cooldownManager.setCooldown(cooldownKey, 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 { AutomodTriggerMatchResult } from "../helpers";
|
||||||
import { availableTriggers } from "../triggers/availableTriggers";
|
import { availableTriggers } from "../triggers/availableTriggers";
|
||||||
import { AutomodContext, AutomodPluginType } from "../types";
|
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) {
|
export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>, context: AutomodContext) {
|
||||||
const userId = context.user?.id || context.member?.id || context.message?.user_id;
|
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.affects_self && userId && userId === pluginData.client.user?.id) continue;
|
||||||
|
|
||||||
if (rule.cooldown && checkAndUpdateCooldown(pluginData, rule, context)) {
|
if (rule.cooldown && checkCooldown(pluginData, rule, context)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,6 +85,9 @@ export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchResult) {
|
if (matchResult) {
|
||||||
|
// Apply cooldowns
|
||||||
|
if (rule.cooldown) applyCooldown(pluginData, rule, context);
|
||||||
|
|
||||||
contexts = [context, ...(matchResult.extraContexts || [])];
|
contexts = [context, ...(matchResult.extraContexts || [])];
|
||||||
|
|
||||||
for (const _context of contexts) {
|
for (const _context of contexts) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue