forked from GitHub/dbot
commit
27baefb6ce
21
run.js
21
run.js
@ -68,20 +68,17 @@ var DBot = function(timers) {
|
||||
|
||||
// Retrieve a random quote from a given category, interpolating any quote references (~~QUOTE CATEGORY~~) within it
|
||||
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 = [];
|
||||
var quoteString = this.db.quoteArrs[key].random();
|
||||
var quoteRefs;
|
||||
while( (quoteRefs = quoteString.match(/~~([\d\w\s-]*)~~/)) ) {
|
||||
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)) {
|
||||
quoteTree.push( cleanRef );
|
||||
console.log( "Tree: " + quoteTree, "clean: " + cleanRef );
|
||||
quoteString = quoteString.replace("~~"+cleanRef+"~~", this.interpolatedQuote(cleanRef, quoteTree.slice()));
|
||||
quoteTree.pop();
|
||||
}
|
||||
var quoteRefs = quoteString.match(/~~([\d\w\s-]*)~~/g);
|
||||
var thisRef;
|
||||
while( quoteRefs && (thisRef = quoteRefs.shift()) !== undefined ) {
|
||||
var cleanRef = this.cleanNick(thisRef.replace(/^~~/,'').replace(/~~$/,'').trim());
|
||||
if (this.db.quoteArrs.hasOwnProperty(cleanRef)) {
|
||||
quoteTree.push( key );
|
||||
quoteString = quoteString.replace("~~"+cleanRef+"~~", this.interpolatedQuote(cleanRef, quoteTree.slice()));
|
||||
quoteTree.pop();
|
||||
}
|
||||
}
|
||||
return quoteString;
|
||||
|
Loading…
Reference in New Issue
Block a user