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:
parent
ab8ea2e7e5
commit
4147298120
9 changed files with 347 additions and 16 deletions
|
@ -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,
|
||||
);
|
||||
},
|
||||
});
|
|
@ -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,
|
||||
});
|
||||
|
|
22
backend/src/plugins/Automod/actions/setCounter.ts
Normal file
22
backend/src/plugins/Automod/actions/setCounter.ts
Normal 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,
|
||||
);
|
||||
},
|
||||
});
|
|
@ -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<string, AutomodTriggerBlueprint<any, any>
|
|||
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,
|
||||
|
|
|
@ -102,6 +102,14 @@ const configPreprocessor: ConfigPreprocessorFn<CountersPluginType> = 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<CountersPluginType>()("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 <a href='/docs/setup-guides/counters'>Counters setup guide</a>",
|
||||
},
|
||||
|
||||
configSchema: ConfigSchema,
|
||||
defaultOptions,
|
||||
configPreprocessor,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue