3
0
mirror of https://github.com/reality/dbot.git synced 2025-01-11 12:32:36 +01:00

Merge pull request #33 from danharibo/master

There I fixed it
This commit is contained in:
Luke Slater 2012-03-13 09:12:06 -07:00
commit 27baefb6ce

21
run.js
View File

@ -68,20 +68,17 @@ var DBot = function(timers) {
// Retrieve a random quote from a given category, interpolating any quote references (~~QUOTE CATEGORY~~) within it // Retrieve a random quote from a given category, interpolating any quote references (~~QUOTE CATEGORY~~) within it
DBot.prototype.interpolatedQuote = function(key, quoteTree) { DBot.prototype.interpolatedQuote = function(key, quoteTree) {
if( quoteTree !== undefined && quoteTree.indexOf( key ) != -1 ) return ''; if( quoteTree !== undefined && quoteTree.indexOf( key ) != -1 ) { console.log('nrll'); return ''; }
else if( quoteTree === undefined ) quoteTree = []; else if( quoteTree === undefined ) quoteTree = [];
var quoteString = this.db.quoteArrs[key].random(); var quoteString = this.db.quoteArrs[key].random();
var quoteRefs; var quoteRefs = quoteString.match(/~~([\d\w\s-]*)~~/g);
while( (quoteRefs = quoteString.match(/~~([\d\w\s-]*)~~/)) ) { var thisRef;
quoteRefs = quoteRefs.slice(1); while( quoteRefs && (thisRef = quoteRefs.shift()) !== undefined ) {
for(var i=0;i<quoteRefs.length;i++) { var cleanRef = this.cleanNick(thisRef.replace(/^~~/,'').replace(/~~$/,'').trim());
var cleanRef = this.cleanNick(quoteRefs[i].trim()); if (this.db.quoteArrs.hasOwnProperty(cleanRef)) {
if (this.db.quoteArrs.hasOwnProperty(cleanRef)) { quoteTree.push( key );
quoteTree.push( cleanRef ); quoteString = quoteString.replace("~~"+cleanRef+"~~", this.interpolatedQuote(cleanRef, quoteTree.slice()));
console.log( "Tree: " + quoteTree, "clean: " + cleanRef ); quoteTree.pop();
quoteString = quoteString.replace("~~"+cleanRef+"~~", this.interpolatedQuote(cleanRef, quoteTree.slice()));
quoteTree.pop();
}
} }
} }
return quoteString; return quoteString;