Added try catch blocks so script execution does not halt.

This commit is contained in:
chris062689 2017-01-15 12:37:43 -05:00
parent e2ee403ee2
commit f9896bdd15
1 changed files with 16 additions and 10 deletions

View File

@ -73,16 +73,20 @@ client.on('message', message => {
logger.info(`${message.author.username} ${message.author} [Channel: ${message.channel}] triggered command: ${message.content}`); logger.info(`${message.author.username} ${message.author} [Channel: ${message.channel}] triggered command: ${message.content}`);
message.delete(); message.delete();
try {
if (cachedModuleType == 'Command') { if (cachedModuleType == 'Command') {
cachedModule.command(message); cachedModule.command(message);
} else if (cachedModuleType == 'Quote') { } else if (cachedModuleType == 'Quote') {
cachedModules['quote.js'].command(message, cachedModule.reply); cachedModules['quote.js'].command(message, cachedModule.reply);
} }
} catch (err) { logger.error(err); }
try {
// Check if the command requires a warning. // Check if the command requires a warning.
if (cmd != 'warn' && cachedModule.warn == true) { if (cmd != 'warn' && cachedModule.warn == true) {
cachedModules['warn.js'].command(message); cachedModules['warn.js'].command(message);
} }
} catch (err) { logger.error(err); }
} else { } else {
// Not a valid command. // Not a valid command.
} }
@ -91,7 +95,9 @@ client.on('message', message => {
cachedTriggers.forEach(function(trigger) { cachedTriggers.forEach(function(trigger) {
if (trigger.roles == undefined || findArray(message.member.roles.map(function(x) { return x.name; }), trigger.roles)) { if (trigger.roles == undefined || findArray(message.member.roles.map(function(x) { return x.name; }), trigger.roles)) {
if (trigger.trigger(message) == true) { if (trigger.trigger(message) == true) {
try {
trigger.execute(message); trigger.execute(message);
} catch (err) { logger.error(err); }
} }
} }
}); });