Merge pull request #230 from lbryio/Coolguy3289-patch-2

Add catch for DMs, @nikooo777 could you update the running version?
This commit is contained in:
filipnyquist 2019-02-20 08:20:43 +01:00 committed by GitHub
commit b6c9a2dd11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
let config = require('config'); let config = require('config');
let botconfig = config.get('bot'); let botconfig = config.get('bot');
let rolelist = config.get('rolelist'); let rolelist = config.get('rolelist');
let inPrivate = require('../helpers.js').inPrivate;
exports.commands = [ exports.commands = [
'addrole', // command that is in this file, every command needs it own export as shown below 'addrole', // command that is in this file, every command needs it own export as shown below
@ -17,36 +18,41 @@ exports.addrole = {
let newrole = msg.guild.roles.find('name', suffix); let newrole = msg.guild.roles.find('name', suffix);
let baserole = msg.guild.roles.find('name', rolelist.baserole); let baserole = msg.guild.roles.find('name', rolelist.baserole);
// Checks if the user put a role in the message. // Checks if the user put a role in the message.
if (suffix) { if (inPrivate(msg)) {
//suffix = suffix.toLowerCase(); msg.channel.send('You can not set roles in DMs! Please go to the Discord server to do this.');
// Checks if the role mentioned in the message is in the allowed roles listed in the wunderbot config. return;
if (rolelist.allowedroles.includes(suffix) || rolelist.baserole.includes(suffix)) { } else {
// Checks if the role even exists in the discord server if (suffix) {
if (newrole !== null) { //suffix = suffix.toLowerCase();
// Checks if the member has the role that they are trying to add // Checks if the role mentioned in the message is in the allowed roles listed in the wunderbot config.
if (!msg.member.roles.find('name', suffix)) { if (rolelist.allowedroles.includes(suffix) || rolelist.baserole.includes(suffix)) {
msg.member.addRole(newrole).then(msg.channel.send(msg.member + ' has been added to the ' + suffix + ' role!')); // Checks if the role even exists in the discord server
if (rolelist.baserole !== ' ') { if (newrole !== null) {
if (baserole !== null) { // Checks if the member has the role that they are trying to add
// Checks if Member has the baserole, and also checks if they just added the baserole if (!msg.member.roles.find('name', suffix)) {
if (!msg.member.roles.find('name', rolelist.baserole) && suffix !== rolelist.baserole) { msg.member.addRole(newrole).then(msg.channel.send(msg.member + ' has been added to the ' + suffix + ' role!'));
msg.member.addRole(baserole).then(msg.channel.send(msg.member + ' has been added to the ' + rolelist.baserole + ' role!')); if (rolelist.baserole !== ' ') {
if (baserole !== null) {
// Checks if Member has the baserole, and also checks if they just added the baserole
if (!msg.member.roles.find('name', rolelist.baserole) && suffix !== 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 + " Role doesn't exist. Please add that role first!");
} }
} else {
msg.channel.send('The ' + rolelist.baserole + " Role 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 { } else {
msg.channel.send('It seems that you already have that role! Try removing it first with the ' + botconfig.prefix + 'delrole command!'); msg.channel.send('The role ' + '`' + suffix + '`' + ' does not exist!');
} }
} else { } else {
msg.channel.send('The role ' + '`' + suffix + '`' + ' does not exist!'); msg.channel.send("That role isn't one you can add yourself to! Please run the " + botconfig.prefix + 'roles command to find out which ones are allowed.');
} }
} else { } else {
msg.channel.send("That role isn't one you can add yourself to! Please run the " + botconfig.prefix + 'roles command to find out which ones are allowed.'); msg.channel.send('Please specify a role. Type ' + botconfig.prefix + 'roles to see which you may add!');
} }
} else {
msg.channel.send('Please specify a role. Type ' + botconfig.prefix + 'roles to see which you may add!');
} }
} }
}; };
@ -57,25 +63,30 @@ exports.delrole = {
// Here in the bot, msg and suffix are available, this function can be async if needed. // Here in the bot, msg and suffix are available, this function can be async if needed.
let oldrole = msg.guild.roles.find('name', suffix); let oldrole = msg.guild.roles.find('name', suffix);
// Checks if the user put a role in the message. // Checks if the user put a role in the message.
if (suffix) { if (inPrivate(msg)) {
// Checks if the role mentioned in the message is in the allowed roles listed in the Wunderbot config. msg.channel.send('You can not set roles in DMs! Please go to the Discord server to do this.');
if (rolelist.allowedroles.includes(suffix)) { return;
// Checks if the role exists in the Discord server } else {
if (oldrole !== null) { if (suffix) {
// Checks if the member has the role that they are trying to add // Checks if the role mentioned in the message is in the allowed roles listed in the Wunderbot config.
if (msg.member.roles.find('name', suffix)) { if (rolelist.allowedroles.includes(suffix)) {
msg.member.removeRole(oldrole).then(msg.channel.send(msg.member + ' has been removed from the ' + suffix + ' role!')); // Checks if the role exists in the Discord server
if (oldrole !== null) {
// Checks if the member has the role that they are trying to add
if (msg.member.roles.find('name', suffix)) {
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 " + botconfig.prefix + 'addrole command!');
}
} else { } else {
msg.channel.send("You don't seem to have that role! Try adding it first with the " + botconfig.prefix + 'addrole command!'); msg.channel.send('The role ' + '`' + suffix + '`' + ' does not exist!');
} }
} else { } else {
msg.channel.send('The role ' + '`' + suffix + '`' + ' does not exist!'); msg.channel.send("That role isn't one you can add yourself to! Please run the " + botconfig.prefix + 'roles command to find out which ones are allowed.');
} }
} else { } else {
msg.channel.send("That role isn't one you can add yourself to! Please run the " + botconfig.prefix + 'roles command to find out which ones are allowed.'); msg.channel.send('Please specify a role. Type ' + botconfig.prefix + 'roles to see which you may add!');
} }
} else {
msg.channel.send('Please specify a role. Type ' + botconfig.prefix + 'roles to see which you may add!');
} }
} }
}; };
@ -83,41 +94,46 @@ exports.roles = {
usage: '', usage: '',
description: 'displays roles you can give yourself', description: 'displays roles you can give yourself',
process: function(bot, msg, suffix) { process: function(bot, msg, suffix) {
// Here in the bot, msg and suffix are available, this function can be async if needed. if (inPrivate(msg)) {
msg.channel.send({ msg.channel.send('You can not set roles in DMs! Please go to the Discord server to do this.');
embed: { return;
color: 3447003, } else {
title: 'Wunderbot', // Here in the bot, msg and suffix are available, this function can be async if needed.
description: 'You have accessed the rolebot function of Wunderbot!', msg.channel.send({
fields: [ embed: {
{ color: 3447003,
name: 'List of roles', title: 'Wunderbot',
value: buildRoleString(rolelist.allowedroles) + '`' + rolelist.baserole + '`', description: 'You have accessed the rolebot function of Wunderbot!',
inline: false fields: [
}, {
{ name: 'List of roles',
name: 'How to add a role to yourself', value: buildRoleString(rolelist.allowedroles) + '`' + rolelist.baserole + '`',
value: '!addrole (role) - Adds a specified role to yourself.\n!addrole International would add the International role.', inline: false
inline: false },
}, {
{ name: 'How to add a role to yourself',
name: 'How to remove a role from yourself', value: '!addrole (role) - Adds a specified role to yourself.\n!addrole International would add the International role.',
value: '!delrole (role) - Removed a specified role from yourself.\n!delrole International would remove the International role.', inline: false
inline: false },
}, {
{ name: 'How to remove a role from yourself',
name: 'NOTE', value: '!delrole (role) - Removed a specified role from yourself.\n!delrole International would remove the International role.',
value: 'The above roles are case sensitive. The LBRYian role will be auto-added when you chose any of the available roles', inline: false
inline: false },
{
name: 'NOTE',
value: 'The above roles are case sensitive. The LBRYian role will be auto-added when you chose any of the available roles',
inline: false
}
],
footer: {
icon_url: msg.author.avatarURL,
text: 'Requested by: ' + JSON.stringify(msg.author.username)
} }
],
footer: {
icon_url: msg.author.avatarURL,
text: 'Requested by: ' + JSON.stringify(msg.author.username)
} }
} });
}); //msg.channel.send(JSON.stringify(rolelist.allowedroles));
//msg.channel.send(JSON.stringify(rolelist.allowedroles)); }
} }
}; };