From cd6211fb7df5c326c7cfbca4d8d98a974aa293c5 Mon Sep 17 00:00:00 2001 From: chris062689 Date: Thu, 30 Mar 2017 21:17:21 -0400 Subject: [PATCH 1/2] Moved caching of modules and reading data outside of client.on.ready due to reconnect issues duplicating triggers. --- server.js | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/server.js b/server.js index 49ebc7b..38fb0b2 100644 --- a/server.js +++ b/server.js @@ -18,34 +18,11 @@ function findArray(haystack, arr) { }; client.on('ready', () => { - - // Cache all command modules. - 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}`); - } - }); - - // Cache all triggers. - 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}`)); - } - }); - // Initalize app channels. app.logChannel = client.channels.get(config.logChannel); app.guild = app.logChannel.guild; - data.readWarnings(); - data.readBans(); - - logger.info('Startup complete. Bot is now online and connected to server.'); - // app.logChannel.sendMessage(`Startup complete.`); + logger.info('Bot is now online and connected to server.'); }); client.on('message', message => { @@ -110,7 +87,28 @@ client.on('message', message => { } }); } - }); +// Cache all command modules. +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}`); + } +}); + +// Cache all triggers. +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}`)); + } +}); + +data.readWarnings(); +data.readBans(); +logger.info('Startup completed.'); + client.login(config.clientLoginToken); From 2a4a0d689f3cacc72e8a342a72fd4d3ba9fcfe91 Mon Sep 17 00:00:00 2001 From: chris062689 Date: Thu, 30 Mar 2017 21:18:23 -0400 Subject: [PATCH 2/2] Clear out arrays before caching. --- server.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server.js b/server.js index 38fb0b2..6a7661b 100644 --- a/server.js +++ b/server.js @@ -90,6 +90,7 @@ client.on('message', message => { }); // Cache all command modules. +cachedModules = []; require("fs").readdirSync('./commands/').forEach(function(file) { // Load the module if it's a script. if (path.extname(file) == '.js') { @@ -99,6 +100,7 @@ require("fs").readdirSync('./commands/').forEach(function(file) { }); // Cache all triggers. +cachedTriggers = []; require("fs").readdirSync('./triggers/').forEach(function(file) { // Load the trigger if it's a script. if (path.extname(file) == '.js') {