Fix crash if automod alert message fails to render
This commit is contained in:
parent
5056b4376a
commit
116c33e341
1 changed files with 23 additions and 11 deletions
|
@ -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 {
|
||||||
|
|
Loading…
Add table
Reference in a new issue