From f9896bdd153b09118b83ac86553a113c4749256d Mon Sep 17 00:00:00 2001 From: chris062689 Date: Sun, 15 Jan 2017 12:37:43 -0500 Subject: [PATCH] Added try catch blocks so script execution does not halt. --- server.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/server.js b/server.js index a319ed5..da15354 100644 --- a/server.js +++ b/server.js @@ -73,16 +73,20 @@ client.on('message', message => { logger.info(`${message.author.username} ${message.author} [Channel: ${message.channel}] triggered command: ${message.content}`); message.delete(); - if (cachedModuleType == 'Command') { - cachedModule.command(message); - } else if (cachedModuleType == 'Quote') { - cachedModules['quote.js'].command(message, cachedModule.reply); - } + try { + if (cachedModuleType == 'Command') { + cachedModule.command(message); + } else if (cachedModuleType == 'Quote') { + cachedModules['quote.js'].command(message, cachedModule.reply); + } + } catch (err) { logger.error(err); } - // Check if the command requires a warning. - if (cmd != 'warn' && cachedModule.warn == true) { - cachedModules['warn.js'].command(message); - } + try { + // Check if the command requires a warning. + if (cmd != 'warn' && cachedModule.warn == true) { + cachedModules['warn.js'].command(message); + } + } catch (err) { logger.error(err); } } else { // Not a valid command. } @@ -91,7 +95,9 @@ client.on('message', message => { cachedTriggers.forEach(function(trigger) { if (trigger.roles == undefined || findArray(message.member.roles.map(function(x) { return x.name; }), trigger.roles)) { if (trigger.trigger(message) == true) { - trigger.execute(message); + try { + trigger.execute(message); + } catch (err) { logger.error(err); } } } });