3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-06-07 16:05:01 +00:00

feat: handle template errors

Fixes ZDEV-20
This commit is contained in:
Dragory 2024-01-27 16:01:48 +02:00
parent 2ce5082018
commit ffa9eeb3f5
No known key found for this signature in database
14 changed files with 231 additions and 94 deletions

View file

@ -4,6 +4,7 @@ import z from "zod";
import { TemplateSafeValueContainer, renderTemplate } from "../../../templateFormatter";
import { zBoundedCharacters, zSnowflake } from "../../../utils";
import { ActionError } from "../ActionError";
import { catchTemplateError } from "../catchTemplateError";
import { CustomEventsPluginType } from "../types";
export const zMessageAction = z.strictObject({
@ -18,7 +19,10 @@ export async function messageAction(
action: TMessageAction,
values: TemplateSafeValueContainer,
) {
const targetChannelId = await renderTemplate(action.channel, values, false);
const targetChannelId = await catchTemplateError(
() => renderTemplate(action.channel, values, false),
"Invalid channel format",
);
const targetChannel = pluginData.guild.channels.cache.get(targetChannelId as Snowflake);
if (!targetChannel) throw new ActionError("Unknown target channel");
if (!(targetChannel instanceof TextChannel)) throw new ActionError("Target channel is not a text channel");