Merge pull request #153 from Coolguy3289/patch-4

Updates to Wunderbot
This commit is contained in:
filipnyquist 2018-04-02 22:36:22 +02:00 committed by GitHub
commit 12776df4af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 16 deletions

View file

@ -43,7 +43,9 @@ bot.on('ready', function() {
console.log('Logged in! Serving in ' + bot.guilds.array().length + ' servers'); console.log('Logged in! Serving in ' + bot.guilds.array().length + ' servers');
require('./plugins.js').init(); require('./plugins.js').init();
console.log('type ' + config.prefix + 'help in Discord for a commands list.'); 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) //initialize the claimbot (content bot)
claimbot.init(bot); claimbot.init(bot);
@ -53,20 +55,39 @@ bot.on('ready', function() {
supportbot.init(bot); supportbot.init(bot);
}); });
process.on('unhandledRejection', err => {
console.log('unhandledRejection: ' + err);
process.exit(1); //exit node.js with an error
});
bot.on('disconnected', function() { bot.on('disconnected', function() {
console.log('Disconnected!'); console.log('Disconnected!');
process.exit(1); //exit node.js with an error 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) { function checkMessageForCommand(msg, isEdit) {
//check if message is a command //check if message is a command
if (msg.author.id != bot.user.id && msg.content.startsWith(config.prefix)) { if (msg.author.id != bot.user.id && msg.content.startsWith(config.prefix)) {
//check if user is Online //check if user is Online
if (!msg.author.presence.status || msg.author.presence.status == 'offline' || msg.author.presence.status == 'invisible') { 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; 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 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 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)) { if (msg.isMentioned(bot.user)) {
@ -144,6 +165,7 @@ function checkMessageForCommand(msg, isEdit) {
} }
} else if (cmd) { } else if (cmd) {
// Add permission check here later on ;) // Add permission check here later on ;)
console.log('treating ' + msg.content + ' from UserID:' + msg.author + ' || UserName: ' + msg.author.username + ' as command');
try { try {
cmd.process(bot, msg, suffix, isEdit); cmd.process(bot, msg, suffix, isEdit);
} catch (e) { } catch (e) {

View file

@ -13,12 +13,31 @@ exports.addrole = {
description: 'Adds you to specified role', description: 'Adds you to specified role',
process: function(bot, msg, suffix) { process: function(bot, msg, suffix) {
// Here the bot,msg and suffix is avaible, this function can be async if needed. // 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. // Checks if the user put a role in the message.
if (suffix) { if (suffix) {
// Checks if the role mentioned in the message is in the allowed roles listed in the wunderbot config. // Checks if the role mentioned in the message is in the allowed roles listed in the wunderbot config.
if (rolelist.allowedroles.includes(suffix)) { 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 // Checks if the role even exists in the discord server
if (newrole !== null) { if (newrole !== null) {
// Checks if the member has the role that they are trying to add // Checks if the member has the role that they are trying to add
@ -82,6 +101,16 @@ exports.roles = {
name: 'List of roles', name: 'List of roles',
value: buildRoleString(rolelist.allowedroles), value: buildRoleString(rolelist.allowedroles),
inline: false 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: { footer: {

View file

@ -19,6 +19,10 @@ exports.onUserJoin = function(bot) {
icon_url: 'https://i.imgur.com/yWf5USu.png' 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({ member.send({
embed: { embed: {
@ -36,7 +40,7 @@ exports.onUserJoin = function(bot) {
icon_url: 'https://i.imgur.com/yWf5USu.png' icon_url: 'https://i.imgur.com/yWf5USu.png'
} }
} }
}); }).catch(function(error) {console.log('could not send dm')});
member.send({ member.send({
embed: { embed: {
description: description:
@ -53,7 +57,7 @@ exports.onUserJoin = function(bot) {
icon_url: 'https://i.imgur.com/yWf5USu.png' icon_url: 'https://i.imgur.com/yWf5USu.png'
} }
} }
}); }).catch(function(error) {console.log('could not send dm')});
member.send({ member.send({
embed: { embed: {
title: '*Click here for more info about LBRY!*', title: '*Click here for more info about LBRY!*',
@ -67,7 +71,7 @@ exports.onUserJoin = function(bot) {
icon_url: 'https://i.imgur.com/yWf5USu.png' icon_url: 'https://i.imgur.com/yWf5USu.png'
} }
} }
}); }).catch(function(error) {console.log('could not send dm')});
member.send({ member.send({
embed: { embed: {
title: '*Click here to see all LBRY Frequently Asked Questions (FAQ)!*', 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' icon_url: 'https://spee.ch/8/Id5Qoc3w.png'
} }
} }
}); }).catch(function(error) {console.log('could not send dm')});
member.send({ member.send({
embed: { embed: {
title: '*Have you checked out spee.ch yet?!*', 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' 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' 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({ msg.mentions.members.first().send({
embed: { embed: {
@ -151,7 +159,7 @@ exports.welcome = {
icon_url: 'https://i.imgur.com/yWf5USu.png' icon_url: 'https://i.imgur.com/yWf5USu.png'
} }
} }
}); }).catch(function(error) {console.log('could not send dm')});
msg.mentions.members.first().send({ msg.mentions.members.first().send({
embed: { embed: {
description: description:
@ -168,7 +176,7 @@ exports.welcome = {
icon_url: 'https://i.imgur.com/yWf5USu.png' icon_url: 'https://i.imgur.com/yWf5USu.png'
} }
} }
}); }).catch(function(error) {console.log('could not send dm')});
msg.mentions.members.first().send({ msg.mentions.members.first().send({
embed: { embed: {
title: '*Click here for more info about LBRY!*', title: '*Click here for more info about LBRY!*',
@ -182,7 +190,7 @@ exports.welcome = {
icon_url: 'https://i.imgur.com/yWf5USu.png' icon_url: 'https://i.imgur.com/yWf5USu.png'
} }
} }
}); }).catch(function(error) {console.log('could not send dm')});
msg.mentions.members.first().send({ msg.mentions.members.first().send({
embed: { embed: {
title: '*Click here to see all LBRY Frequently Asked Questions (FAQ)!*', 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' icon_url: 'https://spee.ch/8/Id5Qoc3w.png'
} }
} }
}); }).catch(console.error).then(console.log('could not send dm'));
msg.mentions.members.first().send({ msg.mentions.members.first().send({
embed: { embed: {
title: '*Have you checked out spee.ch yet?!*', 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' icon_url: 'http://www.pd4pic.com/images/flag-green-blue-purple-indigo-bars-background.png'
} }
} }
}); }).catch(function(error) {console.log('could not send dm')});
} }
}; };

View file

@ -80,9 +80,10 @@
"mainchannel": "363050205043621908" // Main Stats Bot channel for directing with help message "mainchannel": "363050205043621908" // Main Stats Bot channel for directing with help message
}, },
"rolelist": { "rolelist": {
"baserole": "Member",
"allowedroles": [ "allowedroles": [
"Reward Scammer", "Scammer",
"Reported Scammer" "Spammer"
] ]
}, },
"claimbot": { "claimbot": {