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
This commit is contained in:
reality 2013-04-22 14:22:35 +00:00
parent c5fb52a4a7
commit 8e8953999d
10 changed files with 18 additions and 25 deletions

View File

@ -12,6 +12,7 @@ var admin = function(dbot) {
if(configKey) { if(configKey) {
this.db.read('config', configKey, function(err, cRecord) { this.db.read('config', configKey, function(err, cRecord) {
if(cRecord) { if(cRecord) {
console.log('record found');
callback(cRecord.value) callback(cRecord.value)
} else { } else {
var configPath = dbot.config; var configPath = dbot.config;

View File

@ -94,9 +94,9 @@ var commands = function(dbot) {
// Reload DB, translations and modules. // Reload DB, translations and modules.
'reload': function(event) { 'reload': function(event) {
event.reply(dbot.t('reload'));
dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8')); dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
dbot.reloadModules(); dbot.reloadModules();
event.reply(dbot.t('reload'));
}, },
// Say something in a channel // Say something in a channel

View File

@ -4,5 +4,5 @@
"dependencies": [ "command" ], "dependencies": [ "command" ],
"ignorable": true, "ignorable": true,
"help": "https://github.com/reality/depressionbot/blob/master/modules/dent/README.md", "help": "https://github.com/reality/depressionbot/blob/master/modules/dent/README.md",
"dentQuotes": false "dentQuotes": true
} }

View File

@ -58,7 +58,7 @@ var dent = function(dbot) {
this.onLoad = function() { this.onLoad = function() {
if(dbot.config.dent.dentQuotes === true && _.has(dbot.modules, 'quotes')) { 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) { if(text.indexOf('~~') == -1) {
this.api.post(key + ': ' + text); this.api.post(key + ': ' + text);
} }

View File

@ -2,6 +2,6 @@
"ignorable": false, "ignorable": false,
"dependencies": [ "command" ], "dependencies": [ "command" ],
"dbKeys": [ "ignores", "bans" ], "dbKeys": [ "ignores", "bans" ],
"dbType": "memory", "dbType": "redis",
"help": "http://github.com/reality/depressionbot/blob/master/modules/ignore/README.md" "help": "http://github.com/reality/depressionbot/blob/master/modules/ignore/README.md"
} }

View File

@ -1,5 +1,5 @@
{ {
"autoTitle": false, "autoTitle": true,
"dependencies": [ "command" ], "dependencies": [ "command" ],
"ignorable": true, "ignorable": true,
"help": "http://github.com/reality/depressionbot/blob/master/modules/link/README.md" "help": "http://github.com/reality/depressionbot/blob/master/modules/link/README.md"

View File

@ -1,6 +1,6 @@
{ {
"help": "http://github.com/reality/depressionbot/blob/master/modules/poll/README.md", "help": "http://github.com/reality/depressionbot/blob/master/modules/poll/README.md",
"dbType": "disk", "dbType": "redis",
"dbKeys": [ "polls" ], "dbKeys": [ "polls" ],
"ignorable": true, "ignorable": true,
"dependencies": [ "users", "command" ], "dependencies": [ "users", "command" ],

View File

@ -12,10 +12,7 @@ var commands = function(dbot) {
quote = event.input[2]; quote = event.input[2];
this.api.addQuote(key, quote, event.user, function(newCount) { this.api.addQuote(key, quote, event.user, function(newCount) {
dbot.api.event.emit('~qadd', { dbot.api.event.emit('~qadd', [ key, quote ]);
'key': key,
'text': quote
});
event.reply(dbot.t('quote_saved', { event.reply(dbot.t('quote_saved', {
'category': key, 'category': key,
'count': newCount 'count': newCount
@ -47,7 +44,9 @@ var commands = function(dbot) {
'~rq': function(event) { '~rq': function(event) {
var categories = []; var categories = [];
this.db.scan('quote_category', function(result) { this.db.scan('quote_category', function(result) {
if(result) {
categories.push(result); categories.push(result);
}
}, function(err) { }, function(err) {
var cIndex = _.random(0, _.size(categories) -1); var cIndex = _.random(0, _.size(categories) -1);
var qIndex = _.random(0, categories[cIndex].quotes.length - 1); var qIndex = _.random(0, categories[cIndex].quotes.length - 1);
@ -91,17 +90,6 @@ var commands = function(dbot) {
{ 'count': rmCacheCount })); { '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) { '~rmlast': function(event) {
if(this.rmAllowed === true || _.include(dbot.config.admins, event.user)) { if(this.rmAllowed === true || _.include(dbot.config.admins, event.user)) {
var key = event.input[1].trim().toLowerCase(), var key = event.input[1].trim().toLowerCase(),

View File

@ -106,7 +106,11 @@ var quotes = function(dbot) {
key = key.trim().toLowerCase(), key = key.trim().toLowerCase(),
this.api.getQuote(key, function(quote) { this.api.getQuote(key, function(quote) {
if(quote) {
this.internalAPI.interpolatedQuote(server, channel, key, quote, callback); this.internalAPI.interpolatedQuote(server, channel, key, quote, callback);
} else {
callback(quote);
}
}.bind(this)); }.bind(this));
} }
}; };