Merge branch 'master' of github.com:Dragory/ZeppelinBot

This commit is contained in:
Dragory 2024-05-19 13:48:23 +03:00
commit 8a4f7fe0e8
No known key found for this signature in database
7 changed files with 17 additions and 4 deletions

View file

@ -86,7 +86,7 @@
"BOT_ALERT": "{timestamp} ⚠ **BOT ALERT:** {tmplEval(body)}",
"DM_FAILED": "{timestamp} \uD83D\uDEA7 Failed to send DM ({source}) to {userMention(user)}",
"AUTOMOD_ACTION": "{timestamp} \uD83E\uDD16 Automod rule **{rule}** triggered by {userMention(users)}\n{matchSummary}\nActions taken: **{actionsTaken}**",
"AUTOMOD_ACTION": "{timestamp} \uD83E\uDD16 Automod rule **{if(not(prettyName), rule, prettyName)}** triggered by {userMention(users)}\n{matchSummary}\nActions taken: **{actionsTaken}**",
"SET_ANTIRAID_USER": "{timestamp} ⚔ {userMention(user)} set anti-raid to **{level}**",
"SET_ANTIRAID_AUTO": "{timestamp} ⚔ Anti-raid automatically set to **{level}**"
}

View file

@ -34,7 +34,7 @@ const configSchema = z.object({
export const AlertAction = automodAction({
configSchema,
async apply({ pluginData, contexts, actionConfig, ruleName, matchResult }) {
async apply({ pluginData, contexts, actionConfig, ruleName, matchResult, prettyName }) {
const channel = pluginData.guild.channels.cache.get(actionConfig.channel as Snowflake);
const logs = pluginData.getPlugin(LogsPlugin);
@ -55,6 +55,7 @@ export const AlertAction = automodAction({
users: safeUsers,
actionsTaken,
matchSummary: matchResult.summary ?? "",
prettyName,
}),
);
@ -69,6 +70,7 @@ export const AlertAction = automodAction({
text,
actionsTaken,
matchSummary: matchResult.summary,
prettyName,
messageLink: theMessageLink,
logMessage: validateAndParseMessageContent(logMessage)?.content,
}),

View file

@ -6,13 +6,14 @@ import { automodAction } from "../helpers.js";
export const LogAction = automodAction({
configSchema: z.boolean().default(true),
async apply({ pluginData, contexts, ruleName, matchResult }) {
async apply({ pluginData, contexts, ruleName, matchResult, prettyName }) {
const users = unique(contexts.map((c) => c.user)).filter(isTruthy);
const user = users[0];
const actionsTaken = Object.keys(pluginData.config.get().rules[ruleName].actions).join(", ");
pluginData.getPlugin(LogsPlugin).logAutomodAction({
rule: ruleName,
prettyName,
user,
users,
actionsTaken,

View file

@ -35,6 +35,8 @@ export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>,
});
for (const [ruleName, rule] of Object.entries(config.rules)) {
const prettyName = rule.pretty_name;
if (rule.enabled === false) continue;
if (
!rule.affects_bots &&
@ -100,6 +102,7 @@ export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>,
contexts,
actionConfig: true,
matchResult,
prettyName,
});
return;
}
@ -113,7 +116,9 @@ export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>,
triggerConfig,
})) ?? "";
matchResult.fullSummary = `Triggered automod rule **${ruleName}**\n${matchResult.summary}`.trim();
matchResult.fullSummary = `Triggered automod rule **${prettyName ?? ruleName}**\n${
matchResult.summary
}`.trim();
}
if (profilingEnabled()) {
@ -147,6 +152,7 @@ export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>,
contexts,
actionConfig,
matchResult,
prettyName,
});
if (profilingEnabled()) {

View file

@ -59,6 +59,7 @@ type AutomodActionApplyFn<TConfigType> = (meta: {
contexts: AutomodContext[];
actionConfig: TConfigType;
matchResult: AutomodTriggerMatchResult;
prettyName: string | undefined;
}) => Awaitable<void>;
export interface AutomodActionBlueprint<TConfigSchema extends ZodTypeAny> {

View file

@ -61,6 +61,7 @@ const zRule = z.strictObject({
}
return ruleName;
}),
pretty_name: z.string().optional(),
presets: z.array(z.string().max(100)).max(25).default([]),
affects_bots: z.boolean().default(false),
affects_self: z.boolean().default(false),

View file

@ -8,6 +8,7 @@ import { log } from "../util/log.js";
export interface LogAutomodActionData {
rule: string;
prettyName: string | undefined;
user?: User | null;
users: User[];
actionsTaken: string;
@ -20,6 +21,7 @@ export function logAutomodAction(pluginData: GuildPluginData<LogsPluginType>, da
LogType.AUTOMOD_ACTION,
createTypedTemplateSafeValueContainer({
rule: data.rule,
prettyName: data.prettyName,
user: data.user ? userToTemplateSafeUser(data.user) : null,
users: data.users.map((user) => userToTemplateSafeUser(user)),
actionsTaken: data.actionsTaken,