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

Commit b0f84b4

Browse files
author
awalGarg
committed
prettier urls and multiple arguments
i tested in sandbox and it worked for me
1 parent 8ebd059 commit b0f84b4

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

source/plugins/mdn.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
(function () {
22

33
function mdn ( args, cb ) {
4-
IO.jsonp.google(
5-
args.toString() + ' site:developer.mozilla.org', finishCall );
6-
4+
var terms = args.toString().split(/,\s*/g),
5+
results = {'unescapedUrls': [], 'formatted': []};
6+
terms.forEach(function (term) {
7+
IO.jsonp.google(
8+
term + ' site:developer.mozilla.org', finishCall );
9+
});
710
function finishCall ( resp ) {
11+
812
if ( resp.responseStatus !== 200 ) {
913
finish( 'Something went on fire; status ' + resp.responseStatus );
1014
return;
1115
}
1216

1317
var result = resp.responseData.results[ 0 ];
1418
bot.log( result, '/mdn result' );
15-
finish( result.url );
19+
20+
var title = result.titleNoFormatting.replace(/ -.+/, '');
21+
results.formatted.push(bot.adapter.link(IO.decodehtmlEntities(title), result.url));
22+
results.unescapedUrls.push(result.url);
23+
24+
if (results.formatted.length === terms.length) {
25+
var msg = results.formatted.join(', ');
26+
if (msg.length > bot.adapter.maxLineLength) {
27+
msg = results.unescapedUrls.join(', ');
28+
}
29+
finish( msg );
30+
}
31+
1632
}
1733

1834
function finish ( res ) {

0 commit comments

Comments
 (0)