3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-18 08:32:42 +01:00

Don't pork up if UD is down

This commit is contained in:
Luke Slater 2013-01-30 09:56:56 +01:00
parent 2683ce268c
commit eb7a958352

View File

@ -55,12 +55,14 @@ var link = function(dbot) {
var query = event.input[1]; var query = event.input[1];
var reqUrl = 'http://api.urbandictionary.com/v0/define?term=' + encodeURI(query); var reqUrl = 'http://api.urbandictionary.com/v0/define?term=' + encodeURI(query);
request(reqUrl, function(error, response, body) { request(reqUrl, function(error, response, body) {
try {
var result = JSON.parse(body); var result = JSON.parse(body);
if(_.has(result, 'result_type') && result.result_type != 'no_results') { if(_.has(result, 'result_type') && result.result_type != 'no_results') {
event.reply(query + ': ' + result.list[0].definition.split('\n')[0]); event.reply(query + ': ' + result.list[0].definition.split('\n')[0]);
} else { } else {
event.reply(event.user + ': No definition found.'); event.reply(event.user + ': No definition found.');
} }
} catch(err) { }
}); });
} }
}; };