From 8e8953999d1ff57e78954315fd2c804c43153420 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 22 Apr 2013 14:22:35 +0000 Subject: [PATCH] Various database branch fixes [#331]: * Admin module doesn't try to use reload string when it's not there. * Fix dent event hookin * Fix quote retrieval (two ~q definitions and no false check before interpolate) * Change databankerised modules to use redis for testing --- modules/admin/admin.js | 1 + modules/admin/commands.js | 2 +- modules/dent/config.json | 2 +- modules/dent/dent.js | 2 +- modules/ignore/config.json | 2 +- modules/link/config.json | 2 +- modules/poll/config.json | 2 +- modules/quotes/commands.js | 20 ++++---------------- modules/quotes/quotes.js | 6 +++++- run.js | 4 ++-- 10 files changed, 18 insertions(+), 25 deletions(-) diff --git a/modules/admin/admin.js b/modules/admin/admin.js index 6923b19..ce8d73a 100644 --- a/modules/admin/admin.js +++ b/modules/admin/admin.js @@ -12,6 +12,7 @@ var admin = function(dbot) { if(configKey) { this.db.read('config', configKey, function(err, cRecord) { if(cRecord) { + console.log('record found'); callback(cRecord.value) } else { var configPath = dbot.config; diff --git a/modules/admin/commands.js b/modules/admin/commands.js index 3f1f788..a0dae29 100644 --- a/modules/admin/commands.js +++ b/modules/admin/commands.js @@ -94,9 +94,9 @@ var commands = function(dbot) { // Reload DB, translations and modules. 'reload': function(event) { + event.reply(dbot.t('reload')); dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8')); dbot.reloadModules(); - event.reply(dbot.t('reload')); }, // Say something in a channel diff --git a/modules/dent/config.json b/modules/dent/config.json index 8b0fd90..14eb3b3 100644 --- a/modules/dent/config.json +++ b/modules/dent/config.json @@ -4,5 +4,5 @@ "dependencies": [ "command" ], "ignorable": true, "help": "https://github.com/reality/depressionbot/blob/master/modules/dent/README.md", - "dentQuotes": false + "dentQuotes": true } diff --git a/modules/dent/dent.js b/modules/dent/dent.js index a990984..756b13d 100644 --- a/modules/dent/dent.js +++ b/modules/dent/dent.js @@ -58,7 +58,7 @@ var dent = function(dbot) { this.onLoad = function() { if(dbot.config.dent.dentQuotes === true && _.has(dbot.modules, 'quotes')) { - dbot.api.command.addHook('~qadd', function(key, text) { + dbot.api.event.addHook('~qadd', function(key, text) { if(text.indexOf('~~') == -1) { this.api.post(key + ': ' + text); } diff --git a/modules/ignore/config.json b/modules/ignore/config.json index 94f16ed..2a85c47 100644 --- a/modules/ignore/config.json +++ b/modules/ignore/config.json @@ -2,6 +2,6 @@ "ignorable": false, "dependencies": [ "command" ], "dbKeys": [ "ignores", "bans" ], - "dbType": "memory", + "dbType": "redis", "help": "http://github.com/reality/depressionbot/blob/master/modules/ignore/README.md" } diff --git a/modules/link/config.json b/modules/link/config.json index 9c3dc3e..2ce7ed4 100644 --- a/modules/link/config.json +++ b/modules/link/config.json @@ -1,5 +1,5 @@ { - "autoTitle": false, + "autoTitle": true, "dependencies": [ "command" ], "ignorable": true, "help": "http://github.com/reality/depressionbot/blob/master/modules/link/README.md" diff --git a/modules/poll/config.json b/modules/poll/config.json index 9f5ce60..a001437 100644 --- a/modules/poll/config.json +++ b/modules/poll/config.json @@ -1,6 +1,6 @@ { "help": "http://github.com/reality/depressionbot/blob/master/modules/poll/README.md", - "dbType": "disk", + "dbType": "redis", "dbKeys": [ "polls" ], "ignorable": true, "dependencies": [ "users", "command" ], diff --git a/modules/quotes/commands.js b/modules/quotes/commands.js index 9641086..fe3fc3e 100644 --- a/modules/quotes/commands.js +++ b/modules/quotes/commands.js @@ -12,10 +12,7 @@ var commands = function(dbot) { quote = event.input[2]; this.api.addQuote(key, quote, event.user, function(newCount) { - dbot.api.event.emit('~qadd', { - 'key': key, - 'text': quote - }); + dbot.api.event.emit('~qadd', [ key, quote ]); event.reply(dbot.t('quote_saved', { 'category': key, 'count': newCount @@ -47,7 +44,9 @@ var commands = function(dbot) { '~rq': function(event) { var categories = []; this.db.scan('quote_category', function(result) { - categories.push(result); + if(result) { + categories.push(result); + } }, function(err) { var cIndex = _.random(0, _.size(categories) -1); var qIndex = _.random(0, categories[cIndex].quotes.length - 1); @@ -91,17 +90,6 @@ var commands = function(dbot) { { 'count': rmCacheCount })); }, - // Retrieve quote from a category in the database. - '~q': function(event) { - var key = event.input[1].trim().toLowerCase(); - var quote = this.api.getQuote(event, event.input[1]); - if(quote) { - event.reply(key + ': ' + quote); - } else { - event.reply(dbot.t('category_not_found', {'category': key})); - } - }, - '~rmlast': function(event) { if(this.rmAllowed === true || _.include(dbot.config.admins, event.user)) { var key = event.input[1].trim().toLowerCase(), diff --git a/modules/quotes/quotes.js b/modules/quotes/quotes.js index cc66e18..e61ca15 100644 --- a/modules/quotes/quotes.js +++ b/modules/quotes/quotes.js @@ -106,7 +106,11 @@ var quotes = function(dbot) { key = key.trim().toLowerCase(), this.api.getQuote(key, function(quote) { - this.internalAPI.interpolatedQuote(server, channel, key, quote, callback); + if(quote) { + this.internalAPI.interpolatedQuote(server, channel, key, quote, callback); + } else { + callback(quote); + } }.bind(this)); } }; diff --git a/run.js b/run.js index b6297b0..f6bb8e8 100644 --- a/run.js +++ b/run.js @@ -281,8 +281,8 @@ DBot.prototype.reloadModules = function() { var propertyData = {}; try { propertyData = JSON.parse(fs.readFileSync(moduleDir + property + '.json', 'utf-8')); - } catch(err) {}; - _.extend(this[property], propertyData); + } catch(err) {}; + _.extend(this[property], propertyData); }, this); // Provide toString for module name