3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-24 04:49:25 +01:00
dbot/modules/quotes.js

52 lines
1.5 KiB
JavaScript
Raw Normal View History

var quotes = function(dbot) {
2011-08-22 20:24:23 +02:00
var quotes = dbot.db.quoteArrs;
return {
get: function(key) {
2011-08-24 17:15:56 +02:00
key = key.toLowerCase();
if(quotes.hasOwnProperty(key)) {
2011-08-22 20:24:23 +02:00
return key + ': ' + quotes[key].random();
} else {
return 'No quotes under ' + key;
}
},
count: function(key) {
2011-08-24 17:15:56 +02:00
key = key.toLowerCase();
if(quotes.hasOwnProperty(key)) {
return key + ' has ' + quotes[key].length + ' quotes.';
} else {
return 'No quotes under ' + key;
}
},
add: function(key) {
2011-08-24 17:15:56 +02:00
key[1] = key[1].toLowerCase();
if(!Object.isArray(quotes[key[1]])) {
quotes[key[1]] = [];
}
quotes[key[1]].push(key[2]);
return 'Quote saved in \'' + key[1] + '\' (' + quotes[key[1]].length + ')';
},
set: function(key) {
2011-08-24 17:15:56 +02:00
key[1] = key[1].toLowerCase();
if(!quotes.hasOwnProperty(key[1]) || (quotes.hasOwnProperty(key[1]) && quotes[key[1]].length == 1)) {
quotes[key[1]] = [key[2]];
return 'Quote saved as ' + key[1];
} else {
return 'No replacing arrays, you whore.';
}
},
random: function() {
var rQuote = Object.keys(quotes).random();
return rQuote + ': ' + quotes[rQuote].random();
}
};
};
exports.fetch = function(dbot) {
return quotes(dbot);
};