From c81c9b5e52db7344b829d16ccdf2ff36e926487f Mon Sep 17 00:00:00 2001 From: steev Date: Wed, 21 Dec 2022 08:24:23 +0100 Subject: [PATCH] changed roles service AddRoles and RemoveRoles now take object[] with name, reason string as items --- .gitignore | 8 ++++++++ Commons/Services/Roles.js | 27 +++++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 6704566..82bb026 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,14 @@ lerna-debug.log* # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json +# Jetbrains +.fleet +.idea + +# vscode +.vscode +.code + # Runtime data pids *.pid diff --git a/Commons/Services/Roles.js b/Commons/Services/Roles.js index 773901a..c0add21 100644 --- a/Commons/Services/Roles.js +++ b/Commons/Services/Roles.js @@ -31,7 +31,7 @@ const AddRole = async (userVal, roleName, bot, reason) => { @param {string} roleName name of role to assign a user @param {discord.Client} bot the bots instance */ -const AddRoles = async (userVal, roleNames, bot, reason) => { +const AddRoles = async (userVal, roles, bot, reason) => { // error handling if (userVal == undefined) { throw "error user was undefined" } @@ -44,12 +44,12 @@ const AddRoles = async (userVal, roleNames, bot, reason) => { // fetching required data const guild = bot.guilds.cache.first() - roleNames.forEach(r => { - const role = guild.roles.find("name", r) + roles.forEach(r => { + const role = guild.roles.find("name", r.name) if (role == undefined) { throw `error couldnt find role ${role}` } - userVal.roles.add(role, reason) + userVal.roles.add(role, r.reason) }) } @@ -85,7 +85,18 @@ revokes a given roles to a given user @param {string} roleName name of role to assign a user @param {discord.Client} bot the bots instance */ -const RemoveRoles = async (userVal, roleNames, bot, reason) => { +const RemoveRoles = async (userVal, roles, bot) => { + + [ + { + name: "role", + reason: "given as a test" + }, + { + name: "role", + reason: undefined + }, + ] // error handling if (userVal == undefined) { throw "error user was undefined" } @@ -98,11 +109,11 @@ const RemoveRoles = async (userVal, roleNames, bot, reason) => { // fetching required data const guild = bot.guilds.cache.first() - roleNames.forEach(r => { - const role = guild.roles.find("name", r) + roles.forEach(r => { + const role = guild.roles.find("name", r.name) if (role == undefined) { throw `error couldnt find role ${role}` } - userVal.roles.remove(role, reason) + userVal.roles.remove(role, r.reason) }) } \ No newline at end of file