Skip to content
This repository was archived by the owner on Jul 17, 2020. It is now read-only.

Commit f3d1b16

Browse files
author
Zirak
committed
fixes #144
1 parent cc5f14a commit f3d1b16

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

master.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6598,18 +6598,36 @@ bot.addCommand({
65986598
var cache = {};
65996599

66006600
function urban ( args, cb ) {
6601-
if ( !args.length ) {
6601+
if ( cache[args] ) {
6602+
return finish( cache[args] );
6603+
}
6604+
6605+
var parts = args.parse(),
6606+
query, resultIndex;
6607+
6608+
if ( !parts.length ) {
66026609
return 'Y U NO PROVIDE ARGUMENTS!?';
66036610
}
66046611

6605-
if ( cache[args] ) {
6606-
return finish( cache[args] );
6612+
// /urban query in several words
6613+
if ( isNaN(parts[1]) ) {
6614+
bot.log( '/urban input isNaN' );
6615+
query = args.toString();
6616+
resultIndex = 0;
6617+
}
6618+
// /urban query index
6619+
else {
6620+
bot.log( '/urban input isn\'t NaN' );
6621+
query = parts[ 0 ];
6622+
resultIndex = Number( parts[1] );
66076623
}
66086624

6625+
bot.log( query, resultIndex, '/urban input' );
6626+
66096627
IO.jsonp({
66106628
url : 'http://api.urbandictionary.com/v0/define',
66116629
data : {
6612-
term : args.content
6630+
term : query
66136631
},
66146632
jsonpName : 'callback',
66156633
fun : complete
@@ -6619,10 +6637,14 @@ function urban ( args, cb ) {
66196637
var msg;
66206638

66216639
if ( resp.result_type === 'no_results' ) {
6622-
msg = 'No definition found for ' + args;
6640+
msg = 'No definition found for ' + query;
6641+
}
6642+
else if ( resultIndex > resp.list.length ) {
6643+
msg = 'Nothing in that index. The last one is:\n' +
6644+
formatTop( resp.list.pop() );
66236645
}
66246646
else {
6625-
msg = formatTop( resp.list[0] );
6647+
msg = formatTop( resp.list[resultIndex] );
66266648
}
66276649
cache[ args ] = msg;
66286650

@@ -6659,7 +6681,8 @@ bot.addCommand({
66596681

66606682
permissions : { del : 'NONE', use : 'ALL' },
66616683

6662-
description : 'Fetches UrbanDictionary definition. `/urban something`',
6684+
description : 'Fetches UrbanDictionary definition. ' +
6685+
'`/urban query [resultIndex=0]`',
66636686
async : true
66646687
});
66656688

0 commit comments

Comments
 (0)