changed roles service

AddRoles and RemoveRoles now take object[] with name, reason string as items
This commit is contained in:
steev
2022-12-21 08:24:23 +01:00
parent 3a699da4d0
commit c81c9b5e52
2 changed files with 27 additions and 8 deletions

8
.gitignore vendored
View File

@ -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

View File

@ -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)
})
}