diff --git a/.gitignore b/.gitignore index 3cb3532..7cd615f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Data folder. +data/ + # Logs logs *.log 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(); }); 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(); 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', diff --git a/server.js b/server.js index bd39a41..a24bfd4 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. } @@ -95,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}`); + } } }); @@ -105,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}`)); + } } });