Use arrow functions, code cleanup.

This commit is contained in:
chris062689 2016-12-31 00:48:39 -05:00
parent ab25b2599c
commit 2dbe3421af
6 changed files with 32 additions and 43 deletions

View File

@ -7,22 +7,18 @@ var UserBan = require('../models/UserBan.js');
exports.roles = ['Admins', 'Moderators', 'Secret', 'CitraBot']; exports.roles = ['Admins', 'Moderators', 'Secret', 'CitraBot'];
exports.command = function(message) { exports.command = function(message) {
message.mentions.users.map((user) => { 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) { message.channel.sendMessage(`${user} You will now be banned from this channel.`);
logger.error('Error sending #admin-log message.', error); logger.info(`${message.author.toString()} has banned ${user.toString()}.`);
}); app.logChannel.sendMessage(`${message.author} has banned ${user} [${count} + 1].`);
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);
});
app.bans.push(new UserBan(user.id, user.username, message.author.id, message.author.username, count)); 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(); data.flushBans();
}); });
} }

View File

@ -5,14 +5,13 @@ var logger = require('../logging.js');
exports.roles = ['Admins', 'Moderators']; exports.roles = ['Admins', 'Moderators'];
exports.command = function(message) { exports.command = function(message) {
message.mentions.users.map((user) => { 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;
count.forEach(function(warning) {
warning.cleared = true;
});
count.forEach(warning => warning.cleared = true);
data.flushWarnings(); data.flushWarnings();
message.channel.sendMessage(`${user}, your warnings have been cleared.`); 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}].`);
}); });
} }

View File

@ -4,10 +4,12 @@ var logger = require('../logging.js');
exports.roles = ['Admins', 'Moderators', 'Secret']; exports.roles = ['Admins', 'Moderators', 'Secret'];
exports.command = function(message, reply) { exports.command = function(message, reply) {
let replyMessage = 'Hello.'; let replyMessage = 'Hello.';
if (reply == null) { replyMessage = message.content.substr(message.content.indexOf(' ') + 1); } if (reply == null) {
else { replyMessage = `${message.mentions.users.map(function (user) { return `${user}`; })} ${reply}`; } replyMessage = message.content.substr(message.content.indexOf(' ') + 1);
}
else {
replyMessage = `${message.mentions.users.map(user => `${user}`)} ${reply}`;
}
message.channel.sendMessage(replyMessage).catch(function (error) { message.channel.sendMessage(replyMessage);
logger.error('Unable to send reply message to quote.', error);
});
} }

View File

@ -2,14 +2,14 @@ var app = require('../app.js');
var logger = require('../logging.js'); var logger = require('../logging.js');
exports.command = function(message) { exports.command = function(message) {
var roleId = '254036987508424714'; var role = '254036987508424714';
var alreadyJoined = app.guild.roles.get(roleId).members.find(function(member) { return member.id == message.member.id }); var alreadyJoined = app.guild.roles.get(role).members.find(member => member.id == message.member.id);
if (alreadyJoined != null) { if (alreadyJoined != null) {
message.member.removeRole(roleId); message.member.removeRole(role);
message.reply('You are no longer part of the testing group.'); message.reply('You are no longer part of the testing group.');
} else { } else {
message.member.addRole(roleId); message.member.addRole(role);
message.reply('You are now part of the testing group.'); message.reply('You are now part of the testing group.');
} }
} }

View File

@ -7,16 +7,11 @@ var UserWarning = require('../models/UserWarning.js');
exports.roles = ['Admins', 'Moderators', 'Secret', 'Helpers']; exports.roles = ['Admins', 'Moderators', 'Secret', 'Helpers'];
exports.command = function(message) { exports.command = function(message) {
message.mentions.users.map((user) => { 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 have been warned. Additional infractions may result in a ban.`);
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);
});
logger.info(`${message.author.username} ${message.author} has warned ${user.username} ${user} [${count} + 1].`); 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) { app.logChannel.sendMessage(`${message.author} has warned ${user} [${count} + 1].`);
logger.error('Error sending #admin-log message.', error);
});
app.warnings.push(new UserWarning(user.id, user.username, message.author.id, message.author.username, count)); app.warnings.push(new UserWarning(user.id, user.username, message.author.id, message.author.username, count));
data.flushWarnings(); data.flushWarnings();

View File

@ -3,10 +3,7 @@ var logger = require('../logging.js');
exports.command = function(message) { exports.command = function(message) {
message.mentions.users.map((user) => { 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 have ${count} warnings.`);
message.channel.sendMessage(`${user}, you have ${count} warnings.`).catch(function (error) {
logger.error('Error sending #admin-log message.', error);
});
}); });
} }