diff --git a/modules/link/link.js b/modules/link/link.js index 1e283ff..9d24134 100644 --- a/modules/link/link.js +++ b/modules/link/link.js @@ -40,6 +40,23 @@ var link = function(dbot) { page.abort(); } }); + }, + + 'udLookup': function(query, callback) { + var reqUrl = 'http://api.urbandictionary.com/v0/define?term=' + + encodeURI(query); + + request(reqUrl, function(error, response, body) { + try { + var result = JSON.parse(body); + if(_.has(result, 'result_type') && result.result_type != 'no_results') { + callback(result.list[0].word, result.list[0].definition.split('\n')[0]); + } else { + callback(false); + } + } catch(err) { callback(false); } + }); + } }; @@ -92,17 +109,13 @@ var link = function(dbot) { '~ud': function(event) { var query = event.input[1]; - var reqUrl = 'http://api.urbandictionary.com/v0/define?term=' + encodeURI(query); - request(reqUrl, function(error, response, body) { - try { - var result = JSON.parse(body); - if(_.has(result, 'result_type') && result.result_type != 'no_results') { - event.reply(result.list[0].word + ': ' + result.list[0].definition.split('\n')[0]); - } else { - event.reply(event.user + ': No definition found.'); - } - } catch(err) { } + this.api.udLookup(query, function(word, definition) { + if(word) { + event.reply(word + ': ' + definition); + } else { + event.reply(event.user + ': No definition found.'); + } }); } }; diff --git a/modules/quotes/commands.js b/modules/quotes/commands.js index 1ce726a..f47c7ee 100644 --- a/modules/quotes/commands.js +++ b/modules/quotes/commands.js @@ -38,9 +38,19 @@ var commands = function(dbot) { if(quote) { event.reply(key + ': ' + quote); } else { - event.reply(dbot.t('category_not_found', { 'category': key })); + if(this.config.udFallback === true && _.has(dbot.modules, 'link')) { + dbot.api.link.udLookup(key, function(word, definition) { + if(word) { + event.reply(key + '[UD]: ' + definition); + } else { + event.reply(dbot.t('category_not_found', { 'category': key })); + } + }); + } else { + event.reply(dbot.t('category_not_found', { 'category': key })); + } } - }); + }.bind(this)); }, // Choose a random quote category and a random quote from that diff --git a/modules/quotes/config.json b/modules/quotes/config.json index 5b7e2e5..d0fbe4a 100644 --- a/modules/quotes/config.json +++ b/modules/quotes/config.json @@ -3,5 +3,6 @@ "dependencies": [ "users", "event" ], "rmLimit": 10, "ignorable": true, - "quotesOnJoin": false + "quotesOnJoin": false, + "udFallback": false }