Merge pull request #11 from chris062689/master

Round of Code Fixes
This commit is contained in:
Christopher J. Gilbert 2017-04-07 19:38:07 -04:00 committed by GitHub
commit 0429aed636
7 changed files with 37 additions and 15 deletions

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
# Data folder.
data/
# Logs
logs
*.log

View File

@ -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();
});

View File

@ -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) {

View File

@ -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();

View File

@ -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',

View File

@ -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}`));
}
}
});