From 6f0b3e0568bb9bf29a95c95ce44c240978efb42f Mon Sep 17 00:00:00 2001 From: metal Date: Sat, 21 Aug 2021 14:58:34 +0000 Subject: [PATCH] CustomEvents: check existing roles on addRoleAction --- .../src/plugins/CustomEvents/actions/addRoleAction.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/src/plugins/CustomEvents/actions/addRoleAction.ts b/backend/src/plugins/CustomEvents/actions/addRoleAction.ts index 4fb21bf1..f511398a 100644 --- a/backend/src/plugins/CustomEvents/actions/addRoleAction.ts +++ b/backend/src/plugins/CustomEvents/actions/addRoleAction.ts @@ -28,9 +28,12 @@ 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]; + const targetRoles = [...target.roles.cache.keys()]; + const rolesToAdd = (Array.isArray(action.role) ? action.role : [action.role]).filter(id => !targetRoles.includes(id)); + if (rolesToAdd.length === 0) { + throw new ActionError("Target already has the role(s) specified"); + } await target.edit({ - roles: Array.from(new Set([...target.roles.cache.values(), ...rolesToAdd])) as Snowflake[], + roles: Array.from(new Set([...targetRoles, ...rolesToAdd])) as Snowflake[], }); }