mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-11 04:45:02 +00:00
Counters v0.9
Includes automod trigger/action. No user-facing commands yet.
This commit is contained in:
parent
ec37cf27a2
commit
c3407e2d5d
29 changed files with 1387 additions and 3 deletions
|
@ -12,6 +12,7 @@ import { AddRolesAction } from "./addRoles";
|
|||
import { RemoveRolesAction } from "./removeRoles";
|
||||
import { SetAntiraidLevelAction } from "./setAntiraidLevel";
|
||||
import { ReplyAction } from "./reply";
|
||||
import { ChangeCounterAction } from "./changeCounter";
|
||||
|
||||
export const availableActions: Record<string, AutomodActionBlueprint<any>> = {
|
||||
clean: CleanAction,
|
||||
|
@ -26,6 +27,7 @@ export const availableActions: Record<string, AutomodActionBlueprint<any>> = {
|
|||
remove_roles: RemoveRolesAction,
|
||||
set_antiraid_level: SetAntiraidLevelAction,
|
||||
reply: ReplyAction,
|
||||
change_counter: ChangeCounterAction,
|
||||
};
|
||||
|
||||
export const AvailableActions = t.type({
|
||||
|
@ -41,4 +43,5 @@ export const AvailableActions = t.type({
|
|||
remove_roles: RemoveRolesAction.configType,
|
||||
set_antiraid_level: SetAntiraidLevelAction.configType,
|
||||
reply: ReplyAction.configType,
|
||||
change_counter: ChangeCounterAction.configType,
|
||||
});
|
||||
|
|
27
backend/src/plugins/Automod/actions/changeCounter.ts
Normal file
27
backend/src/plugins/Automod/actions/changeCounter.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import * as t from "io-ts";
|
||||
import { automodAction } from "../helpers";
|
||||
import { CountersPlugin } from "../../Counters/CountersPlugin";
|
||||
|
||||
export const ChangeCounterAction = automodAction({
|
||||
configType: t.type({
|
||||
name: t.string,
|
||||
change: t.string,
|
||||
}),
|
||||
|
||||
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,
|
||||
contexts[0].message?.channel_id || null,
|
||||
contexts[0].user?.id || null,
|
||||
change,
|
||||
);
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue