From 56616d6bdf0f0257bfa2f3d652f2b14926475445 Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 12 Oct 2013 22:58:34 +0000 Subject: [PATCH] imdb link handler --- modules/imdb/imdb.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/imdb/imdb.js b/modules/imdb/imdb.js index 1be0653..8f79b52 100644 --- a/modules/imdb/imdb.js +++ b/modules/imdb/imdb.js @@ -32,7 +32,7 @@ var imdb = function(dbot) { this.commands = { '~film': function(event) { - request.get(ApiRoot + 'movies.json', { + request.get(ApiRoot, { 'qs': { 'q': event.input[1], 'page_limit': 1 @@ -48,6 +48,24 @@ var imdb = function(dbot) { } }; this.commands['~film'].regex = [/^~film (.+)$/, 2]; + + this.onLoad = function() { + dbot.api.link.addHandler('imdb', /https?:\/\/(www\.)?imdb\.com\/title\/([a-zA-Z0-9]+)/, function(matches, name, callback) { + var id = matches[2]; + request.get(ApiRoot, { + 'qs': { + 'id': id, + 'page_limit': 1 + }, + 'json': true + }, function(error, response, body) { + if(_.isObject(body) && !_.has(body, 'error')) { + callback(this.internalAPI.formatLink(body)); + } + }.bind(this)); + + }.bind(this)); + }.bind(this) }; exports.fetch = function(dbot) {