mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-14 22:05:01 +00:00
feat: handle template errors
Fixes ZDEV-20
This commit is contained in:
parent
2ce5082018
commit
ffa9eeb3f5
14 changed files with 231 additions and 94 deletions
|
@ -5,7 +5,7 @@ import { CaseTypes } from "../../../data/CaseTypes";
|
|||
import { LogType } from "../../../data/LogType";
|
||||
import { registerExpiringTempban } from "../../../data/loops/expiringTempbansLoop";
|
||||
import { logger } from "../../../logger";
|
||||
import { TemplateSafeValueContainer, renderTemplate } from "../../../templateFormatter";
|
||||
import { TemplateParseError, TemplateSafeValueContainer, renderTemplate } from "../../../templateFormatter";
|
||||
import {
|
||||
DAYS,
|
||||
SECONDS,
|
||||
|
@ -52,30 +52,52 @@ export async function banUserId(
|
|||
|
||||
if (contactMethods.length) {
|
||||
if (!banTime && config.ban_message) {
|
||||
const banMessage = await renderTemplate(
|
||||
config.ban_message,
|
||||
new TemplateSafeValueContainer({
|
||||
guildName: pluginData.guild.name,
|
||||
reason,
|
||||
moderator: banOptions.caseArgs?.modId
|
||||
? userToTemplateSafeUser(await resolveUser(pluginData.client, banOptions.caseArgs.modId))
|
||||
: null,
|
||||
}),
|
||||
);
|
||||
let banMessage: string;
|
||||
try {
|
||||
banMessage = await renderTemplate(
|
||||
config.ban_message,
|
||||
new TemplateSafeValueContainer({
|
||||
guildName: pluginData.guild.name,
|
||||
reason,
|
||||
moderator: banOptions.caseArgs?.modId
|
||||
? userToTemplateSafeUser(await resolveUser(pluginData.client, banOptions.caseArgs.modId))
|
||||
: null,
|
||||
}),
|
||||
);
|
||||
} catch (err) {
|
||||
if (err instanceof TemplateParseError) {
|
||||
return {
|
||||
status: "failed",
|
||||
error: `Invalid ban_message format: ${err.message}`,
|
||||
};
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
notifyResult = await notifyUser(member.user, banMessage, contactMethods);
|
||||
} else if (banTime && config.tempban_message) {
|
||||
const banMessage = await renderTemplate(
|
||||
config.tempban_message,
|
||||
new TemplateSafeValueContainer({
|
||||
guildName: pluginData.guild.name,
|
||||
reason,
|
||||
moderator: banOptions.caseArgs?.modId
|
||||
? userToTemplateSafeUser(await resolveUser(pluginData.client, banOptions.caseArgs.modId))
|
||||
: null,
|
||||
banTime: humanizeDuration(banTime),
|
||||
}),
|
||||
);
|
||||
let banMessage: string;
|
||||
try {
|
||||
banMessage = await renderTemplate(
|
||||
config.tempban_message,
|
||||
new TemplateSafeValueContainer({
|
||||
guildName: pluginData.guild.name,
|
||||
reason,
|
||||
moderator: banOptions.caseArgs?.modId
|
||||
? userToTemplateSafeUser(await resolveUser(pluginData.client, banOptions.caseArgs.modId))
|
||||
: null,
|
||||
banTime: humanizeDuration(banTime),
|
||||
}),
|
||||
);
|
||||
} catch (err) {
|
||||
if (err instanceof TemplateParseError) {
|
||||
return {
|
||||
status: "failed",
|
||||
error: `Invalid tempban_message format: ${err.message}`,
|
||||
};
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
notifyResult = await notifyUser(member.user, banMessage, contactMethods);
|
||||
} else {
|
||||
|
|
|
@ -2,7 +2,7 @@ import { GuildMember } from "discord.js";
|
|||
import { GuildPluginData } from "knub";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
|
||||
import { renderTemplate, TemplateParseError, TemplateSafeValueContainer } from "../../../templateFormatter";
|
||||
import { createUserNotificationError, notifyUser, resolveUser, ucfirst, UserNotificationResult } from "../../../utils";
|
||||
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
|
@ -31,16 +31,27 @@ export async function kickMember(
|
|||
|
||||
if (contactMethods.length) {
|
||||
if (config.kick_message) {
|
||||
const kickMessage = await renderTemplate(
|
||||
config.kick_message,
|
||||
new TemplateSafeValueContainer({
|
||||
guildName: pluginData.guild.name,
|
||||
reason,
|
||||
moderator: kickOptions.caseArgs?.modId
|
||||
? userToTemplateSafeUser(await resolveUser(pluginData.client, kickOptions.caseArgs.modId))
|
||||
: null,
|
||||
}),
|
||||
);
|
||||
let kickMessage: string;
|
||||
try {
|
||||
kickMessage = await renderTemplate(
|
||||
config.kick_message,
|
||||
new TemplateSafeValueContainer({
|
||||
guildName: pluginData.guild.name,
|
||||
reason,
|
||||
moderator: kickOptions.caseArgs?.modId
|
||||
? userToTemplateSafeUser(await resolveUser(pluginData.client, kickOptions.caseArgs.modId))
|
||||
: null,
|
||||
}),
|
||||
);
|
||||
} catch (err) {
|
||||
if (err instanceof TemplateParseError) {
|
||||
return {
|
||||
status: "failed",
|
||||
error: `Invalid kick_message format: ${err.message}`,
|
||||
};
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
notifyResult = await notifyUser(member.user, kickMessage, contactMethods);
|
||||
} else {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { GuildMember, Snowflake } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { TemplateSafeValueContainer, renderTemplate } from "../../../templateFormatter";
|
||||
import { TemplateParseError, TemplateSafeValueContainer, renderTemplate } from "../../../templateFormatter";
|
||||
import { UserNotificationResult, createUserNotificationError, notifyUser, resolveUser, ucfirst } from "../../../utils";
|
||||
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||
import { waitForButtonConfirm } from "../../../utils/waitForInteraction";
|
||||
|
@ -20,16 +20,27 @@ export async function warnMember(
|
|||
|
||||
let notifyResult: UserNotificationResult;
|
||||
if (config.warn_message) {
|
||||
const warnMessage = await renderTemplate(
|
||||
config.warn_message,
|
||||
new TemplateSafeValueContainer({
|
||||
guildName: pluginData.guild.name,
|
||||
reason,
|
||||
moderator: warnOptions.caseArgs?.modId
|
||||
? userToTemplateSafeUser(await resolveUser(pluginData.client, warnOptions.caseArgs.modId))
|
||||
: null,
|
||||
}),
|
||||
);
|
||||
let warnMessage: string;
|
||||
try {
|
||||
warnMessage = await renderTemplate(
|
||||
config.warn_message,
|
||||
new TemplateSafeValueContainer({
|
||||
guildName: pluginData.guild.name,
|
||||
reason,
|
||||
moderator: warnOptions.caseArgs?.modId
|
||||
? userToTemplateSafeUser(await resolveUser(pluginData.client, warnOptions.caseArgs.modId))
|
||||
: null,
|
||||
}),
|
||||
);
|
||||
} catch (err) {
|
||||
if (err instanceof TemplateParseError) {
|
||||
return {
|
||||
status: "failed",
|
||||
error: `Invalid warn_message format: ${err.message}`,
|
||||
};
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
const contactMethods = warnOptions?.contactMethods
|
||||
? warnOptions.contactMethods
|
||||
: getDefaultContactMethods(pluginData, "warn");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue