3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-11 04:45:02 +00:00

Add counter documentation/examples. Tweak counter triggers/actions in automod.

Rename change_counter automod action to add_to_counter,
add set_counter action, rename counter trigger to counter_trigger.
This commit is contained in:
Dragory 2021-04-02 17:44:21 +03:00
parent ab8ea2e7e5
commit 4147298120
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
9 changed files with 347 additions and 16 deletions

View file

@ -2,26 +2,21 @@ import * as t from "io-ts";
import { automodAction } from "../helpers";
import { CountersPlugin } from "../../Counters/CountersPlugin";
export const ChangeCounterAction = automodAction({
export const AddToCounterAction = automodAction({
configType: t.type({
name: t.string,
change: t.string,
counter: t.string,
amount: t.number,
}),
defaultConfig: {},
async apply({ pluginData, contexts, actionConfig, matchResult }) {
const change = parseInt(actionConfig.change, 10);
if (Number.isNaN(change)) {
throw new Error("Invalid change number");
}
const countersPlugin = pluginData.getPlugin(CountersPlugin);
countersPlugin.changeCounterValue(
actionConfig.name,
actionConfig.counter,
contexts[0].message?.channel_id || null,
contexts[0].user?.id || null,
change,
actionConfig.amount,
);
},
});

View file

@ -12,7 +12,8 @@ import { AddRolesAction } from "./addRoles";
import { RemoveRolesAction } from "./removeRoles";
import { SetAntiraidLevelAction } from "./setAntiraidLevel";
import { ReplyAction } from "./reply";
import { ChangeCounterAction } from "./changeCounter";
import { AddToCounterAction } from "./addToCounter";
import { SetCounterAction } from "./setCounter";
export const availableActions: Record<string, AutomodActionBlueprint<any>> = {
clean: CleanAction,
@ -27,7 +28,8 @@ export const availableActions: Record<string, AutomodActionBlueprint<any>> = {
remove_roles: RemoveRolesAction,
set_antiraid_level: SetAntiraidLevelAction,
reply: ReplyAction,
change_counter: ChangeCounterAction,
add_to_counter: AddToCounterAction,
set_counter: SetCounterAction,
};
export const AvailableActions = t.type({
@ -43,5 +45,6 @@ export const AvailableActions = t.type({
remove_roles: RemoveRolesAction.configType,
set_antiraid_level: SetAntiraidLevelAction.configType,
reply: ReplyAction.configType,
change_counter: ChangeCounterAction.configType,
add_to_counter: AddToCounterAction.configType,
set_counter: SetCounterAction.configType,
});

View file

@ -0,0 +1,22 @@
import * as t from "io-ts";
import { automodAction } from "../helpers";
import { CountersPlugin } from "../../Counters/CountersPlugin";
export const SetCounterAction = automodAction({
configType: t.type({
counter: t.string,
value: t.number,
}),
defaultConfig: {},
async apply({ pluginData, contexts, actionConfig, matchResult }) {
const countersPlugin = pluginData.getPlugin(CountersPlugin);
countersPlugin.setCounterValue(
actionConfig.counter,
contexts[0].message?.channel_id || null,
contexts[0].user?.id || null,
actionConfig.value,
);
},
});