From 2dbe3421afdfbef3a8a28de4c89c7cd0256af00b Mon Sep 17 00:00:00 2001 From: chris062689 Date: Sat, 31 Dec 2016 00:48:39 -0500 Subject: [PATCH] Use arrow functions, code cleanup. --- commands/ban.js | 22 +++++++++------------- commands/clearWarnings.js | 11 +++++------ commands/quote.js | 12 +++++++----- commands/testing.js | 10 +++++----- commands/warn.js | 13 ++++--------- commands/warnings.js | 7 ++----- 6 files changed, 32 insertions(+), 43 deletions(-) diff --git a/commands/ban.js b/commands/ban.js index c96dcd4..f1fc43d 100644 --- a/commands/ban.js +++ b/commands/ban.js @@ -7,22 +7,18 @@ var UserBan = require('../models/UserBan.js'); exports.roles = ['Admins', 'Moderators', 'Secret', 'CitraBot']; exports.command = function(message) { message.mentions.users.map((user) => { - var count = app.warnings.filter(function(x) { return x.id == user.id && !x.cleared }).length || 0; + var count = app.warnings.filter(x => x.id == user.id && !x.cleared).length || 0; - message.channel.sendMessage(`${user} You will now be banned from this channel.`).catch(function (error) { - logger.error('Error sending #admin-log message.', error); - }); - - logger.info(`${message.author.username} ${message.author} has banned ${user.username} ${user}.`); - app.logChannel.sendMessage(`${message.author} has banned ${user} [${count} + 1].`).catch(function (error) { - logger.error('Error sending #admin-log message.', error); - }); - - message.guild.member(user).ban().catch(function (error) { - logger.error(`Error banning ${user.username} ${user.id}.`, error); - }); + message.channel.sendMessage(`${user} You will now be banned from this channel.`); + logger.info(`${message.author.toString()} has banned ${user.toString()}.`); + app.logChannel.sendMessage(`${message.author} has banned ${user} [${count} + 1].`); app.bans.push(new UserBan(user.id, user.username, message.author.id, message.author.username, count)); + + message.guild.member(user).ban().catch(function (error) { + app.logChannel.sendMessage(`Error banning ${user.toString()}`); + logger.error(`Error banning ${user.toString()}.`, error); + }); data.flushBans(); }); } diff --git a/commands/clearWarnings.js b/commands/clearWarnings.js index cd86628..f81935b 100644 --- a/commands/clearWarnings.js +++ b/commands/clearWarnings.js @@ -5,14 +5,13 @@ var logger = require('../logging.js'); exports.roles = ['Admins', 'Moderators']; exports.command = function(message) { message.mentions.users.map((user) => { - var count = app.warnings.filter(function(x) { return x.id == user.id && !x.cleared }).length || 0; - count.forEach(function(warning) { - warning.cleared = true; - }); + var count = app.warnings.filter(x => x.id == user.id && !x.cleared).length || 0; + count.forEach(warning => warning.cleared = true); data.flushWarnings(); - + message.channel.sendMessage(`${user}, your warnings have been cleared.`); - app.logChannel.sendMessage(`${message.author} has cleared all warnings for ${user} [${count}].`); + logger.info(`${message.author.toString()} has cleared all warnings for ${user.toString()} [${count}].`); + app.logChannel.sendMessage(`${message.author.toString()} has cleared all warnings for ${user.toString()} [${count}].`); }); } diff --git a/commands/quote.js b/commands/quote.js index b7079ac..acec19b 100644 --- a/commands/quote.js +++ b/commands/quote.js @@ -4,10 +4,12 @@ var logger = require('../logging.js'); exports.roles = ['Admins', 'Moderators', 'Secret']; exports.command = function(message, reply) { let replyMessage = 'Hello.'; - if (reply == null) { replyMessage = message.content.substr(message.content.indexOf(' ') + 1); } - else { replyMessage = `${message.mentions.users.map(function (user) { return `${user}`; })} ${reply}`; } + if (reply == null) { + replyMessage = message.content.substr(message.content.indexOf(' ') + 1); + } + else { + replyMessage = `${message.mentions.users.map(user => `${user}`)} ${reply}`; + } - message.channel.sendMessage(replyMessage).catch(function (error) { - logger.error('Unable to send reply message to quote.', error); - }); + message.channel.sendMessage(replyMessage); } diff --git a/commands/testing.js b/commands/testing.js index 0f7a69d..72d00ed 100644 --- a/commands/testing.js +++ b/commands/testing.js @@ -2,14 +2,14 @@ var app = require('../app.js'); var logger = require('../logging.js'); exports.command = function(message) { - var roleId = '254036987508424714'; - var alreadyJoined = app.guild.roles.get(roleId).members.find(function(member) { return member.id == message.member.id }); - + var role = '254036987508424714'; + var alreadyJoined = app.guild.roles.get(role).members.find(member => member.id == message.member.id); + if (alreadyJoined != null) { - message.member.removeRole(roleId); + message.member.removeRole(role); message.reply('You are no longer part of the testing group.'); } else { - message.member.addRole(roleId); + message.member.addRole(role); message.reply('You are now part of the testing group.'); } } diff --git a/commands/warn.js b/commands/warn.js index db32e24..3d8f997 100644 --- a/commands/warn.js +++ b/commands/warn.js @@ -7,17 +7,12 @@ var UserWarning = require('../models/UserWarning.js'); exports.roles = ['Admins', 'Moderators', 'Secret', 'Helpers']; exports.command = function(message) { message.mentions.users.map((user) => { - var count = app.warnings.filter(function(x) { return x.id == user.id && !x.cleared }).length || 0; - - message.channel.sendMessage(`${user} You have been warned. Additional infractions may result in a ban.`).catch(function (error) { - logger.error('Error sending #admin-log message.', error); - }); + var count = app.warnings.filter(x => x.id == user.id && !x.cleared).length || 0; + message.channel.sendMessage(`${user} You have been warned. Additional infractions may result in a ban.`); logger.info(`${message.author.username} ${message.author} has warned ${user.username} ${user} [${count} + 1].`); - app.logChannel.sendMessage(`${message.author} has warned ${user} [${count} + 1].`).catch(function (error) { - logger.error('Error sending #admin-log message.', error); - }); - + app.logChannel.sendMessage(`${message.author} has warned ${user} [${count} + 1].`); + app.warnings.push(new UserWarning(user.id, user.username, message.author.id, message.author.username, count)); data.flushWarnings(); diff --git a/commands/warnings.js b/commands/warnings.js index bba3072..ecd03ec 100644 --- a/commands/warnings.js +++ b/commands/warnings.js @@ -3,10 +3,7 @@ var logger = require('../logging.js'); exports.command = function(message) { message.mentions.users.map((user) => { - var count = app.warnings.filter(function(x) { return x.id == user.id && !x.cleared }).length || 0; - - message.channel.sendMessage(`${user}, you have ${count} warnings.`).catch(function (error) { - logger.error('Error sending #admin-log message.', error); - }); + var count = app.warnings.filter(x => x.id == user.id && !x.cleared).length || 0; + message.channel.sendMessage(`${user}, you have ${count} warnings.`); }); }