~~-nick-~~

This commit is contained in:
reality 2013-08-31 22:57:29 +00:00
parent 306b28bf93
commit b1c41008ce
3 changed files with 18 additions and 8 deletions

View File

@ -18,7 +18,8 @@ var command = function(dbot) {
if(!_.has(dbot.commands, commandName)) { if(!_.has(dbot.commands, commandName)) {
if(_.has(dbot.modules, 'quotes')) { if(_.has(dbot.modules, 'quotes')) {
var key = event.message.substring(1); var key = event.message.substring(1);
dbot.api.quotes.getInterpolatedQuote(event.server, event.channel.name, key, function(quote) { dbot.api.quotes.getInterpolatedQuote(event.server,
event.channel.name, event.user, key, function(quote) {
if(quote) { if(quote) {
event.reply(key + ': ' + quote); event.reply(key + ': ' + quote);
} else if(_.has(dbot.modules, 'spelling')) { } else if(_.has(dbot.modules, 'spelling')) {

View File

@ -34,7 +34,8 @@ var commands = 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]; var key = event.input[1];
this.api.getInterpolatedQuote(event.server, event.channel, key, function(quote) { this.api.getInterpolatedQuote(event.server, event.channel,
event.user, key, function(quote) {
if(quote) { if(quote) {
event.reply(key + ': ' + quote); event.reply(key + ': ' + quote);
} else { } else {

View File

@ -10,23 +10,29 @@ var quotes = function(dbot) {
this.internalAPI = { this.internalAPI = {
// Parse quote interpolations // Parse quote interpolations
'interpolatedQuote': function(server, channel, key, quote, callback) { 'interpolatedQuote': function(server, channel, username, key, quote, callback) {
console.log(quote);
var quoteRefs = quote.match(/~~([\d\w\s-]*)~~/g); var quoteRefs = quote.match(/~~([\d\w\s-]*)~~/g);
if(quoteRefs) { if(quoteRefs) {
var ref = this.internalAPI.cleanRef(quoteRefs[0].replace(/^~~/,'').replace(/~~$/,'').trim()); var ref = this.internalAPI.cleanRef(quoteRefs[0].replace(/^~~/,'').replace(/~~$/,'').trim());
if(ref === '-nicks-') { if(ref === '-nicks-') {
dbot.api.users.getRandomChannelUser(server, channel, function(user) { dbot.api.users.getRandomChannelUser(server, channel, function(user) {
quote = quote.replace('~~' + ref + '~~', user.currentNick); quote = quote.replace('~~' + ref + '~~', user.currentNick);
this.internalAPI.interpolatedQuote(server, channel, key, quote, callback); this.internalAPI.interpolatedQuote(server, channel,
username, key, quote, callback);
}.bind(this)); }.bind(this));
} else if(ref === '-nick-') {
quote = quote.replace('~~' + ref + '~~', username);
this.internalAPI.interpolatedQuote(server, channel,
username, key, quote, callback);
} else { } else {
this.api.getQuote(ref, function(interQuote) { this.api.getQuote(ref, function(interQuote) {
if(!interQuote || ref == key) { if(!interQuote || ref == key) {
interQuote = ''; interQuote = '';
} }
quote = quote.replace('~~' + ref + '~~', interQuote); quote = quote.replace('~~' + ref + '~~', interQuote);
console.log('lol'); this.internalAPI.interpolatedQuote(server, channel,
this.internalAPI.interpolatedQuote(server, channel, key, quote, callback); username, key, quote, callback);
}.bind(this)); }.bind(this));
} }
} else { } else {
@ -110,12 +116,14 @@ var quotes = function(dbot) {
}); });
}, },
'getInterpolatedQuote': function(server, channel, key, callback) { 'getInterpolatedQuote': function(server, channel, username, key, callback) {
console.log(key);
key = key.trim().toLowerCase(), key = key.trim().toLowerCase(),
this.api.getQuote(key, function(quote) { this.api.getQuote(key, function(quote) {
if(quote) { if(quote) {
this.internalAPI.interpolatedQuote(server, channel, key, quote, callback); this.internalAPI.interpolatedQuote(server, channel,
username, key, quote, callback);
} else { } else {
callback(quote); callback(quote);
} }