mirror of
https://github.com/reality/dbot.git
synced 2025-01-11 20:42:37 +01:00
-nicks- now picks random nick from channel [#105]
This commit is contained in:
parent
76733f4679
commit
0f39a227f2
@ -9,7 +9,7 @@ var quotes = function(dbot) {
|
|||||||
|
|
||||||
// Retrieve a random quote from a given category, interpolating any quote
|
// Retrieve a random quote from a given category, interpolating any quote
|
||||||
// references (~~QUOTE CATEGORY~~) within it
|
// references (~~QUOTE CATEGORY~~) within it
|
||||||
var interpolatedQuote = function(key, quoteTree) {
|
var interpolatedQuote = function(event, key, quoteTree) {
|
||||||
if(quoteTree !== undefined && quoteTree.indexOf(key) != -1) {
|
if(quoteTree !== undefined && quoteTree.indexOf(key) != -1) {
|
||||||
return '';
|
return '';
|
||||||
} else if(quoteTree === undefined) {
|
} else if(quoteTree === undefined) {
|
||||||
@ -24,10 +24,14 @@ var quotes = function(dbot) {
|
|||||||
|
|
||||||
while(quoteRefs && (thisRef = quoteRefs.shift()) !== undefined) {
|
while(quoteRefs && (thisRef = quoteRefs.shift()) !== undefined) {
|
||||||
var cleanRef = dbot.cleanNick(thisRef.replace(/^~~/,'').replace(/~~$/,'').trim());
|
var cleanRef = dbot.cleanNick(thisRef.replace(/^~~/,'').replace(/~~$/,'').trim());
|
||||||
if (quotes.hasOwnProperty(cleanRef)) {
|
if(cleanRef === '-nicks-') {
|
||||||
|
var randomNick = Object.keys(event.channel.nicks).random();
|
||||||
|
quoteString = quoteString.replace("~~" + cleanRef + "~~", randomNick);
|
||||||
|
quoteTree.pop();
|
||||||
|
} else if(quotes.hasOwnProperty(cleanRef)) {
|
||||||
quoteTree.push(key);
|
quoteTree.push(key);
|
||||||
quoteString = quoteString.replace("~~" + cleanRef + "~~",
|
quoteString = quoteString.replace("~~" + cleanRef + "~~",
|
||||||
interpolatedQuote(cleanRef, quoteTree.slice()));
|
interpolatedQuote(event, cleanRef, quoteTree.slice()));
|
||||||
quoteTree.pop();
|
quoteTree.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,7 +60,7 @@ var quotes = function(dbot) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var api = {
|
var api = {
|
||||||
'getQuote': function(category) {
|
'getQuote': function(event, category) {
|
||||||
var key = category.trim().toLowerCase();
|
var key = category.trim().toLowerCase();
|
||||||
var altKey;
|
var altKey;
|
||||||
if(key.split(' ').length > 0) {
|
if(key.split(' ').length > 0) {
|
||||||
@ -65,9 +69,9 @@ var quotes = function(dbot) {
|
|||||||
|
|
||||||
if(key.charAt(0) !== '_') { // lol
|
if(key.charAt(0) !== '_') { // lol
|
||||||
if(quotes.hasOwnProperty(key)) {
|
if(quotes.hasOwnProperty(key)) {
|
||||||
return interpolatedQuote(key);
|
return interpolatedQuote(event, key);
|
||||||
} else if(quotes.hasOwnProperty(altKey)) {
|
} else if(quotes.hasOwnProperty(altKey)) {
|
||||||
return interpolatedQuote(altKey);
|
return interpolatedQuote(event, altKey);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -117,7 +121,7 @@ var quotes = function(dbot) {
|
|||||||
// Retrieve quote from a category in the database.
|
// Retrieve quote from a category in the database.
|
||||||
'~q': function(event) {
|
'~q': function(event) {
|
||||||
var key = event.input[1].trim().toLowerCase();
|
var key = event.input[1].trim().toLowerCase();
|
||||||
var quote = api.getQuote(event.input[1]);
|
var quote = api.getQuote(event, event.input[1]);
|
||||||
if(quote) {
|
if(quote) {
|
||||||
event.reply(key + ': ' + quote);
|
event.reply(key + ': ' + quote);
|
||||||
} else {
|
} else {
|
||||||
@ -245,7 +249,7 @@ var quotes = function(dbot) {
|
|||||||
|
|
||||||
'~rq': function(event) {
|
'~rq': function(event) {
|
||||||
var rQuote = Object.keys(quotes).random();
|
var rQuote = Object.keys(quotes).random();
|
||||||
event.reply(rQuote + ': ' + interpolatedQuote(rQuote));
|
event.reply(rQuote + ': ' + interpolatedQuote(event, rQuote));
|
||||||
},
|
},
|
||||||
|
|
||||||
'~link': function(event) {
|
'~link': function(event) {
|
||||||
@ -315,9 +319,9 @@ var quotes = function(dbot) {
|
|||||||
dbot.instance.emit(event);
|
dbot.instance.emit(event);
|
||||||
}
|
}
|
||||||
} else if(event.action == 'JOIN') {
|
} else if(event.action == 'JOIN') {
|
||||||
var userQuote = api.getQuote(event.user)
|
var userQuote = api.getQuote(event, event.user)
|
||||||
if(userQuote) {
|
if(userQuote) {
|
||||||
event.reply(event.user + ': ' + api.getQuote(event.user));
|
event.reply(event.user + ': ' + api.getQuote(event, event.user));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user