3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-30 16:09:27 +01:00

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) {
this.db.read('config', configKey, function(err, cRecord) {
if(cRecord) {
console.log('record found');
callback(cRecord.value)
} else {
var configPath = dbot.config;

View File

@ -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

View File

@ -4,5 +4,5 @@
"dependencies": [ "command" ],
"ignorable": true,
"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() {
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);
}

View File

@ -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"
}

View File

@ -1,5 +1,5 @@
{
"autoTitle": false,
"autoTitle": true,
"dependencies": [ "command" ],
"ignorable": true,
"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",
"dbType": "disk",
"dbType": "redis",
"dbKeys": [ "polls" ],
"ignorable": true,
"dependencies": [ "users", "command" ],

View File

@ -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(),

View File

@ -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));
}
};

4
run.js
View File

@ -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