3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-14 21:31:50 +00:00

automod: add default configs for actions

This commit is contained in:
Dragory 2020-07-30 01:45:14 +03:00
parent 6324b9654b
commit ae97a5dded
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
16 changed files with 64 additions and 19 deletions

View file

@ -93,6 +93,23 @@ const configPreprocessor: ConfigPreprocessorFn<AutomodPluginType> = options => {
}
}
if (rule["actions"]) {
for (const actionName in rule["actions"]) {
if (!availableActions[actionName]) {
throw new StrictValidationError([`Unknown action '${actionName}' in rule '${rule.name}'`]);
}
const actionBlueprint = availableActions[actionName];
const actionConfig = rule["actions"][actionName];
if (typeof actionConfig !== "object" || Array.isArray(actionConfig) || actionConfig == null) {
rule["actions"][actionName] = actionConfig;
} else {
rule["actions"][actionName] = configUtils.mergeConfig(actionBlueprint.defaultConfig, actionConfig);
}
}
}
// Enable logging of automod actions by default
if (rule["actions"]) {
for (const actionName in rule.actions) {

View file

@ -7,6 +7,7 @@ import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
export const AddRolesAction = automodAction({
configType: t.array(t.string),
defaultConfig: [],
async apply({ pluginData, contexts, actionConfig }) {
const members = unique(contexts.map(c => c.member).filter(Boolean));

View file

@ -14,6 +14,8 @@ export const AlertAction = automodAction({
text: t.string,
}),
defaultConfig: {},
async apply({ pluginData, contexts, actionConfig, ruleName, matchResult }) {
const channel = pluginData.guild.channels.get(actionConfig.channel);
const logs = pluginData.getPlugin(LogsPlugin);

View file

@ -13,6 +13,10 @@ export const BanAction = automodAction({
deleteMessageDays: tNullable(t.number),
}),
defaultConfig: {
notify: null, // Use defaults from ModActions
},
async apply({ pluginData, contexts, actionConfig, matchResult }) {
const reason = actionConfig.reason || "Kicked automatically";
const contactMethods = resolveActionContactMethods(pluginData, actionConfig);
@ -20,9 +24,7 @@ export const BanAction = automodAction({
const caseArgs = {
modId: pluginData.client.user.id,
extraNotes: [
matchResult.summary, // TODO
],
extraNotes: [matchResult.fullSummary],
};
const userIdsToBan = unique(contexts.map(c => c.user?.id).filter(Boolean));

View file

@ -9,6 +9,8 @@ export const ChangeNicknameAction = automodAction({
name: t.string,
}),
defaultConfig: {},
async apply({ pluginData, contexts, actionConfig }) {
const members = unique(contexts.map(c => c.member).filter(Boolean));

View file

@ -4,6 +4,7 @@ import { LogType } from "../../../data/LogType";
export const CleanAction = automodAction({
configType: t.boolean,
defaultConfig: false,
async apply({ pluginData, contexts }) {
const messageIdsToDeleteByChannelId: Map<string, string[]> = new Map();

View file

@ -6,6 +6,8 @@ export const ExampleAction = automodAction({
someValue: t.string,
}),
defaultConfig: {},
async apply({ pluginData, contexts, actionConfig }) {
// TODO: Everything
},

View file

@ -12,15 +12,17 @@ export const KickAction = automodAction({
notifyChannel: tNullable(t.string),
}),
defaultConfig: {
notify: null, // Use defaults from ModActions
},
async apply({ pluginData, contexts, actionConfig, matchResult }) {
const reason = actionConfig.reason || "Kicked automatically";
const contactMethods = resolveActionContactMethods(pluginData, actionConfig);
const caseArgs = {
modId: pluginData.client.user.id,
extraNotes: [
matchResult.summary, // TODO
],
extraNotes: [matchResult.fullSummary],
};
const userIdsToKick = unique(contexts.map(c => c.user?.id).filter(Boolean));

View file

@ -6,6 +6,7 @@ import { stripObjectToScalars } from "../../../utils";
export const LogAction = automodAction({
configType: t.boolean,
defaultConfig: true,
async apply({ pluginData, contexts, ruleName, matchResult }) {
const safeUsers = contexts.map(c => c.user && stripObjectToScalars(c.user)).filter(Boolean);

View file

@ -14,6 +14,10 @@ export const MuteAction = automodAction({
notifyChannel: tNullable(t.string),
}),
defaultConfig: {
notify: null, // Use defaults from ModActions
},
async apply({ pluginData, contexts, actionConfig, matchResult }) {
const duration = actionConfig.duration ? convertDelayStringToMS(actionConfig.duration) : null;
const reason = actionConfig.reason || "Muted automatically";
@ -21,9 +25,7 @@ export const MuteAction = automodAction({
const caseArgs = {
modId: pluginData.client.user.id,
extraNotes: [
matchResult.summary, // TODO
],
extraNotes: [matchResult.fullSummary],
};
const userIdsToMute = unique(contexts.map(c => c.user?.id).filter(Boolean));

View file

@ -8,6 +8,8 @@ import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
export const RemoveRolesAction = automodAction({
configType: t.array(t.string),
defaultConfig: [],
async apply({ pluginData, contexts, actionConfig }) {
const members = unique(contexts.map(c => c.member).filter(Boolean));

View file

@ -23,6 +23,8 @@ export const ReplyAction = automodAction({
}),
]),
defaultConfig: {},
async apply({ pluginData, contexts, actionConfig }) {
const contextsWithTextChannels = contexts
.filter(c => c.message?.channel_id)

View file

@ -4,6 +4,7 @@ import { setAntiraidLevel } from "../functions/setAntiraidLevel";
export const SetAntiraidLevelAction = automodAction({
configType: t.string,
defaultConfig: null,
async apply({ pluginData, contexts, actionConfig }) {
setAntiraidLevel(pluginData, actionConfig);

View file

@ -12,15 +12,17 @@ export const WarnAction = automodAction({
notifyChannel: tNullable(t.string),
}),
defaultConfig: {
notify: null, // Use defaults from ModActions
},
async apply({ pluginData, contexts, actionConfig, matchResult }) {
const reason = actionConfig.reason || "Warned automatically";
const contactMethods = resolveActionContactMethods(pluginData, actionConfig);
const caseArgs = {
modId: pluginData.client.user.id,
extraNotes: [
matchResult.summary, // TODO
],
extraNotes: [matchResult.fullSummary],
};
const userIdsToWarn = unique(contexts.map(c => c.user?.id).filter(Boolean));

View file

@ -55,13 +55,16 @@ export async function runAutomod(pluginData: PluginData<AutomodPluginType>, cont
return;
}
matchResult.summary = await trigger.renderMatchInformation({
ruleName,
pluginData,
contexts,
matchResult,
triggerConfig,
});
matchResult.summary =
(await trigger.renderMatchInformation({
ruleName,
pluginData,
contexts,
matchResult,
triggerConfig,
})) ?? "";
matchResult.fullSummary = `Triggered automod rule **${ruleName}**\n${matchResult.summary}`.trim();
break triggerLoop;
}

View file

@ -10,6 +10,7 @@ export interface AutomodTriggerMatchResult<TExtra extends any = unknown> {
silentClean?: boolean; // TODO: Maybe generalize to a "silent" value in general, which mutes alert/log
summary?: string;
fullSummary?: string;
}
type AutomodTriggerMatchFn<TConfigType, TMatchResultExtra> = (meta: {
@ -61,6 +62,8 @@ type AutomodActionApplyFn<TConfigType> = (meta: {
export interface AutomodActionBlueprint<TConfigType extends t.Any> {
configType: TConfigType;
defaultConfig: Partial<t.TypeOf<TConfigType>>;
apply: AutomodActionApplyFn<t.TypeOf<TConfigType>>;
}