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

Fix crash if automod alert message fails to render

This commit is contained in:
Dragory 2020-12-17 03:44:42 +02:00
parent 5056b4376a
commit 116c33e341
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -13,7 +13,7 @@ import {
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods"; import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin"; import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
import { TextChannel } from "eris"; import { TextChannel } from "eris";
import { renderTemplate } from "../../../templateFormatter"; import { renderTemplate, TemplateParseError } from "../../../templateFormatter";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
export const AlertAction = automodAction({ export const AlertAction = automodAction({
@ -45,16 +45,28 @@ export const AlertAction = automodAction({
matchSummary: matchResult.summary, matchSummary: matchResult.summary,
}); });
const rendered = await renderTemplate(actionConfig.text, { let rendered;
rule: ruleName, try {
user: safeUser, rendered = await renderTemplate(actionConfig.text, {
users: safeUsers, rule: ruleName,
text, user: safeUser,
actionsTaken, users: safeUsers,
matchSummary: matchResult.summary, text,
messageLink: theMessageLink, actionsTaken,
logMessage, matchSummary: matchResult.summary,
}); messageLink: theMessageLink,
logMessage,
});
} catch (err) {
if (err instanceof TemplateParseError) {
pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, {
body: `Error in alert format of automod rule ${ruleName}: ${err.message}`,
});
return;
}
throw err;
}
await createChunkedMessage(channel, rendered); await createChunkedMessage(channel, rendered);
} else { } else {