3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

counters: move triggers to counters plugin; architectural tweaks

This commit is contained in:
Dragory 2021-04-02 16:36:45 +03:00
parent 7f75d6d8d3
commit ab8ea2e7e5
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
17 changed files with 357 additions and 200 deletions

View file

@ -2,30 +2,38 @@ import { GuildPluginData } from "knub";
import { AutomodContext, AutomodPluginType } from "../types";
import { runAutomod } from "../functions/runAutomod";
import { resolveMember, resolveUser, UnknownUser } from "../../../utils";
import { CountersPlugin } from "../../Counters/CountersPlugin";
export async function runAutomodOnCounterTrigger(
pluginData: GuildPluginData<AutomodPluginType>,
counterName: string,
condition: string,
triggerName: string,
channelId: string | null,
userId: string | null,
reverse: boolean,
) {
const user = userId ? await resolveUser(pluginData.client, userId) : undefined;
const member = (userId && (await resolveMember(pluginData.client, pluginData.guild, userId))) || undefined;
const prettyCounterName = pluginData.getPlugin(CountersPlugin).getPrettyNameForCounter(counterName);
const prettyTriggerName = pluginData
.getPlugin(CountersPlugin)
.getPrettyNameForCounterTrigger(counterName, triggerName);
const context: AutomodContext = {
timestamp: Date.now(),
counterTrigger: {
name: counterName,
condition,
counter: counterName,
trigger: triggerName,
prettyCounter: prettyCounterName,
prettyTrigger: prettyTriggerName,
channelId,
userId,
reverse,
},
user: user instanceof UnknownUser ? undefined : user,
member,
// TODO: Channel
};
pluginData.state.queue.add(async () => {