2021-02-13 17:29:10 +02:00
|
|
|
import * as t from "io-ts";
|
2021-04-11 13:44:48 +03:00
|
|
|
import { LogType } from "../../../data/LogType";
|
2021-06-06 23:51:32 +02:00
|
|
|
import { CountersPlugin } from "../../Counters/CountersPlugin";
|
|
|
|
import { automodAction } from "../helpers";
|
2021-02-13 17:29:10 +02:00
|
|
|
|
2021-04-02 17:44:21 +03:00
|
|
|
export const AddToCounterAction = automodAction({
|
2021-02-13 17:29:10 +02:00
|
|
|
configType: t.type({
|
2021-04-02 17:44:21 +03:00
|
|
|
counter: t.string,
|
|
|
|
amount: t.number,
|
2021-02-13 17:29:10 +02:00
|
|
|
}),
|
|
|
|
|
|
|
|
defaultConfig: {},
|
|
|
|
|
2021-04-11 13:44:48 +03:00
|
|
|
async apply({ pluginData, contexts, actionConfig, matchResult, ruleName }) {
|
2021-02-13 17:29:10 +02:00
|
|
|
const countersPlugin = pluginData.getPlugin(CountersPlugin);
|
2021-04-11 13:44:48 +03:00
|
|
|
if (!countersPlugin.counterExists(actionConfig.counter)) {
|
|
|
|
pluginData.state.logs.log(LogType.BOT_ALERT, {
|
|
|
|
body: `Unknown counter \`${actionConfig.counter}\` in \`add_to_counter\` action of Automod rule \`${ruleName}\``,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-13 17:29:10 +02:00
|
|
|
countersPlugin.changeCounterValue(
|
2021-04-02 17:44:21 +03:00
|
|
|
actionConfig.counter,
|
2021-02-13 17:29:10 +02:00
|
|
|
contexts[0].message?.channel_id || null,
|
|
|
|
contexts[0].user?.id || null,
|
2021-04-02 17:44:21 +03:00
|
|
|
actionConfig.amount,
|
2021-02-13 17:29:10 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|