diff --git a/bot/bot.js b/bot/bot.js index dc5d764..4d6cb6d 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); @@ -53,20 +55,39 @@ 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)) { //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(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); 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)) { @@ -144,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) { diff --git a/bot/modules/rolesetter.js b/bot/modules/rolesetter.js index e7f7a64..4f6d141 100644 --- a/bot/modules/rolesetter.js +++ b/bot/modules/rolesetter.js @@ -13,12 +13,31 @@ 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); + 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) { // 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 @@ -82,6 +101,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: { diff --git a/bot/modules/welcome.js b/bot/modules/welcome.js index bea5e18..3f0637d 100644 --- a/bot/modules/welcome.js +++ b/bot/modules/welcome.js @@ -19,6 +19,10 @@ exports.onUserJoin = function(bot) { icon_url: 'https://i.imgur.com/yWf5USu.png' } } + }).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: { @@ -36,7 +40,7 @@ exports.onUserJoin = function(bot) { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }); + }).catch(function(error) {console.log('could not send dm')}); member.send({ embed: { description: @@ -53,7 +57,7 @@ exports.onUserJoin = function(bot) { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }); + }).catch(function(error) {console.log('could not send dm')}); member.send({ embed: { title: '*Click here for more info about LBRY!*', @@ -67,7 +71,7 @@ exports.onUserJoin = function(bot) { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }); + }).catch(function(error) {console.log('could not send dm')}); member.send({ embed: { title: '*Click here to see all LBRY Frequently Asked Questions (FAQ)!*', @@ -81,7 +85,7 @@ exports.onUserJoin = function(bot) { icon_url: 'https://spee.ch/8/Id5Qoc3w.png' } } - }); + }).catch(function(error) {console.log('could not send dm')}); member.send({ embed: { title: '*Have you checked out spee.ch yet?!*', @@ -95,7 +99,7 @@ exports.onUserJoin = function(bot) { icon_url: 'http://www.pd4pic.com/images/flag-green-blue-purple-indigo-bars-background.png' } } - }); + }).catch(function(error) {console.log('could not send dm')}); }); }; @@ -134,6 +138,10 @@ exports.welcome = { icon_url: 'https://i.imgur.com/yWf5USu.png' } } + }).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: { @@ -151,7 +159,7 @@ exports.welcome = { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }); + }).catch(function(error) {console.log('could not send dm')}); msg.mentions.members.first().send({ embed: { description: @@ -168,7 +176,7 @@ exports.welcome = { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }); + }).catch(function(error) {console.log('could not send dm')}); msg.mentions.members.first().send({ embed: { title: '*Click here for more info about LBRY!*', @@ -182,7 +190,7 @@ exports.welcome = { icon_url: 'https://i.imgur.com/yWf5USu.png' } } - }); + }).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)!*', @@ -196,7 +204,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 +218,6 @@ exports.welcome = { icon_url: 'http://www.pd4pic.com/images/flag-green-blue-purple-indigo-bars-background.png' } } - }); + }).catch(function(error) {console.log('could not send dm')}); } }; 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": {