mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Typed log functions + more
This commit is contained in:
parent
d2ac700143
commit
bed6589d48
166 changed files with 4021 additions and 869 deletions
|
@ -2,17 +2,24 @@ import { Snowflake, TextChannel } from "discord.js";
|
|||
import * as t from "io-ts";
|
||||
import { erisAllowedMentionsToDjsMentionOptions } from "src/utils/erisAllowedMentionsToDjsMentionOptions";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { renderTemplate, TemplateParseError } from "../../../templateFormatter";
|
||||
import {
|
||||
createTypedTemplateSafeValueContainer,
|
||||
renderTemplate,
|
||||
TemplateParseError,
|
||||
TemplateSafeValueContainer,
|
||||
} from "../../../templateFormatter";
|
||||
import {
|
||||
createChunkedMessage,
|
||||
messageLink,
|
||||
stripObjectToScalars,
|
||||
tAllowedMentions,
|
||||
tNormalizedNullOptional,
|
||||
isTruthy,
|
||||
verboseChannelMention,
|
||||
} from "../../../utils";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { automodAction } from "../helpers";
|
||||
import { TemplateSafeUser, userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||
|
||||
export const AlertAction = automodAction({
|
||||
configType: t.type({
|
||||
|
@ -32,33 +39,39 @@ export const AlertAction = automodAction({
|
|||
const theMessageLink =
|
||||
contexts[0].message && messageLink(pluginData.guild.id, contexts[0].message.channel_id, contexts[0].message.id);
|
||||
|
||||
const safeUsers = contexts.map(c => c.user && stripObjectToScalars(c.user)).filter(Boolean);
|
||||
const safeUsers = contexts.map(c => (c.user ? userToTemplateSafeUser(c.user) : null)).filter(isTruthy);
|
||||
const safeUser = safeUsers[0];
|
||||
const actionsTaken = Object.keys(pluginData.config.get().rules[ruleName].actions).join(", ");
|
||||
|
||||
const logMessage = await logs.getLogMessage(LogType.AUTOMOD_ACTION, {
|
||||
rule: ruleName,
|
||||
user: safeUser,
|
||||
users: safeUsers,
|
||||
actionsTaken,
|
||||
matchSummary: matchResult.summary,
|
||||
});
|
||||
|
||||
let rendered;
|
||||
try {
|
||||
rendered = await renderTemplate(actionConfig.text, {
|
||||
const logMessage = await logs.getLogMessage(
|
||||
LogType.AUTOMOD_ACTION,
|
||||
createTypedTemplateSafeValueContainer({
|
||||
rule: ruleName,
|
||||
user: safeUser,
|
||||
users: safeUsers,
|
||||
text,
|
||||
actionsTaken,
|
||||
matchSummary: matchResult.summary,
|
||||
messageLink: theMessageLink,
|
||||
logMessage,
|
||||
});
|
||||
matchSummary: matchResult.summary ?? "",
|
||||
}),
|
||||
);
|
||||
|
||||
let rendered;
|
||||
try {
|
||||
rendered = await renderTemplate(
|
||||
actionConfig.text,
|
||||
new TemplateSafeValueContainer({
|
||||
rule: ruleName,
|
||||
user: safeUser,
|
||||
users: safeUsers,
|
||||
text,
|
||||
actionsTaken,
|
||||
matchSummary: matchResult.summary,
|
||||
messageLink: theMessageLink,
|
||||
logMessage: logMessage?.content,
|
||||
}),
|
||||
);
|
||||
} catch (err) {
|
||||
if (err instanceof TemplateParseError) {
|
||||
pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, {
|
||||
pluginData.getPlugin(LogsPlugin).logBotAlert({
|
||||
body: `Error in alert format of automod rule ${ruleName}: ${err.message}`,
|
||||
});
|
||||
return;
|
||||
|
@ -75,13 +88,13 @@ export const AlertAction = automodAction({
|
|||
);
|
||||
} catch (err) {
|
||||
if (err.code === 50001) {
|
||||
logs.log(LogType.BOT_ALERT, {
|
||||
logs.logBotAlert({
|
||||
body: `Missing access to send alert to channel ${verboseChannelMention(
|
||||
channel,
|
||||
)} in automod rule **${ruleName}**`,
|
||||
});
|
||||
} else {
|
||||
logs.log(LogType.BOT_ALERT, {
|
||||
logs.logBotAlert({
|
||||
body: `Error ${err.code || "UNKNOWN"} when sending alert to channel ${verboseChannelMention(
|
||||
channel,
|
||||
)} in automod rule **${ruleName}**`,
|
||||
|
@ -89,7 +102,7 @@ export const AlertAction = automodAction({
|
|||
}
|
||||
}
|
||||
} else {
|
||||
logs.log(LogType.BOT_ALERT, {
|
||||
logs.logBotAlert({
|
||||
body: `Invalid channel id \`${actionConfig.channel}\` for alert action in automod rule **${ruleName}**`,
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue