From 2ce0e67d4b212ed690752019a7626d2012e9482b Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 2 Nov 2013 21:40:10 +0000 Subject: [PATCH] well lets give this a try --- database.js | 26 +++++++++++++++----------- run.js | 3 +-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/database.js b/database.js index 3010140..f2b39cf 100644 --- a/database.js +++ b/database.js @@ -15,19 +15,23 @@ var DatabaseDriver = function(config) { * Connect to or create a new DataBank */ DatabaseDriver.prototype.createDB = function(name, driver, schema, callback) { - var params = { 'schema': schema }; + if(!_.has(this.databanks, name)) { + var params = { 'schema': schema }; - if(driver == 'redis' && _.has(this.config, 'redisPort')) params.port = this.config.redisPort; - if(driver == 'disk') params.dir = 'db'; + if(driver == 'redis' && _.has(this.config, 'redisPort')) params.port = this.config.redisPort; + if(driver == 'disk') params.dir = 'db'; - this.databanks[name] = Databank.get(driver, params); - this.databanks[name].connect({}, function(err) { - if(err) { - console.log('Didn\'t manage to connect to the data source - ' + err); - } else { - callback(this.databanks[name]); - } - }.bind(this)); + this.databanks[name] = Databank.get(driver, params); + this.databanks[name].connect({}, function(err) { + if(err) { + console.log('Didn\'t manage to connect to the data source - ' + err); + } else { + callback(this.databanks[name]); + } + }.bind(this)); + } else { + callback(this.databanks[name]); + } }; exports.DatabaseDriver = DatabaseDriver; diff --git a/run.js b/run.js index 4290f25..5367d5d 100644 --- a/run.js +++ b/run.js @@ -165,6 +165,7 @@ DBot.prototype.reloadModules = function() { delete require.cache[path]; require('./snippets'); + // Clear JSBot listeners and hooks this.instance.removeListeners(); this.instance.clearHooks(); @@ -217,7 +218,6 @@ DBot.prototype.reloadModules = function() { } } - process.nextTick(function() { _.each(moduleNames, function(name) { if(this.status[name] === true) { try { @@ -304,7 +304,6 @@ DBot.prototype.reloadModules = function() { this.modules[module.name] = module; } }.bind(this)); - }.bind(this)); process.nextTick(function() { if(_.has(this.modules, 'web')) this.modules.web.reloadPages();