mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-12 21:05:02 +00:00
automod: add cooldown support
This commit is contained in:
parent
5882bbda4e
commit
7fb7787583
4 changed files with 36 additions and 2 deletions
|
@ -0,0 +1,25 @@
|
|||
import { AutomodContext, AutomodPluginType, TRule } from "../types";
|
||||
import { PluginData } from "knub";
|
||||
import { AutomodTriggerMatchResult } from "../helpers";
|
||||
import { convertDelayStringToMS } from "../../../utils";
|
||||
|
||||
export function checkAndUpdateCooldown(
|
||||
pluginData: PluginData<AutomodPluginType>,
|
||||
rule: TRule,
|
||||
context: AutomodContext,
|
||||
) {
|
||||
const cooldownKey = 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;
|
||||
}
|
|
@ -4,6 +4,7 @@ import { availableTriggers } from "../triggers/availableTriggers";
|
|||
import { availableActions } from "../actions/availableActions";
|
||||
import { AutomodTriggerMatchResult } from "../helpers";
|
||||
import { CleanAction } from "../actions/clean";
|
||||
import { checkAndUpdateCooldown } from "./checkAndUpdateCooldown";
|
||||
|
||||
export async function runAutomod(pluginData: PluginData<AutomodPluginType>, context: AutomodContext) {
|
||||
const userId = context.user?.id || context.message?.user_id;
|
||||
|
@ -24,6 +25,10 @@ export async function runAutomod(pluginData: PluginData<AutomodPluginType>, cont
|
|||
if (rule.enabled === false) continue;
|
||||
if (!rule.affects_bots && user.bot) continue;
|
||||
|
||||
if (rule.cooldown && checkAndUpdateCooldown(pluginData, rule, context)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let matchResult: AutomodTriggerMatchResult<any>;
|
||||
let contexts: AutomodContext[];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue