From 5bb31db42758cd9992854910d29437f284f558cd Mon Sep 17 00:00:00 2001 From: Ralph Date: Fri, 30 Mar 2018 15:49:54 -0400 Subject: [PATCH 01/13] Fix Prettier --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index ed3b349..d338496 100644 --- a/package.json +++ b/package.json @@ -19,11 +19,11 @@ "wget": "^0.0.1" }, "scripts": { - "prettier": "prettier --write '{bot,.}/**/*.{js,json}' --single-quote --print-width 240", + "prettier": "prettier --write * --single-quote --print-width 240", "build": "babel bot -d dist", "prod": "babel bot -d dist & node dist/bot.js", - "lint": "prettier --write '{bot,.}/**/*.{js,json}' --single-quote --print-width 240", - "precommit": "prettier --write '{bot,.}/**/*.{js,json}' --single-quote --print-width 240" + "lint": "prettier --write bot/**/*.js --single-quote --print-width 240", + "precommit": "prettier --write bot/**/*.js --single-quote true --print-width 240" }, "devDependencies": { "husky": "^0.14.3", From fe568ebfb9268c9e60650549d97cbd115afe7ab4 Mon Sep 17 00:00:00 2001 From: Ralph Date: Fri, 30 Mar 2018 15:51:30 -0400 Subject: [PATCH 02/13] Update rolelist to include baserole --- config/default.json.example | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config/default.json.example b/config/default.json.example index 157a104..548816a 100644 --- a/config/default.json.example +++ b/config/default.json.example @@ -80,9 +80,10 @@ "mainchannel": "363050205043621908" // Main Stats Bot channel for directing with help message }, "rolelist": { + "baserole": "Member", "allowedroles": [ - "Reward Scammer", - "Reported Scammer" + "Scammer", + "Spammer" ] }, "claimbot": { From 6db77871d10cc016185701349e083f51ddbdbb8d Mon Sep 17 00:00:00 2001 From: Ralph Date: Fri, 30 Mar 2018 16:07:30 -0400 Subject: [PATCH 03/13] Updated setGame to setActivity (Deprecation) --- bot/bot.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bot/bot.js b/bot/bot.js index dc5d764..5ed3f12 100644 --- a/bot/bot.js +++ b/bot/bot.js @@ -43,7 +43,9 @@ bot.on('ready', function() { console.log('Logged in! Serving in ' + bot.guilds.array().length + ' servers'); require('./plugins.js').init(); console.log('type ' + config.prefix + 'help in Discord for a commands list.'); - bot.user.setGame(config.prefix + 'help'); + bot.user + .setActivity(config.prefix + 'help', { type: 'LISTENING' }) + .catch(console.error); //initialize the claimbot (content bot) claimbot.init(bot); From e693dd55280f8fe15ba4b4cae6d8064eef23ef82 Mon Sep 17 00:00:00 2001 From: Ralph Date: Fri, 30 Mar 2018 17:28:16 -0400 Subject: [PATCH 04/13] Reverted RegEx on Prettier Script --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index d338496..ed3b349 100644 --- a/package.json +++ b/package.json @@ -19,11 +19,11 @@ "wget": "^0.0.1" }, "scripts": { - "prettier": "prettier --write * --single-quote --print-width 240", + "prettier": "prettier --write '{bot,.}/**/*.{js,json}' --single-quote --print-width 240", "build": "babel bot -d dist", "prod": "babel bot -d dist & node dist/bot.js", - "lint": "prettier --write bot/**/*.js --single-quote --print-width 240", - "precommit": "prettier --write bot/**/*.js --single-quote true --print-width 240" + "lint": "prettier --write '{bot,.}/**/*.{js,json}' --single-quote --print-width 240", + "precommit": "prettier --write '{bot,.}/**/*.{js,json}' --single-quote --print-width 240" }, "devDependencies": { "husky": "^0.14.3", From 7a6a9bf748c6192660b131e6a5b49bfe014c2ebd Mon Sep 17 00:00:00 2001 From: Ralph Date: Fri, 30 Mar 2018 17:51:54 -0400 Subject: [PATCH 05/13] 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 06/13] 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!'); } } }; From f77041f69521cd0f239959e20f85a592e130e33b Mon Sep 17 00:00:00 2001 From: MSFTserver Date: Sat, 31 Mar 2018 14:05:12 -0700 Subject: [PATCH 07/13] crash fix for offline and non dm-able --- bot/bot.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bot/bot.js b/bot/bot.js index 5ed3f12..88cd08f 100644 --- a/bot/bot.js +++ b/bot/bot.js @@ -65,7 +65,13 @@ function checkMessageForCommand(msg, isEdit) { if (msg.author.id != bot.user.id && msg.content.startsWith(config.prefix)) { //check if user is Online if (!msg.author.presence.status || msg.author.presence.status == 'offline' || msg.author.presence.status == 'invisible') { - msg.channel.send('Please set your Discord Presence to Online to talk to the Bot!'); + msg.author.send('Please set your Discord Presence to Online to talk to the bot!') + .catch(msg.channel.send(msg.author + + ', Please enable Direct Messages from server members to communicate fully with our bot, ' + + 'it is located in the user setting area under Privacy & Safety tab, ' + + 'select the option allow direct messages from server members') + .then(msg.channel.send('Please set your Discord Presence to Online to talk to the Bot!')) + ); return; } console.log('treating ' + msg.content + ' from UserID:' + msg.author + ' || UserName: ' + msg.author.username + ' as command'); From 11f12120e02ce87b467ca365c59f9087075740d5 Mon Sep 17 00:00:00 2001 From: MSFTserver Date: Sat, 31 Mar 2018 14:20:07 -0700 Subject: [PATCH 08/13] fix bot crashes when not allowed to dm --- bot/modules/welcome.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/bot/modules/welcome.js b/bot/modules/welcome.js index bea5e18..a0780df 100644 --- a/bot/modules/welcome.js +++ b/bot/modules/welcome.js @@ -19,7 +19,10 @@ exports.onUserJoin = function(bot) { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }); + }).catch(console.error).then(bot.channels.get('369896313082478594').send(member + + ', Please enable Direct Messages from server members to communicate fully with our bot, it is located in the user setting area under Privacy & Safety tab, select the option allow direct messages from server members\nSince the bot could not send you our Welcome message please check the posts in <#428634445176766464> and available commands in <#428661678796832768>' + ) + ); member.send({ embed: { description: @@ -36,7 +39,7 @@ exports.onUserJoin = function(bot) { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }); + }).catch(console.error).then(console.log('could not send dm')); member.send({ embed: { description: @@ -53,7 +56,7 @@ exports.onUserJoin = function(bot) { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }); + }).catch(console.error).then(console.log('could not send dm')); member.send({ embed: { title: '*Click here for more info about LBRY!*', @@ -67,7 +70,7 @@ exports.onUserJoin = function(bot) { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }); + }).catch(console.error).then(console.log('could not send dm')); member.send({ embed: { title: '*Click here to see all LBRY Frequently Asked Questions (FAQ)!*', @@ -81,7 +84,7 @@ exports.onUserJoin = function(bot) { icon_url: 'https://spee.ch/8/Id5Qoc3w.png' } } - }); + }).catch(console.error).then(console.log('could not send dm')); member.send({ embed: { title: '*Have you checked out spee.ch yet?!*', @@ -95,7 +98,7 @@ exports.onUserJoin = function(bot) { icon_url: 'http://www.pd4pic.com/images/flag-green-blue-purple-indigo-bars-background.png' } } - }); + }).catch(console.error).then(console.log('could not send dm')); }); }; @@ -134,7 +137,10 @@ exports.welcome = { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }); + }).catch(console.error).then(msg.channel.send(msg.mentions.members.first() + + ', Please enable Direct Messages from server members to communicate fully with our bot, it is located in the user setting area under Privacy & Safety tab, select the option allow direct messages from server members' + ) + ); msg.mentions.members.first().send({ embed: { description: @@ -151,7 +157,7 @@ exports.welcome = { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }); + }).catch(console.error).then(console.log('could not send dm')); msg.mentions.members.first().send({ embed: { description: @@ -168,7 +174,7 @@ exports.welcome = { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }); + }).catch(console.error).then(console.log('could not send dm')); msg.mentions.members.first().send({ embed: { title: '*Click here for more info about LBRY!*', @@ -182,7 +188,7 @@ exports.welcome = { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }); + }).catch(console.error).then(console.log('could not send dm')); msg.mentions.members.first().send({ embed: { title: '*Click here to see all LBRY Frequently Asked Questions (FAQ)!*', @@ -196,7 +202,7 @@ exports.welcome = { icon_url: 'https://spee.ch/8/Id5Qoc3w.png' } } - }); + }).catch(console.error).then(console.log('could not send dm')); msg.mentions.members.first().send({ embed: { title: '*Have you checked out spee.ch yet?!*', @@ -210,6 +216,6 @@ exports.welcome = { icon_url: 'http://www.pd4pic.com/images/flag-green-blue-purple-indigo-bars-background.png' } } - }); + }).catch(console.error).then(console.log('could not send dm')); } }; From 5fb14d97a8a14e9d53961074bcbc8d90fda95717 Mon Sep 17 00:00:00 2001 From: MSFTserver Date: Sat, 31 Mar 2018 14:24:18 -0700 Subject: [PATCH 09/13] last fixes for crashes pm2 will catch and restart --- bot/bot.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bot/bot.js b/bot/bot.js index 88cd08f..6d88785 100644 --- a/bot/bot.js +++ b/bot/bot.js @@ -55,11 +55,21 @@ bot.on('ready', function() { supportbot.init(bot); }); +process.on('unhandledRejection', err => { + console.log('unhandledRejection: ' + err); + process.exit(1); //exit node.js with an error +}); + bot.on('disconnected', function() { console.log('Disconnected!'); process.exit(1); //exit node.js with an error }); +bot.on('error', function(error) { + console.log('error: ' + error); + process.exit(1); //exit node.js with an error +}); + function checkMessageForCommand(msg, isEdit) { //check if message is a command if (msg.author.id != bot.user.id && msg.content.startsWith(config.prefix)) { From 9dea8384fca83d3384d1902398f5e04ebeee9a22 Mon Sep 17 00:00:00 2001 From: MSFTserver Date: Sat, 31 Mar 2018 15:46:34 -0700 Subject: [PATCH 10/13] fix checks --- bot/bot.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/bot/bot.js b/bot/bot.js index 6d88785..ac8a883 100644 --- a/bot/bot.js +++ b/bot/bot.js @@ -76,13 +76,17 @@ function checkMessageForCommand(msg, isEdit) { //check if user is Online if (!msg.author.presence.status || msg.author.presence.status == 'offline' || msg.author.presence.status == 'invisible') { msg.author.send('Please set your Discord Presence to Online to talk to the bot!') - .catch(msg.channel.send(msg.author + - ', Please enable Direct Messages from server members to communicate fully with our bot, ' + - 'it is located in the user setting area under Privacy & Safety tab, ' + - 'select the option allow direct messages from server members') - .then(msg.channel.send('Please set your Discord Presence to Online to talk to the Bot!')) - ); + .catch(function(error) { + msg.channel.send(msg.author + + ', Please enable Direct Messages from server members to communicate fully with our bot, ' + + 'it is located in the user setting area under Privacy & Safety tab, ' + + 'select the option allow direct messages from server members' + ).then(msg.channel.send( + 'Please set your Discord Presence to Online to talk to the Bot!' + ); + ); return; + }); } console.log('treating ' + msg.content + ' from UserID:' + msg.author + ' || UserName: ' + msg.author.username + ' as command'); var cmdTxt = msg.content.split(' ')[0].substring(config.prefix.length); From 5198918ed4d53fd9501f46a287ff8c6406521c43 Mon Sep 17 00:00:00 2001 From: MSFTserver Date: Sat, 31 Mar 2018 15:51:26 -0700 Subject: [PATCH 11/13] fix checks --- bot/modules/welcome.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/bot/modules/welcome.js b/bot/modules/welcome.js index a0780df..3f0637d 100644 --- a/bot/modules/welcome.js +++ b/bot/modules/welcome.js @@ -19,10 +19,11 @@ exports.onUserJoin = function(bot) { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }).catch(console.error).then(bot.channels.get('369896313082478594').send(member + - ', Please enable Direct Messages from server members to communicate fully with our bot, it is located in the user setting area under Privacy & Safety tab, select the option allow direct messages from server members\nSince the bot could not send you our Welcome message please check the posts in <#428634445176766464> and available commands in <#428661678796832768>' + }).catch(function(error) { + bot.channels.get('369896313082478594').send(member + + ', Please enable Direct Messages from server members to communicate fully with our bot, it is located in the user setting area under Privacy & Safety tab, select the option allow direct messages from server members\nSince the bot could not send you our Welcome message please check the posts in <#428634445176766464> and available commands in <#428661678796832768>' ) - ); + }); member.send({ embed: { description: @@ -39,7 +40,7 @@ exports.onUserJoin = function(bot) { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }).catch(console.error).then(console.log('could not send dm')); + }).catch(function(error) {console.log('could not send dm')}); member.send({ embed: { description: @@ -56,7 +57,7 @@ exports.onUserJoin = function(bot) { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }).catch(console.error).then(console.log('could not send dm')); + }).catch(function(error) {console.log('could not send dm')}); member.send({ embed: { title: '*Click here for more info about LBRY!*', @@ -70,7 +71,7 @@ exports.onUserJoin = function(bot) { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }).catch(console.error).then(console.log('could not send dm')); + }).catch(function(error) {console.log('could not send dm')}); member.send({ embed: { title: '*Click here to see all LBRY Frequently Asked Questions (FAQ)!*', @@ -84,7 +85,7 @@ exports.onUserJoin = function(bot) { icon_url: 'https://spee.ch/8/Id5Qoc3w.png' } } - }).catch(console.error).then(console.log('could not send dm')); + }).catch(function(error) {console.log('could not send dm')}); member.send({ embed: { title: '*Have you checked out spee.ch yet?!*', @@ -98,7 +99,7 @@ exports.onUserJoin = function(bot) { icon_url: 'http://www.pd4pic.com/images/flag-green-blue-purple-indigo-bars-background.png' } } - }).catch(console.error).then(console.log('could not send dm')); + }).catch(function(error) {console.log('could not send dm')}); }); }; @@ -137,10 +138,11 @@ exports.welcome = { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }).catch(console.error).then(msg.channel.send(msg.mentions.members.first() + + }).catch(function(error) { + msg.channel.send(msg.mentions.members.first() + ', Please enable Direct Messages from server members to communicate fully with our bot, it is located in the user setting area under Privacy & Safety tab, select the option allow direct messages from server members' ) - ); + }); msg.mentions.members.first().send({ embed: { description: @@ -157,7 +159,7 @@ exports.welcome = { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }).catch(console.error).then(console.log('could not send dm')); + }).catch(function(error) {console.log('could not send dm')}); msg.mentions.members.first().send({ embed: { description: @@ -174,7 +176,7 @@ exports.welcome = { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }).catch(console.error).then(console.log('could not send dm')); + }).catch(function(error) {console.log('could not send dm')}); msg.mentions.members.first().send({ embed: { title: '*Click here for more info about LBRY!*', @@ -188,7 +190,7 @@ exports.welcome = { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }).catch(console.error).then(console.log('could not send dm')); + }).catch(function(error) {console.log('could not send dm')}); msg.mentions.members.first().send({ embed: { title: '*Click here to see all LBRY Frequently Asked Questions (FAQ)!*', @@ -216,6 +218,6 @@ exports.welcome = { icon_url: 'http://www.pd4pic.com/images/flag-green-blue-purple-indigo-bars-background.png' } } - }).catch(console.error).then(console.log('could not send dm')); + }).catch(function(error) {console.log('could not send dm')}); } }; From 1f92b7b6637a1b75d4c6f8ab105a25cdfed8aa51 Mon Sep 17 00:00:00 2001 From: MSFTserver Date: Sat, 31 Mar 2018 16:14:13 -0700 Subject: [PATCH 12/13] move treating command moves treating command message down to valid command to avoid logging all messages with activator ! --- bot/bot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/bot.js b/bot/bot.js index ac8a883..4d6cb6d 100644 --- a/bot/bot.js +++ b/bot/bot.js @@ -88,7 +88,6 @@ function checkMessageForCommand(msg, isEdit) { return; }); } - console.log('treating ' + msg.content + ' from UserID:' + msg.author + ' || UserName: ' + msg.author.username + ' as command'); var cmdTxt = msg.content.split(' ')[0].substring(config.prefix.length); var suffix = msg.content.substring(cmdTxt.length + config.prefix.length + 1); //add one for the ! and one for the space if (msg.isMentioned(bot.user)) { @@ -166,6 +165,7 @@ function checkMessageForCommand(msg, isEdit) { } } else if (cmd) { // Add permission check here later on ;) + console.log('treating ' + msg.content + ' from UserID:' + msg.author + ' || UserName: ' + msg.author.username + ' as command'); try { cmd.process(bot, msg, suffix, isEdit); } catch (e) { From 0d2d2dc2700d5d8f22808eb5d76877280de19bb1 Mon Sep 17 00:00:00 2001 From: Ralph Date: Mon, 2 Apr 2018 16:34:55 -0400 Subject: [PATCH 13/13] Changed var to let --- bot/modules/rolesetter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/modules/rolesetter.js b/bot/modules/rolesetter.js index 9bc7170..4f6d141 100644 --- a/bot/modules/rolesetter.js +++ b/bot/modules/rolesetter.js @@ -13,8 +13,8 @@ exports.addrole = { description: 'Adds you to specified role', 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); + let newrole = msg.guild.roles.find('name', suffix); + let baserole = msg.guild.roles.find('name', rolelist.baserole); // Checks if the user put a role in the message. if (suffix) {