3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-25 04:02:39 +01:00

Interpolated quotes, because why not?

This commit is contained in:
Psychedelic Squid 2012-03-07 22:13:31 +00:00
parent e36f985536
commit 1d2659f361
3 changed files with 22 additions and 6 deletions

View File

@ -4,9 +4,9 @@ var puns = function(dbot) {
return { return {
'listener': function(data) { 'listener': function(data) {
if(data.user == 'reality') { if(data.user == 'reality') {
dbot.instance.say(data.channel, dbot.db.quoteArrs['realityonce'].random()); dbot.instance.say(data.channel, dbot.interpolatedQuote('realityonce'));
} else if(dbot.db.quoteArrs.hasOwnProperty(data.user.toLowerCase())) { } else if(dbot.db.quoteArrs.hasOwnProperty(data.user.toLowerCase())) {
dbot.say(data.channel, data.user + ': ' + dbot.db.quoteArrs[data.user.toLowerCase()].random()); dbot.say(data.channel, data.user + ': ' + dbot.interpolatedQuote(data.user.toLowerCase()));
} else if(dbot.instance.inChannel(data.channel)) { } else if(dbot.instance.inChannel(data.channel)) {
dbot.instance.say('aisbot', '.karma ' + data.user); dbot.instance.say('aisbot', '.karma ' + data.user);
dbot.waitingForKarma = data.channel; dbot.waitingForKarma = data.channel;

View File

@ -10,7 +10,7 @@ var quotes = function(dbot) {
q[1] = q[1].trim(); q[1] = q[1].trim();
key = q[1].toLowerCase(); key = q[1].toLowerCase();
if(quotes.hasOwnProperty(key)) { if(quotes.hasOwnProperty(key)) {
dbot.say(data.channel, q[1] + ': ' + quotes[key].random()); dbot.say(data.channel, q[1] + ': ' + dbot.interpolatedQuote(key));
} else { } else {
dbot.say(data.channel, 'Nobody loves ' + q[1]); dbot.say(data.channel, 'Nobody loves ' + q[1]);
} }
@ -189,11 +189,11 @@ var quotes = function(dbot) {
'~rq': function(data, params) { '~rq': function(data, params) {
var rQuote = Object.keys(quotes).random(); var rQuote = Object.keys(quotes).random();
dbot.say(data.channel, rQuote + ': ' + quotes[rQuote].random()); dbot.say(data.channel, rQuote + ': ' + dbot.interpolatedQuote(rQuote));
}, },
'~d': function(data, params) { '~d': function(data, params) {
dbot.say(data.channel, data.user + ': ' + dbot.db.quoteArrs['depressionbot'].random()); dbot.say(data.channel, data.user + ': ' + dbot.interpolatedQuote('depressionbot'));
}, },
'~link': function(data, params) { '~link': function(data, params) {

18
run.js
View File

@ -61,6 +61,22 @@ var DBot = function(timers) {
this.instance.connect(); this.instance.connect();
}; };
// Retrieve a random quote from a given category, interpolating any quote references (~~QUOTE CATEGORY~~) within it
DBot.prototype.interpolatedQuote = function(key) {
var quoteString = this.db.quoteArrs[key].random();
var quoteRefs = quoteString.match(/~~([\d\w\s-]*)~~/);
if (quoteRefs) {
quoteRefs = quoteRefs.slice(1);
for(var i=0;i<quoteRefs.length;i++) {
var cleanRef = this.cleanNick(quoteRefs[i].trim());
if (this.db.quoteArrs.hasOwnProperty(cleanRef)) {
quoteString = quoteString.replace("~~"+cleanRef+"~~", this.db.quoteArrs[cleanRef].random());
}
}
}
return quoteString;
};
// Say something in a channel // Say something in a channel
DBot.prototype.say = function(channel, data) { DBot.prototype.say = function(channel, data) {
this.instance.say(channel, data); this.instance.say(channel, data);
@ -150,7 +166,7 @@ DBot.prototype.reloadModules = function() {
q[1] = q[1].trim(); q[1] = q[1].trim();
key = this.cleanNick(q[1]) key = this.cleanNick(q[1])
if(this.db.quoteArrs.hasOwnProperty(key)) { if(this.db.quoteArrs.hasOwnProperty(key)) {
this.say(data.channel, q[1] + ': ' + this.db.quoteArrs[key].random()); this.say(data.channel, q[1] + ': ' + this.interpolatedQuote(key));
} else { } else {
// See if it's similar to anything // See if it's similar to anything
var winnerDistance = Infinity; var winnerDistance = Infinity;