From a99d91b04c5116a3c3da013261e896e5d79aed7a Mon Sep 17 00:00:00 2001 From: Ralph Date: Fri, 27 Oct 2017 01:19:43 -0400 Subject: [PATCH 1/7] Create rolesetter.js This module adds the ability to add/remove roles, as well as list the "allowed" Roles that the bot can add and remove. --- bot/modules/rolesetter.js | 76 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 bot/modules/rolesetter.js diff --git a/bot/modules/rolesetter.js b/bot/modules/rolesetter.js new file mode 100644 index 0000000..832a36d --- /dev/null +++ b/bot/modules/rolesetter.js @@ -0,0 +1,76 @@ + +var config = require('config'); +rolelist = config.get('rolelist'); + +exports.commands = [ + "addrole", // command that is in this file, every command needs it own export as shown below + "delrole", + "roles" +] + +exports.addrole = { + usage: "", + description: 'description of command', + 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 rolecheck = msg.guild.roles; + //var rolecheckvar = JSON.parse(rolecheck).find('name', suffix); + + //console.log('Addrole Event firing.'); + //console.log(rolelist); + //console.log(rolelist.allowedroles); + //console.log(config.get('allowedroles')); + if (suffix === rolelist.allowedroles.Member || rolelist.allowedroles.Trustee) { + //console.log('Role is in allowed roles.'); + //console.log('Role to add: ' + newrole); + if (!msg.member.roles.find('name', suffix)) { + msg.member.addRole(newrole) + .then(msg.channel.send(msg.member + ' has been added to the ' + suffix + ' role!')); + //console.log('Added role') + //msg.channel.send(msg.member + ' has been added to the ' + suffix + ' role!'); + } + else{ + msg.channel.send('It seems that you already have that role! Try removing it first with the delrole command!'); + } + } + else { + msg.channel.send("That role isn't one you can add yourself too! Please run the roles command to find out which ones are allowed."); + } + + + } +}; +exports.delrole = { + usage: "", + description: 'description of command', + process: function(bot,msg,suffix) { + // Here the bot,msg and suffix is avaible, this function can be async if needed. + var oldrole = msg.guild.roles.find('name', suffix); + //console.log(oldrole); + //console.log('Delrole Event firing.'); + //console.log(msg); + //console.log('Printing Suffix! ' + suffix); + if (suffix === rolelist.allowedroles.Member || rolelist.allowedroles.Trustee) { + if (msg.member.roles.find('name', suffix)) { + msg.member.removeRole(oldrole); + msg.channel.send(msg.member + ' has been removed from the ' + suffix + ' role!') + } + else { + msg.channel.send("You don't seem to have that role! Try adding it first with the addrole command!"); + } + } + else { + msg.channel.send("That role isn't one you can add yourself too! Please run the roles command to find out which ones are allowed."); + } + + } +}; +exports.roles = { + usage: "", + description: 'description of command', + process: function(bot,msg,suffix){ + // Here the bot,msg and suffix is avaible, this function can be async if needed. + msg.channel.send(JSON.stringify(rolelist.listedroles)); + } +}; From 2575972e85e60f9c3080a4ed3432261fdf0194bb Mon Sep 17 00:00:00 2001 From: Ralph Date: Fri, 27 Oct 2017 01:24:16 -0400 Subject: [PATCH 2/7] Added Config for Rolesetter --- config/default.json.example | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config/default.json.example b/config/default.json.example index c5d4fb5..ba9c47d 100644 --- a/config/default.json.example +++ b/config/default.json.example @@ -16,5 +16,9 @@ "moderation":{ "perms": ["LBRY MODS","LBRY TEAM"], // Roles that have access to all commands. "logchannel": "371620338263523328" // Channel to log the bots moderation.. + }, + "rolelist":{ + "allowedroles": {"Role1":"Role1", "Role2":"Role2"}, + "listedroles": ["Role1","Role2"] } -} \ No newline at end of file +} From 8a230f1639121e24393c8f91121b6196b423770d Mon Sep 17 00:00:00 2001 From: Ralph Date: Fri, 27 Oct 2017 09:53:11 -0400 Subject: [PATCH 3/7] Changed var to let --- bot/modules/rolesetter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bot/modules/rolesetter.js b/bot/modules/rolesetter.js index 832a36d..2d46da6 100644 --- a/bot/modules/rolesetter.js +++ b/bot/modules/rolesetter.js @@ -1,5 +1,5 @@ -var config = require('config'); +let config = require('config'); rolelist = config.get('rolelist'); exports.commands = [ @@ -13,7 +13,7 @@ exports.addrole = { description: 'description of command', 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); + let newrole = msg.guild.roles.find('name', suffix); //var rolecheck = msg.guild.roles; //var rolecheckvar = JSON.parse(rolecheck).find('name', suffix); @@ -46,7 +46,7 @@ exports.delrole = { description: 'description of command', process: function(bot,msg,suffix) { // Here the bot,msg and suffix is avaible, this function can be async if needed. - var oldrole = msg.guild.roles.find('name', suffix); + let oldrole = msg.guild.roles.find('name', suffix); //console.log(oldrole); //console.log('Delrole Event firing.'); //console.log(msg); From ac9c3d814b8d5c3256e19d1d848984e1da4db7b9 Mon Sep 17 00:00:00 2001 From: MSFTserver Date: Fri, 27 Oct 2017 11:49:27 -0700 Subject: [PATCH 4/7] welcome DM bot --- bot/modules/welcome.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 bot/modules/welcome.js diff --git a/bot/modules/welcome.js b/bot/modules/welcome.js new file mode 100644 index 0000000..930a3a2 --- /dev/null +++ b/bot/modules/welcome.js @@ -0,0 +1,36 @@ +exports.custom = [ + "onUserJoin" +] +exports.onUserJoin = function(bot) { + + bot.on('guildMemberAdd', member => { + member.send( + "**Welcome to Lbry Discord!** \n" + + "Please respect everyone in the community \n" + + "1. No begging for Free Coins \n" + + "2. **No Harrasing** other community members this includes any **racist comments** in the server! \n" + + "3. Dont be Afraid to ask questions, please use proper channels when doing so \n" + + " we have dedicated channels like ***#feedback-and-ideas #mining #market-and-trading #random** for your needs \n" + + "4. If you need help please use the channel #help and someone will assist you \n" + + "5. **#general** is to be used for general talk about lbry off-topic stuff find the right channel please \n" + + "**If your here for *Verification* please go to **#verification** channel and post you'd like to be verified and mod will get to you asap, please be patient as we are not up 24/7 to monitor all activity in that channel** \n" + + "\n\n" + + "*NOTE: the platform is in Beta, you may encounter bugs or errors, we are aware of most issues please check our github(https://github.com/lbryio/lbry-app/issues) for issues that you may come across before reoprting it, thanks for your time and patience*" + ); + member.send( + { + "embed": { + "title": "*Click Here for more Info!*", + "description": "[**LBRY**](https://lbry.io) is a protocol providing fully decentralized network for the discovery, distribution, and payment of data. It utilizes the [**LBRY blockchain**](https://lbry.io/what#the-network) as a global namespace and database of digital content. Blockchain entries contain searchable content metadata, identities, and rights and access rules. \n[_**Get the App here**_](https://lbry.io/get)", + "url": "https://lbry.io/what", + "color": 7976557, + "author": { + "name": "What is LBRY?", + "url": "https://lbry.io/what", + "icon_url": "https://i.imgur.com/yWf5USu.png" + } + } + }); +}); + +} From 9e5d676d99249d8031a5d11c51ff2006e4a4ce0a Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Fri, 27 Oct 2017 15:15:13 -0400 Subject: [PATCH 5/7] fix typo --- bot/modules/tipbot.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/modules/tipbot.js b/bot/modules/tipbot.js index 60cd3f2..9ffdc7d 100644 --- a/bot/modules/tipbot.js +++ b/bot/modules/tipbot.js @@ -10,8 +10,8 @@ exports.commands = [ ] exports.tip = { usage: "", - description: 'balance: get your balance\n deposit: get adress for your deposits\n withdraw ADDRESS AMOUNT: withdraw AMOUNT credits to ADDRESS\n : mention a user with @ and then the amount to tip them', + description: 'balance: get your balance\n deposit: get address for your deposits\n withdraw ADDRESS AMOUNT: withdraw AMOUNT credits to ADDRESS\n : mention a user with @ and then the amount to tip them', process: async function(bot,msg,suffix){ return; // Tipping is now handled by the separate tipbot(in branch tipbot_dc), no need to to anything here... } -} \ No newline at end of file +} From f88415edb99dc0394d121ca52f3efcac5033ec6f Mon Sep 17 00:00:00 2001 From: Ralph Date: Fri, 27 Oct 2017 15:54:31 -0400 Subject: [PATCH 6/7] Updates Cleaned up the code, fixed the if function for checking if a role is "Allowed". Created an embed for the !roles command to show the allowed roles people can add. --- bot/modules/rolesetter.js | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/bot/modules/rolesetter.js b/bot/modules/rolesetter.js index 2d46da6..73cd65a 100644 --- a/bot/modules/rolesetter.js +++ b/bot/modules/rolesetter.js @@ -1,5 +1,5 @@ -let config = require('config'); +var config = require('config'); rolelist = config.get('rolelist'); exports.commands = [ @@ -13,7 +13,8 @@ exports.addrole = { description: 'description of command', process: function(bot,msg,suffix){ // Here the bot,msg and suffix is avaible, this function can be async if needed. - let newrole = msg.guild.roles.find('name', suffix); + //amsg.reply(rolelist.allowedroles.includes(suffix)); + var newrole = msg.guild.roles.find('name', suffix); //var rolecheck = msg.guild.roles; //var rolecheckvar = JSON.parse(rolecheck).find('name', suffix); @@ -21,7 +22,7 @@ exports.addrole = { //console.log(rolelist); //console.log(rolelist.allowedroles); //console.log(config.get('allowedroles')); - if (suffix === rolelist.allowedroles.Member || rolelist.allowedroles.Trustee) { + if (rolelist.allowedroles.includes(suffix)) { //console.log('Role is in allowed roles.'); //console.log('Role to add: ' + newrole); if (!msg.member.roles.find('name', suffix)) { @@ -51,10 +52,10 @@ exports.delrole = { //console.log('Delrole Event firing.'); //console.log(msg); //console.log('Printing Suffix! ' + suffix); - if (suffix === rolelist.allowedroles.Member || rolelist.allowedroles.Trustee) { + if (rolelist.allowedroles.includes(suffix)) { if (msg.member.roles.find('name', suffix)) { - msg.member.removeRole(oldrole); - msg.channel.send(msg.member + ' has been removed from the ' + suffix + ' role!') + msg.member.removeRole(oldrole) + .then(msg.channel.send(msg.member + ' has been removed from the ' + suffix + ' role!')); } else { msg.channel.send("You don't seem to have that role! Try adding it first with the addrole command!"); @@ -71,6 +72,29 @@ exports.roles = { description: 'description of command', process: function(bot,msg,suffix){ // Here the bot,msg and suffix is avaible, this function can be async if needed. - msg.channel.send(JSON.stringify(rolelist.listedroles)); + msg.channel.send({embed: { + color: 3447003, + title: "Wunderbot", + description: "You have accessed the rolebot function of Wunderbot!", + fields: [{ + name: "List of roles", + value: buildRoleString(rolelist.allowedroles), + inline: false + }], + footer:{ + icon_url: msg.author.avatarURL, + text: 'Requested by: ' + JSON.stringify(msg.author.username) + } + + }}); + //msg.channel.send(JSON.stringify(rolelist.allowedroles)); } }; + +function buildRoleString(roles) { + let str = ""; + for (let i = 0; i < roles.length; i++) { + str += "`" + roles[i] + "`" + '\n'; + } + return str; +} From 10cadc90026ba81300f2c3afc049837a36083799 Mon Sep 17 00:00:00 2001 From: Ralph Date: Fri, 27 Oct 2017 15:55:35 -0400 Subject: [PATCH 7/7] Updated List Changed the way the rolesetter reads the config to make it easier and less repetitive. --- config/default.json.example | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config/default.json.example b/config/default.json.example index ba9c47d..dd4c564 100644 --- a/config/default.json.example +++ b/config/default.json.example @@ -18,7 +18,6 @@ "logchannel": "371620338263523328" // Channel to log the bots moderation.. }, "rolelist":{ - "allowedroles": {"Role1":"Role1", "Role2":"Role2"}, - "listedroles": ["Role1","Role2"] + "allowedroles": ["Role1","Role2"] } }