mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-06-17 03:25: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
|
@ -4,6 +4,7 @@ import { canActOn } from "../../../pluginUtils";
|
|||
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
|
||||
import { resolveMember, zSnowflake } from "../../../utils";
|
||||
import { ActionError } from "../ActionError";
|
||||
import { catchTemplateError } from "../catchTemplateError";
|
||||
import { CustomEventsPluginType, TCustomEvent } from "../types";
|
||||
|
||||
export const zAddRoleAction = z.strictObject({
|
||||
|
@ -20,7 +21,10 @@ export async function addRoleAction(
|
|||
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: ${targetId}`);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue