From 7a6a9bf748c6192660b131e6a5b49bfe014c2ebd Mon Sep 17 00:00:00 2001 From: Ralph Date: Fri, 30 Mar 2018 17:51:54 -0400 Subject: [PATCH 1/2] Added Base Role Functionality --- bot/modules/rolesetter.js | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/bot/modules/rolesetter.js b/bot/modules/rolesetter.js index e7f7a64..e0fa442 100644 --- a/bot/modules/rolesetter.js +++ b/bot/modules/rolesetter.js @@ -14,11 +14,30 @@ exports.addrole = { process: function(bot, msg, suffix) { // Here the bot,msg and suffix is avaible, this function can be async if needed. var newrole = msg.guild.roles.find('name', suffix); + var baserole = msg.guild.roles.find('name', rolelist.baserole); // Checks if the user put a role in the message. if (suffix) { // Checks if the role mentioned in the message is in the allowed roles listed in the wunderbot config. if (rolelist.allowedroles.includes(suffix)) { + // Checks if the role even exists in the discord server + if (newrole !== null) { + // Checks if the member has the role that they are trying to add + if (!msg.member.roles.find('name', suffix)) { + msg.member.addRole(newrole).then(msg.channel.send(msg.member + ' has been added to the ' + suffix + ' role!')); + if (baserole !== null) { + if (!msg.member.roles.find('name', rolelist.baserole)) { + msg.member.addRole(baserole).then(msg.channel.send(msg.member + ' has been added to the ' + rolelist.baserole + ' role!')); + } + } else { + msg.channel.send('The ' + rolelist.baserole + " Doesn't exist. Please add that role first!"); + } + } else { + msg.channel.send('It seems that you already have that role! Try removing it first with the ' + botconfig.prefix + 'delrole command!'); + } + } else { + msg.channel.send('The role ' + '`' + suffix + '`' + ' does not exist!'); + } // Checks if the role even exists in the discord server if (newrole !== null) { // Checks if the member has the role that they are trying to add @@ -62,8 +81,6 @@ exports.delrole = { } else { msg.channel.send("That role isn't one you can add yourself too! Please run the " + botconfig.prefix + 'roles command to find out which ones are allowed.'); } - } else { - msg.channel.send('Please specify a role. Type ' + botconfig.prefix + 'roles to see which you may add!'); } } }; @@ -82,6 +99,16 @@ exports.roles = { name: 'List of roles', value: buildRoleString(rolelist.allowedroles), inline: false + }, + { + name: 'How to add a role to yourself', + value: '!addrole (role) - Adds a specified role to yourself.\n!addrole Certified Troll would add the Certified Troll role.', + inline: false + }, + { + name: 'How to remove a role from yourself', + value: '!delrole (role) - Removed a specified role from yourself.\n!delrole Certified Troll would remove the Certified Troll role.', + inline: false } ], footer: { From ba9f3de3d6777a3f324e807baeb4ab4fdb08e731 Mon Sep 17 00:00:00 2001 From: Ralph Date: Fri, 30 Mar 2018 17:54:56 -0400 Subject: [PATCH 2/2] Update rolesetter.js --- bot/modules/rolesetter.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bot/modules/rolesetter.js b/bot/modules/rolesetter.js index e0fa442..9bc7170 100644 --- a/bot/modules/rolesetter.js +++ b/bot/modules/rolesetter.js @@ -81,6 +81,8 @@ exports.delrole = { } else { msg.channel.send("That role isn't one you can add yourself too! Please run the " + botconfig.prefix + 'roles command to find out which ones are allowed.'); } + } else { + msg.channel.send('Please specify a role. Type ' + botconfig.prefix + 'roles to see which you may add!'); } } };