3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Merge pull request #475 from rubyowo/feat/pretty_name

feat: pretty_name for automod
This commit is contained in:
Miikka 2024-05-19 13:33:21 +03:00 committed by GitHub
commit 0a38440bca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 17 additions and 4 deletions

View file

@ -86,7 +86,7 @@
"BOT_ALERT": "{timestamp} ⚠ **BOT ALERT:** {tmplEval(body)}", "BOT_ALERT": "{timestamp} ⚠ **BOT ALERT:** {tmplEval(body)}",
"DM_FAILED": "{timestamp} \uD83D\uDEA7 Failed to send DM ({source}) to {userMention(user)}", "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_USER": "{timestamp} ⚔ {userMention(user)} set anti-raid to **{level}**",
"SET_ANTIRAID_AUTO": "{timestamp} ⚔ Anti-raid automatically set 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({ export const AlertAction = automodAction({
configSchema, 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 channel = pluginData.guild.channels.cache.get(actionConfig.channel as Snowflake);
const logs = pluginData.getPlugin(LogsPlugin); const logs = pluginData.getPlugin(LogsPlugin);
@ -55,6 +55,7 @@ export const AlertAction = automodAction({
users: safeUsers, users: safeUsers,
actionsTaken, actionsTaken,
matchSummary: matchResult.summary ?? "", matchSummary: matchResult.summary ?? "",
prettyName,
}), }),
); );
@ -69,6 +70,7 @@ export const AlertAction = automodAction({
text, text,
actionsTaken, actionsTaken,
matchSummary: matchResult.summary, matchSummary: matchResult.summary,
prettyName,
messageLink: theMessageLink, messageLink: theMessageLink,
logMessage: validateAndParseMessageContent(logMessage)?.content, logMessage: validateAndParseMessageContent(logMessage)?.content,
}), }),

View file

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

View file

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

View file

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

View file

@ -61,6 +61,7 @@ const zRule = z.strictObject({
} }
return ruleName; return ruleName;
}), }),
pretty_name: z.string().optional(),
presets: z.array(z.string().max(100)).max(25).default([]), presets: z.array(z.string().max(100)).max(25).default([]),
affects_bots: z.boolean().default(false), affects_bots: z.boolean().default(false),
affects_self: 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 { export interface LogAutomodActionData {
rule: string; rule: string;
prettyName: string | undefined;
user?: User | null; user?: User | null;
users: User[]; users: User[];
actionsTaken: string; actionsTaken: string;
@ -20,6 +21,7 @@ export function logAutomodAction(pluginData: GuildPluginData<LogsPluginType>, da
LogType.AUTOMOD_ACTION, LogType.AUTOMOD_ACTION,
createTypedTemplateSafeValueContainer({ createTypedTemplateSafeValueContainer({
rule: data.rule, rule: data.rule,
prettyName: data.prettyName,
user: data.user ? userToTemplateSafeUser(data.user) : null, user: data.user ? userToTemplateSafeUser(data.user) : null,
users: data.users.map((user) => userToTemplateSafeUser(user)), users: data.users.map((user) => userToTemplateSafeUser(user)),
actionsTaken: data.actionsTaken, actionsTaken: data.actionsTaken,