From f2f246ee84f60215c2cbd4e8f41d69c20f18c522 Mon Sep 17 00:00:00 2001 From: metal Date: Sat, 4 Sep 2021 17:11:10 +0100 Subject: [PATCH] Custom Events fixes (#255) --- .../src/plugins/CustomEvents/CustomEventsPlugin.ts | 2 +- .../plugins/CustomEvents/actions/addRoleAction.ts | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/backend/src/plugins/CustomEvents/CustomEventsPlugin.ts b/backend/src/plugins/CustomEvents/CustomEventsPlugin.ts index 009bf5a6..391ee191 100644 --- a/backend/src/plugins/CustomEvents/CustomEventsPlugin.ts +++ b/backend/src/plugins/CustomEvents/CustomEventsPlugin.ts @@ -51,7 +51,7 @@ export const CustomEventsPlugin = zeppelinGuildPlugin()( } const values = createTypedTemplateSafeValueContainer({ - ...args, + ...safeArgs, msg: messageToTemplateSafeMessage(message), }); diff --git a/backend/src/plugins/CustomEvents/actions/addRoleAction.ts b/backend/src/plugins/CustomEvents/actions/addRoleAction.ts index 4fb21bf1..6b83770a 100644 --- a/backend/src/plugins/CustomEvents/actions/addRoleAction.ts +++ b/backend/src/plugins/CustomEvents/actions/addRoleAction.ts @@ -28,9 +28,11 @@ export async function addRoleAction( if (event.trigger.type === "command" && !canActOn(pluginData, eventData.msg.member, target)) { throw new ActionError("Missing permissions"); } - - const rolesToAdd = Array.isArray(action.role) ? action.role : [action.role]; - await target.edit({ - roles: Array.from(new Set([...target.roles.cache.values(), ...rolesToAdd])) as Snowflake[], - }); + const rolesToAdd = (Array.isArray(action.role) ? action.role : [action.role]).filter( + id => !target.roles.cache.has(id), + ); + if (rolesToAdd.length === 0) { + throw new ActionError("Target already has the role(s) specified"); + } + await target.roles.add(rolesToAdd); }