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

Commit 248d44b

Browse files
committed
adding imdb
1 parent eb3f300 commit 248d44b

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

source/plugins/imdb.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
(function () {
2+
3+
function imdb ( args, cb ) {
4+
var terms = args.toString().split(/,\s*/g);
5+
var results = {
6+
unescapedUrls : [],
7+
formatted : []
8+
};
9+
10+
terms.forEach(function ( term ) {
11+
IO.jsonp.google(
12+
term + ' site:imdb.com', finishCall );
13+
});
14+
15+
function finishCall ( resp ) {
16+
if ( resp.responseStatus !== 200 ) {
17+
finish( 'Something went on fire; status ' + resp.responseStatus );
18+
return;
19+
}
20+
21+
var result = resp.responseData.results[ 0 ];
22+
bot.log( result, '/imdb result' );
23+
24+
var title = IO.decodehtmlEntities(
25+
result.titleNoFormatting.split(' -')[0].trim()
26+
);
27+
28+
results.formatted.push( bot.adapter.link(title, result.url) );
29+
results.unescapedUrls.push( result.url );
30+
31+
if ( results.formatted.length === terms.length ) {
32+
aggregatedResults();
33+
}
34+
}
35+
function aggregatedResults () {
36+
var msg = results.formatted.join( ', ' );
37+
if ( msg.length > bot.adapter.maxLineLength ) {
38+
msg = results.unescapedUrls.join( ', ' );
39+
}
40+
41+
finish( msg );
42+
}
43+
function finish ( res ) {
44+
if ( cb && cb.call ) {
45+
cb( res );
46+
}
47+
else {
48+
args.reply( res );
49+
}
50+
}
51+
};
52+
53+
bot.addCommand({
54+
name : 'imdb',
55+
fun : imdb,
56+
57+
permissions : { del : 'NONE', use : 'ALL' },
58+
description : 'Fetches imdb page. `/imdb what`',
59+
async : true
60+
});
61+
62+
})();

0 commit comments

Comments
 (0)