mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +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,6 +5,7 @@ import { canActOn } from "../../../pluginUtils";
|
|||
import { TemplateSafeValueContainer, renderTemplate } from "../../../templateFormatter";
|
||||
import { resolveMember, zSnowflake } from "../../../utils";
|
||||
import { ActionError } from "../ActionError";
|
||||
import { catchTemplateError } from "../catchTemplateError";
|
||||
import { CustomEventsPluginType, TCustomEvent } from "../types";
|
||||
|
||||
export const zMoveToVoiceChannelAction = z.strictObject({
|
||||
|
@ -21,7 +22,10 @@ export async function moveToVoiceChannelAction(
|
|||
event: TCustomEvent,
|
||||
eventData: any,
|
||||
) {
|
||||
const targetId = await renderTemplate(action.target, values, false);
|
||||
const targetId = await catchTemplateError(
|
||||
() => renderTemplate(action.target, values, false),
|
||||
"Invalid target format",
|
||||
);
|
||||
const target = await resolveMember(pluginData.client, pluginData.guild, targetId);
|
||||
if (!target) throw new ActionError("Unknown target member");
|
||||
|
||||
|
@ -29,7 +33,10 @@ export async function moveToVoiceChannelAction(
|
|||
throw new ActionError("Missing permissions");
|
||||
}
|
||||
|
||||
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 VoiceChannel)) throw new ActionError("Target channel is not a voice channel");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue