Merge pull request #679 from Scritches/master

Urban dictionary API changed - removed result_type
This commit is contained in:
Luke Slater 2018-08-27 19:26:50 +01:00 committed by GitHub
commit 8c97c665a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,14 +47,19 @@ var link = function(dbot) {
encodeURI(query);
request(reqUrl, function(error, response, body) {
console.log(reqUrl);
try {
var result = JSON.parse(body);
if(_.has(result, 'result_type') && result.result_type != 'no_results') {
if(_.has(result, 'list') && result.list.length > 0) {
callback(result.list[0].word, result.list[0].definition.split('\n')[0]);
} else {
callback(false);
}
} catch(err) { callback(false); }
} catch(err) {
console.log(err);
callback(false);
}
});
},