diff --git a/backend/src/plugins/Automod/actions/changeCounter.ts b/backend/src/plugins/Automod/actions/addToCounter.ts similarity index 62% rename from backend/src/plugins/Automod/actions/changeCounter.ts rename to backend/src/plugins/Automod/actions/addToCounter.ts index a3db8d31..fe293e4c 100644 --- a/backend/src/plugins/Automod/actions/changeCounter.ts +++ b/backend/src/plugins/Automod/actions/addToCounter.ts @@ -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, ); }, }); diff --git a/backend/src/plugins/Automod/actions/availableActions.ts b/backend/src/plugins/Automod/actions/availableActions.ts index 21ebe945..7857db6f 100644 --- a/backend/src/plugins/Automod/actions/availableActions.ts +++ b/backend/src/plugins/Automod/actions/availableActions.ts @@ -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> = { clean: CleanAction, @@ -27,7 +28,8 @@ export const availableActions: Record> = { 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, }); diff --git a/backend/src/plugins/Automod/actions/setCounter.ts b/backend/src/plugins/Automod/actions/setCounter.ts new file mode 100644 index 00000000..0dbbaa37 --- /dev/null +++ b/backend/src/plugins/Automod/actions/setCounter.ts @@ -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, + ); + }, +}); diff --git a/backend/src/plugins/Automod/triggers/availableTriggers.ts b/backend/src/plugins/Automod/triggers/availableTriggers.ts index 175df6d7..18c671b6 100644 --- a/backend/src/plugins/Automod/triggers/availableTriggers.ts +++ b/backend/src/plugins/Automod/triggers/availableTriggers.ts @@ -17,7 +17,7 @@ import { MemberJoinTrigger } from "./memberJoin"; import { RoleAddedTrigger } from "./roleAdded"; import { RoleRemovedTrigger } from "./roleRemoved"; import { StickerSpamTrigger } from "./stickerSpam"; -import { CounterTrigger } from "./counter"; +import { CounterTrigger } from "./counterTrigger"; import { NoteTrigger } from "./note"; import { WarnTrigger } from "./warn"; import { MuteTrigger } from "./mute"; @@ -46,7 +46,7 @@ export const availableTriggers: Record member_join_spam: MemberJoinSpamTrigger, sticker_spam: StickerSpamTrigger, - counter: CounterTrigger, + counter_trigger: CounterTrigger, note: NoteTrigger, warn: WarnTrigger, @@ -77,7 +77,7 @@ export const AvailableTriggers = t.type({ member_join_spam: MemberJoinSpamTrigger.configType, sticker_spam: StickerSpamTrigger.configType, - counter: CounterTrigger.configType, + counter_trigger: CounterTrigger.configType, note: NoteTrigger.configType, warn: WarnTrigger.configType, diff --git a/backend/src/plugins/Automod/triggers/counter.ts b/backend/src/plugins/Automod/triggers/counterTrigger.ts similarity index 100% rename from backend/src/plugins/Automod/triggers/counter.ts rename to backend/src/plugins/Automod/triggers/counterTrigger.ts diff --git a/backend/src/plugins/Counters/CountersPlugin.ts b/backend/src/plugins/Counters/CountersPlugin.ts index b6789e81..68a5bcea 100644 --- a/backend/src/plugins/Counters/CountersPlugin.ts +++ b/backend/src/plugins/Counters/CountersPlugin.ts @@ -102,6 +102,14 @@ const configPreprocessor: ConfigPreprocessorFn = options => * After being triggered, a trigger is "reset" if the counter value no longer matches the trigger (e.g. drops to 100 or below in the above example). After this, that trigger can be triggered again. */ export const CountersPlugin = zeppelinGuildPlugin()("counters", { + showInDocs: true, + info: { + prettyName: "Counters", + description: + "Keep track of per-user, per-channel, or global numbers and trigger specific actions based on this number", + configurationGuide: "See Counters setup guide", + }, + configSchema: ConfigSchema, defaultOptions, configPreprocessor, diff --git a/dashboard/src/components/docs/Counters.vue b/dashboard/src/components/docs/Counters.vue new file mode 100644 index 00000000..c8af5159 --- /dev/null +++ b/dashboard/src/components/docs/Counters.vue @@ -0,0 +1,295 @@ + + + diff --git a/dashboard/src/components/docs/DocsLayout.vue b/dashboard/src/components/docs/DocsLayout.vue index b508ef46..e8657d8a 100644 --- a/dashboard/src/components/docs/DocsLayout.vue +++ b/dashboard/src/components/docs/DocsLayout.vue @@ -115,6 +115,10 @@ to: '/docs/setup-guides/moderation', label: 'Moderation', }, + { + to: '/docs/setup-guides/counters', + label: 'Counters', + }, ], }, ]; diff --git a/dashboard/src/routes.ts b/dashboard/src/routes.ts index c38d1f7e..4ef8e996 100644 --- a/dashboard/src/routes.ts +++ b/dashboard/src/routes.ts @@ -53,6 +53,10 @@ export const router = new VueRouter({ path: "setup-guides/moderation", component: () => import("./components/docs/WorkInProgress.vue"), }, + { + path: "setup-guides/counters", + component: () => import("./components/docs/Counters.vue"), + }, { path: "plugins/:pluginName/:tab?", component: () => import("./components/docs/Plugin.vue"),