From 399e484c58a1bc88be92898b0592e5270636aca5 Mon Sep 17 00:00:00 2001 From: chris062689 Date: Fri, 7 Apr 2017 19:17:05 -0400 Subject: [PATCH 1/6] Updated ban code for proper logging of username in message. --- commands/ban.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/commands/ban.js b/commands/ban.js index f1fc43d..cbaf640 100644 --- a/commands/ban.js +++ b/commands/ban.js @@ -4,20 +4,20 @@ var data = require('../data.js'); var logger = require('../logging.js'); var UserBan = require('../models/UserBan.js'); -exports.roles = ['Admins', 'Moderators', 'Secret', 'CitraBot']; +exports.roles = ['Admins', 'Moderators', 'CitraBot']; exports.command = function(message) { message.mentions.users.map((user) => { 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.`); - logger.info(`${message.author.toString()} has banned ${user.toString()}.`); - app.logChannel.sendMessage(`${message.author} has banned ${user} [${count} + 1].`); + message.channel.sendMessage(`${user} ${user.username}, You will now be banned from this channel.`); + logger.info(`${message.author.toString()} has banned ${user.toString()} ${user} ${user.username}.`); + app.logChannel.sendMessage(`${message.author} has banned ${user} ${user.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); + app.logChannel.sendMessage(`Error banning ${user} ${user.username}`); + logger.error(`Error banning ${user.toString()} ${user} ${user.username}.`, error); }); data.flushBans(); }); From cf55869bb8ba76077edf3171667d6b1b12ffa71b Mon Sep 17 00:00:00 2001 From: chris062689 Date: Fri, 7 Apr 2017 19:17:19 -0400 Subject: [PATCH 2/6] Updated permissions. Disabled testing command. --- commands/quote.js | 2 +- commands/{testing.js => testing.disabled.js} | 0 commands/warn.js | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) rename commands/{testing.js => testing.disabled.js} (100%) diff --git a/commands/quote.js b/commands/quote.js index acec19b..d3a4ea1 100644 --- a/commands/quote.js +++ b/commands/quote.js @@ -1,7 +1,7 @@ var app = require('../app.js'); var logger = require('../logging.js'); -exports.roles = ['Admins', 'Moderators', 'Secret']; +exports.roles = ['Admins', 'Moderators']; exports.command = function(message, reply) { let replyMessage = 'Hello.'; if (reply == null) { diff --git a/commands/testing.js b/commands/testing.disabled.js similarity index 100% rename from commands/testing.js rename to commands/testing.disabled.js diff --git a/commands/warn.js b/commands/warn.js index 3d8f997..b1468c3 100644 --- a/commands/warn.js +++ b/commands/warn.js @@ -4,7 +4,7 @@ var data = require('../data.js'); var logger = require('../logging.js'); var UserWarning = require('../models/UserWarning.js'); -exports.roles = ['Admins', 'Moderators', 'Secret', 'Helpers']; +exports.roles = ['Admins', 'Moderators']; exports.command = function(message) { message.mentions.users.map((user) => { var count = app.warnings.filter(x => x.id == user.id && !x.cleared).length || 0; @@ -12,7 +12,7 @@ exports.command = function(message) { logger.info(`${message.author.username} ${message.author} has warned ${user.username} ${user} [${count} + 1].`); 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(); From 49755a41829a60418afe504715b5aeb8bf8efdba Mon Sep 17 00:00:00 2001 From: chris062689 Date: Fri, 7 Apr 2017 19:17:55 -0400 Subject: [PATCH 3/6] Added data folder to gitignore. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 3cb3532..7cd615f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Data folder. +data/ + # Logs logs *.log From 6f48e1c379820817462035d674c4148633f8ef40 Mon Sep 17 00:00:00 2001 From: chris062689 Date: Fri, 7 Apr 2017 19:22:57 -0400 Subject: [PATCH 4/6] Check if logdnaKey is defined before attempting to use it. --- logging.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logging.js b/logging.js index a0010e0..0e8b814 100644 --- a/logging.js +++ b/logging.js @@ -19,7 +19,7 @@ var logger = new winston.Logger({ exitOnError: false }); -if (process.env.NODE_ENV == 'production') { +if (process.env.NODE_ENV == 'production' && config.logdnaKey) { // Setup logging for LogDNA cloud logging. logger.add(winston.transports.Logdna, { level: 'info', From 2509bd2179145136596674d29eefe31b60f822b0 Mon Sep 17 00:00:00 2001 From: chris062689 Date: Fri, 7 Apr 2017 19:33:03 -0400 Subject: [PATCH 5/6] Access check to see if the user has privilages to warn after command runs. --- server.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index bd39a41..a51b548 100644 --- a/server.js +++ b/server.js @@ -17,6 +17,10 @@ function findArray(haystack, arr) { }); }; +process.on('unhandledRejection', function onError(err) { + throw err; +}); + client.on('ready', () => { // Initalize app channels. app.logChannel = client.channels.get(config.logChannel); @@ -66,12 +70,19 @@ client.on('message', message => { } } catch (err) { logger.error(err); } + // Warn after running command? try { // Check if the command requires a warning. if (cmd != 'warn' && cachedModule.warn == true) { - cachedModules['warn.js'].command(message); + // Access check to see if the user has privilages to warn. + let warnCommand = cachedModules['warn.js']; + if (findArray(message.member.roles.map(function(x) { return x.name; }), warnCommand.roles)) { + // They are allowed to warn because they are in warn's roles. + warnCommand.command(message); + } } } catch (err) { logger.error(err); } + } else { // Not a valid command. } From af4fb4d2fcf5a8370acbf6ded6ffc414069b8f7b Mon Sep 17 00:00:00 2001 From: chris062689 Date: Fri, 7 Apr 2017 19:36:45 -0400 Subject: [PATCH 6/6] Updated disabled module and trigger code. --- server.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index a51b548..a24bfd4 100644 --- a/server.js +++ b/server.js @@ -106,8 +106,12 @@ cachedModules = []; require("fs").readdirSync('./commands/').forEach(function(file) { // Load the module if it's a script. if (path.extname(file) == '.js') { - logger.info(`Loaded module: ${file}`); - cachedModules[file] = require(`./commands/${file}`); + if (file.includes('.disabled')) { + logger.info(`Did not load disabled module: ${file}`); + } else { + logger.info(`Loaded module: ${file}`); + cachedModules[file] = require(`./commands/${file}`); + } } }); @@ -116,8 +120,12 @@ cachedTriggers = []; require("fs").readdirSync('./triggers/').forEach(function(file) { // Load the trigger if it's a script. if (path.extname(file) == '.js') { - logger.info(`Loaded trigger: ${file}`); - cachedTriggers.push(require(`./triggers/${file}`)); + if (file.includes('.disabled')) { + logger.info(`Did not load disabled trigger: ${file}`); + } else { + logger.info(`Loaded trigger: ${file}`); + cachedTriggers.push(require(`./triggers/${file}`)); + } } });