automod: add default configs for actions
This commit is contained in:
parent
6324b9654b
commit
ae97a5dded
16 changed files with 64 additions and 19 deletions
|
@ -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
|
// Enable logging of automod actions by default
|
||||||
if (rule["actions"]) {
|
if (rule["actions"]) {
|
||||||
for (const actionName in rule.actions) {
|
for (const actionName in rule.actions) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
|
||||||
|
|
||||||
export const AddRolesAction = automodAction({
|
export const AddRolesAction = automodAction({
|
||||||
configType: t.array(t.string),
|
configType: t.array(t.string),
|
||||||
|
defaultConfig: [],
|
||||||
|
|
||||||
async apply({ pluginData, contexts, actionConfig }) {
|
async apply({ pluginData, contexts, actionConfig }) {
|
||||||
const members = unique(contexts.map(c => c.member).filter(Boolean));
|
const members = unique(contexts.map(c => c.member).filter(Boolean));
|
||||||
|
|
|
@ -14,6 +14,8 @@ export const AlertAction = automodAction({
|
||||||
text: t.string,
|
text: t.string,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
defaultConfig: {},
|
||||||
|
|
||||||
async apply({ pluginData, contexts, actionConfig, ruleName, matchResult }) {
|
async apply({ pluginData, contexts, actionConfig, ruleName, matchResult }) {
|
||||||
const channel = pluginData.guild.channels.get(actionConfig.channel);
|
const channel = pluginData.guild.channels.get(actionConfig.channel);
|
||||||
const logs = pluginData.getPlugin(LogsPlugin);
|
const logs = pluginData.getPlugin(LogsPlugin);
|
||||||
|
|
|
@ -13,6 +13,10 @@ export const BanAction = automodAction({
|
||||||
deleteMessageDays: tNullable(t.number),
|
deleteMessageDays: tNullable(t.number),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
defaultConfig: {
|
||||||
|
notify: null, // Use defaults from ModActions
|
||||||
|
},
|
||||||
|
|
||||||
async apply({ pluginData, contexts, actionConfig, matchResult }) {
|
async apply({ pluginData, contexts, actionConfig, matchResult }) {
|
||||||
const reason = actionConfig.reason || "Kicked automatically";
|
const reason = actionConfig.reason || "Kicked automatically";
|
||||||
const contactMethods = resolveActionContactMethods(pluginData, actionConfig);
|
const contactMethods = resolveActionContactMethods(pluginData, actionConfig);
|
||||||
|
@ -20,9 +24,7 @@ export const BanAction = automodAction({
|
||||||
|
|
||||||
const caseArgs = {
|
const caseArgs = {
|
||||||
modId: pluginData.client.user.id,
|
modId: pluginData.client.user.id,
|
||||||
extraNotes: [
|
extraNotes: [matchResult.fullSummary],
|
||||||
matchResult.summary, // TODO
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const userIdsToBan = unique(contexts.map(c => c.user?.id).filter(Boolean));
|
const userIdsToBan = unique(contexts.map(c => c.user?.id).filter(Boolean));
|
||||||
|
|
|
@ -9,6 +9,8 @@ export const ChangeNicknameAction = automodAction({
|
||||||
name: t.string,
|
name: t.string,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
defaultConfig: {},
|
||||||
|
|
||||||
async apply({ pluginData, contexts, actionConfig }) {
|
async apply({ pluginData, contexts, actionConfig }) {
|
||||||
const members = unique(contexts.map(c => c.member).filter(Boolean));
|
const members = unique(contexts.map(c => c.member).filter(Boolean));
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { LogType } from "../../../data/LogType";
|
||||||
|
|
||||||
export const CleanAction = automodAction({
|
export const CleanAction = automodAction({
|
||||||
configType: t.boolean,
|
configType: t.boolean,
|
||||||
|
defaultConfig: false,
|
||||||
|
|
||||||
async apply({ pluginData, contexts }) {
|
async apply({ pluginData, contexts }) {
|
||||||
const messageIdsToDeleteByChannelId: Map<string, string[]> = new Map();
|
const messageIdsToDeleteByChannelId: Map<string, string[]> = new Map();
|
||||||
|
|
|
@ -6,6 +6,8 @@ export const ExampleAction = automodAction({
|
||||||
someValue: t.string,
|
someValue: t.string,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
defaultConfig: {},
|
||||||
|
|
||||||
async apply({ pluginData, contexts, actionConfig }) {
|
async apply({ pluginData, contexts, actionConfig }) {
|
||||||
// TODO: Everything
|
// TODO: Everything
|
||||||
},
|
},
|
||||||
|
|
|
@ -12,15 +12,17 @@ export const KickAction = automodAction({
|
||||||
notifyChannel: tNullable(t.string),
|
notifyChannel: tNullable(t.string),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
defaultConfig: {
|
||||||
|
notify: null, // Use defaults from ModActions
|
||||||
|
},
|
||||||
|
|
||||||
async apply({ pluginData, contexts, actionConfig, matchResult }) {
|
async apply({ pluginData, contexts, actionConfig, matchResult }) {
|
||||||
const reason = actionConfig.reason || "Kicked automatically";
|
const reason = actionConfig.reason || "Kicked automatically";
|
||||||
const contactMethods = resolveActionContactMethods(pluginData, actionConfig);
|
const contactMethods = resolveActionContactMethods(pluginData, actionConfig);
|
||||||
|
|
||||||
const caseArgs = {
|
const caseArgs = {
|
||||||
modId: pluginData.client.user.id,
|
modId: pluginData.client.user.id,
|
||||||
extraNotes: [
|
extraNotes: [matchResult.fullSummary],
|
||||||
matchResult.summary, // TODO
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const userIdsToKick = unique(contexts.map(c => c.user?.id).filter(Boolean));
|
const userIdsToKick = unique(contexts.map(c => c.user?.id).filter(Boolean));
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { stripObjectToScalars } from "../../../utils";
|
||||||
|
|
||||||
export const LogAction = automodAction({
|
export const LogAction = automodAction({
|
||||||
configType: t.boolean,
|
configType: t.boolean,
|
||||||
|
defaultConfig: true,
|
||||||
|
|
||||||
async apply({ pluginData, contexts, ruleName, matchResult }) {
|
async apply({ pluginData, contexts, ruleName, matchResult }) {
|
||||||
const safeUsers = contexts.map(c => c.user && stripObjectToScalars(c.user)).filter(Boolean);
|
const safeUsers = contexts.map(c => c.user && stripObjectToScalars(c.user)).filter(Boolean);
|
||||||
|
|
|
@ -14,6 +14,10 @@ export const MuteAction = automodAction({
|
||||||
notifyChannel: tNullable(t.string),
|
notifyChannel: tNullable(t.string),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
defaultConfig: {
|
||||||
|
notify: null, // Use defaults from ModActions
|
||||||
|
},
|
||||||
|
|
||||||
async apply({ pluginData, contexts, actionConfig, matchResult }) {
|
async apply({ pluginData, contexts, actionConfig, matchResult }) {
|
||||||
const duration = actionConfig.duration ? convertDelayStringToMS(actionConfig.duration) : null;
|
const duration = actionConfig.duration ? convertDelayStringToMS(actionConfig.duration) : null;
|
||||||
const reason = actionConfig.reason || "Muted automatically";
|
const reason = actionConfig.reason || "Muted automatically";
|
||||||
|
@ -21,9 +25,7 @@ export const MuteAction = automodAction({
|
||||||
|
|
||||||
const caseArgs = {
|
const caseArgs = {
|
||||||
modId: pluginData.client.user.id,
|
modId: pluginData.client.user.id,
|
||||||
extraNotes: [
|
extraNotes: [matchResult.fullSummary],
|
||||||
matchResult.summary, // TODO
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const userIdsToMute = unique(contexts.map(c => c.user?.id).filter(Boolean));
|
const userIdsToMute = unique(contexts.map(c => c.user?.id).filter(Boolean));
|
||||||
|
|
|
@ -8,6 +8,8 @@ import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
|
||||||
export const RemoveRolesAction = automodAction({
|
export const RemoveRolesAction = automodAction({
|
||||||
configType: t.array(t.string),
|
configType: t.array(t.string),
|
||||||
|
|
||||||
|
defaultConfig: [],
|
||||||
|
|
||||||
async apply({ pluginData, contexts, actionConfig }) {
|
async apply({ pluginData, contexts, actionConfig }) {
|
||||||
const members = unique(contexts.map(c => c.member).filter(Boolean));
|
const members = unique(contexts.map(c => c.member).filter(Boolean));
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,8 @@ export const ReplyAction = automodAction({
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
|
defaultConfig: {},
|
||||||
|
|
||||||
async apply({ pluginData, contexts, actionConfig }) {
|
async apply({ pluginData, contexts, actionConfig }) {
|
||||||
const contextsWithTextChannels = contexts
|
const contextsWithTextChannels = contexts
|
||||||
.filter(c => c.message?.channel_id)
|
.filter(c => c.message?.channel_id)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { setAntiraidLevel } from "../functions/setAntiraidLevel";
|
||||||
|
|
||||||
export const SetAntiraidLevelAction = automodAction({
|
export const SetAntiraidLevelAction = automodAction({
|
||||||
configType: t.string,
|
configType: t.string,
|
||||||
|
defaultConfig: null,
|
||||||
|
|
||||||
async apply({ pluginData, contexts, actionConfig }) {
|
async apply({ pluginData, contexts, actionConfig }) {
|
||||||
setAntiraidLevel(pluginData, actionConfig);
|
setAntiraidLevel(pluginData, actionConfig);
|
||||||
|
|
|
@ -12,15 +12,17 @@ export const WarnAction = automodAction({
|
||||||
notifyChannel: tNullable(t.string),
|
notifyChannel: tNullable(t.string),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
defaultConfig: {
|
||||||
|
notify: null, // Use defaults from ModActions
|
||||||
|
},
|
||||||
|
|
||||||
async apply({ pluginData, contexts, actionConfig, matchResult }) {
|
async apply({ pluginData, contexts, actionConfig, matchResult }) {
|
||||||
const reason = actionConfig.reason || "Warned automatically";
|
const reason = actionConfig.reason || "Warned automatically";
|
||||||
const contactMethods = resolveActionContactMethods(pluginData, actionConfig);
|
const contactMethods = resolveActionContactMethods(pluginData, actionConfig);
|
||||||
|
|
||||||
const caseArgs = {
|
const caseArgs = {
|
||||||
modId: pluginData.client.user.id,
|
modId: pluginData.client.user.id,
|
||||||
extraNotes: [
|
extraNotes: [matchResult.fullSummary],
|
||||||
matchResult.summary, // TODO
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const userIdsToWarn = unique(contexts.map(c => c.user?.id).filter(Boolean));
|
const userIdsToWarn = unique(contexts.map(c => c.user?.id).filter(Boolean));
|
||||||
|
|
|
@ -55,13 +55,16 @@ export async function runAutomod(pluginData: PluginData<AutomodPluginType>, cont
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
matchResult.summary = await trigger.renderMatchInformation({
|
matchResult.summary =
|
||||||
ruleName,
|
(await trigger.renderMatchInformation({
|
||||||
pluginData,
|
ruleName,
|
||||||
contexts,
|
pluginData,
|
||||||
matchResult,
|
contexts,
|
||||||
triggerConfig,
|
matchResult,
|
||||||
});
|
triggerConfig,
|
||||||
|
})) ?? "";
|
||||||
|
|
||||||
|
matchResult.fullSummary = `Triggered automod rule **${ruleName}**\n${matchResult.summary}`.trim();
|
||||||
|
|
||||||
break triggerLoop;
|
break triggerLoop;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
silentClean?: boolean; // TODO: Maybe generalize to a "silent" value in general, which mutes alert/log
|
||||||
|
|
||||||
summary?: string;
|
summary?: string;
|
||||||
|
fullSummary?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type AutomodTriggerMatchFn<TConfigType, TMatchResultExtra> = (meta: {
|
type AutomodTriggerMatchFn<TConfigType, TMatchResultExtra> = (meta: {
|
||||||
|
@ -61,6 +62,8 @@ type AutomodActionApplyFn<TConfigType> = (meta: {
|
||||||
|
|
||||||
export interface AutomodActionBlueprint<TConfigType extends t.Any> {
|
export interface AutomodActionBlueprint<TConfigType extends t.Any> {
|
||||||
configType: TConfigType;
|
configType: TConfigType;
|
||||||
|
defaultConfig: Partial<t.TypeOf<TConfigType>>;
|
||||||
|
|
||||||
apply: AutomodActionApplyFn<t.TypeOf<TConfigType>>;
|
apply: AutomodActionApplyFn<t.TypeOf<TConfigType>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue