mirror of
https://github.com/reality/dbot.git
synced 2024-11-30 16:09:27 +01:00
Merge pull request #31 from danharibo/master
Recursive interpolatedQuote
This commit is contained in:
commit
1753b79463
9
run.js
9
run.js
@ -67,7 +67,9 @@ 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) {
|
DBot.prototype.interpolatedQuote = function(key, quoteTree) {
|
||||||
|
if( quoteTree !== undefined && quoteTree.indexOf( key ) != -1 ) return '';
|
||||||
|
else if( quoteTree === undefined ) quoteTree = [];
|
||||||
var quoteString = this.db.quoteArrs[key].random();
|
var quoteString = this.db.quoteArrs[key].random();
|
||||||
var quoteRefs;
|
var quoteRefs;
|
||||||
while( (quoteRefs = quoteString.match(/~~([\d\w\s-]*)~~/)) ) {
|
while( (quoteRefs = quoteString.match(/~~([\d\w\s-]*)~~/)) ) {
|
||||||
@ -75,7 +77,10 @@ DBot.prototype.interpolatedQuote = function(key) {
|
|||||||
for(var i=0;i<quoteRefs.length;i++) {
|
for(var i=0;i<quoteRefs.length;i++) {
|
||||||
var cleanRef = this.cleanNick(quoteRefs[i].trim());
|
var cleanRef = this.cleanNick(quoteRefs[i].trim());
|
||||||
if (this.db.quoteArrs.hasOwnProperty(cleanRef)) {
|
if (this.db.quoteArrs.hasOwnProperty(cleanRef)) {
|
||||||
quoteString = quoteString.replace("~~"+cleanRef+"~~", this.db.quoteArrs[cleanRef].random());
|
quoteTree.push( cleanRef );
|
||||||
|
console.log( "Tree: " + quoteTree, "clean: " + cleanRef );
|
||||||
|
quoteString = quoteString.replace("~~"+cleanRef+"~~", this.interpolatedQuote(cleanRef, quoteTree.slice()));
|
||||||
|
quoteTree.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user