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

Commit 66a9170

Browse files
committed
added imdb command
1 parent cf411e7 commit 66a9170

File tree

1 file changed

+63
-19
lines changed

1 file changed

+63
-19
lines changed

master.js

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3403,8 +3403,6 @@ IO.register( 'input', function afkInputListener ( msgObj ) {
34033403

34043404
})();
34053405

3406-
;
3407-
34083406
;
34093407
(function () {
34103408
"use strict";
@@ -4496,10 +4494,6 @@ bot.addCommand({
44964494

44974495
}());
44984496

4499-
;
4500-
4501-
;
4502-
45034497
;
45044498
//listener to help decide which Firefly episode to watch
45054499

@@ -4799,7 +4793,68 @@ bot.addCommand({
47994793
}());
48004794

48014795
;
4796+
(function () {
4797+
4798+
function imdb ( args, cb ) {
4799+
var terms = args.toString().split(/,\s*/g);
4800+
var results = {
4801+
unescapedUrls : [],
4802+
formatted : []
4803+
};
4804+
4805+
terms.forEach(function ( term ) {
4806+
IO.jsonp.google(
4807+
term + ' site:imdb.com', finishCall );
4808+
});
4809+
4810+
function finishCall ( resp ) {
4811+
if ( resp.responseStatus !== 200 ) {
4812+
finish( 'Something went on fire; status ' + resp.responseStatus );
4813+
return;
4814+
}
4815+
4816+
var result = resp.responseData.results[ 0 ];
4817+
bot.log( result, '/imdb result' );
4818+
4819+
var title = IO.decodehtmlEntities(
4820+
result.titleNoFormatting.split(' -')[0].trim()
4821+
);
4822+
4823+
results.formatted.push( bot.adapter.link(title, result.url) );
4824+
results.unescapedUrls.push( result.url );
4825+
4826+
if ( results.formatted.length === terms.length ) {
4827+
aggregatedResults();
4828+
}
4829+
}
4830+
function aggregatedResults () {
4831+
var msg = results.formatted.join( ', ' );
4832+
if ( msg.length > bot.adapter.maxLineLength ) {
4833+
msg = results.unescapedUrls.join( ', ' );
4834+
}
4835+
4836+
finish( msg );
4837+
}
4838+
function finish ( res ) {
4839+
if ( cb && cb.call ) {
4840+
cb( res );
4841+
}
4842+
else {
4843+
args.reply( res );
4844+
}
4845+
}
4846+
};
4847+
4848+
bot.addCommand({
4849+
name : 'imdb',
4850+
fun : imdb,
4851+
4852+
permissions : { del : 'NONE', use : 'ALL' },
4853+
description : 'Fetches imdb page. `/imdb what`',
4854+
async : true
4855+
});
48024856

4857+
})();
48034858
;
48044859
(function () {
48054860
var baseURL = 'http://api.jquery.com/';
@@ -4883,8 +4938,6 @@ bot.addCommand({
48834938

48844939
})();
48854940

4886-
;
4887-
48884941
;
48894942
(function () {
48904943
"use strict";
@@ -5182,8 +5235,6 @@ bot.addCommand({
51825235

51835236
})();
51845237

5185-
;
5186-
51875238
;
51885239
(function () {
51895240
// #151: Listen for meme image names and reply with that meme.
@@ -5350,8 +5401,6 @@ bot.addCommand( moustache );
53505401

53515402
}());
53525403

5353-
;
5354-
53555404
;
53565405
(function () {
53575406

@@ -5479,8 +5528,6 @@ function nudgeListener ( args ) {
54795528

54805529
}());
54815530

5482-
;
5483-
54845531
;
54855532
(function () {
54865533
var specParts;
@@ -6236,7 +6283,8 @@ function createLecture ( content ) {
62366283

62376284
var lecture = (
62386285
'Please don\'t post unformatted code - ' +
6239-
'hit Ctrl+K before sending, and see the {0}.'
6286+
'hit Ctrl+K before sending, use up-arrow to edit messages, ' +
6287+
'and see the {0}.'
62406288
).supplant( bot.adapter.link('faq', '/faq') );
62416289

62426290
if ( lineCount >= 10 ) {
@@ -6259,8 +6307,6 @@ function hasUnformattedCode ( text ) {
62596307

62606308
})();
62616309

6262-
;
6263-
62646310
;
62656311
(function () {
62666312
"use strict";
@@ -6482,8 +6528,6 @@ bot.addCommand({
64826528

64836529
})();
64846530

6485-
;
6486-
64876531
;
64886532
bot.addCommand({
64896533
name : 'user',

0 commit comments

Comments
 (0)