From 7c621aeae2dc7137cfff71e9527d64e8c5f41976 Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 12 Oct 2013 22:31:57 +0000 Subject: [PATCH] replace rottentomatoes module with new fancier imdb module --- modules/imdb/config.json | 3 +++ modules/imdb/imdb.js | 55 +++++++++++++++++++++++++++++++++++++++ modules/imdb/strings.json | 8 ++++++ modules/rt/config.json | 4 --- modules/rt/rt.js | 52 ------------------------------------ modules/rt/strings.json | 8 ------ 6 files changed, 66 insertions(+), 64 deletions(-) create mode 100644 modules/imdb/config.json create mode 100644 modules/imdb/imdb.js create mode 100644 modules/imdb/strings.json delete mode 100644 modules/rt/config.json delete mode 100644 modules/rt/rt.js delete mode 100644 modules/rt/strings.json diff --git a/modules/imdb/config.json b/modules/imdb/config.json new file mode 100644 index 0000000..48f4b6e --- /dev/null +++ b/modules/imdb/config.json @@ -0,0 +1,3 @@ +{ + "outputPrefix": "\u00033IMDB\u000f" +} diff --git a/modules/imdb/imdb.js b/modules/imdb/imdb.js new file mode 100644 index 0000000..1be0653 --- /dev/null +++ b/modules/imdb/imdb.js @@ -0,0 +1,55 @@ +/** + * Module Name: IMDB + * Description: Various IMDB functionality. + */ + +var _ = require('underscore')._, + request = require('request'); + +var imdb = function(dbot) { + var ApiRoot = 'http://mymovieapi.com/'; + + this.internalAPI = { + 'formatLink': function(m) { + var rating = m.rating; + var rColour = (rating <= 5) ? '\u00033 ' : '\u00034 '; + rating = rColour + String(rating) + '\u000f'; + + var mString = dbot.t('imdb_film', { + 'title': m.title, + 'year': m.year, + 'rating': rating + }); + + if(_.has(m, 'directors')) mString += ' [Director: ' + m.directors[0] + ']'; + if(_.has(m, 'genres')) mString += ' [Genre: ' + m.genres[0] + ']'; + if(_.has(m, 'plot_simple')) mString += ' [Description: ' + m.plot_simple + ']'; + mString += ' - ' + m.imdb_url; + + return mString; + } + }; + + this.commands = { + '~film': function(event) { + request.get(ApiRoot + 'movies.json', { + 'qs': { + 'q': event.input[1], + 'page_limit': 1 + }, + 'json': true + }, function(error, response, body) { + if(_.isObject(body) && !_.isUndefined(body[0])) { + event.reply(this.internalAPI.formatLink(body[0])); + } else { + event.reply(dbot.t('imdb_noresults')); + } + }.bind(this)); + } + }; + this.commands['~film'].regex = [/^~film (.+)$/, 2]; +}; + +exports.fetch = function(dbot) { + return new imdb(dbot); +}; diff --git a/modules/imdb/strings.json b/modules/imdb/strings.json new file mode 100644 index 0000000..4a2431e --- /dev/null +++ b/modules/imdb/strings.json @@ -0,0 +1,8 @@ +{ + "imdb_film": { + "en": "[{title} -{rating} - {year}]" + }, + "imdb_noresults": { + "en": "No films found." + } +} diff --git a/modules/rt/config.json b/modules/rt/config.json deleted file mode 100644 index 9c61bd4..0000000 --- a/modules/rt/config.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "apikey": "http://developer.rottentomatoes.com/", - "outputPrefix": "\u00033R\u00034T\u000f" -} diff --git a/modules/rt/rt.js b/modules/rt/rt.js deleted file mode 100644 index 104d67d..0000000 --- a/modules/rt/rt.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Module Name: Rotten Tomatoes - * Description: Various Rotten Tomatoes functionality. - */ - -var _ = require('underscore')._, - request = require('request'); - -var rt = function(dbot) { - var ApiRoot = 'http://api.rottentomatoes.com/api/public/v1.0/'; - - this.internalAPI = { - 'formatLink': function(m) { - var rating = m.ratings.audience_score; - if(_.has(m.ratings, 'critics_score')) rating = m.ratings.critics_score; - var rColour = (rating <= 50) ? '\u00033 ' : '\u00034 '; - rating = rColour + String(rating) + '%\u000f'; - - return dbot.t('rt_film', { - 'title': m.title, - 'year': m.year, - 'link': m.links.alternate, - 'rating': rating - }); - } - }; - - this.commands = { - '~film': function(event) { - //http://api.rottentomatoes.com/api/public/v1.0/movies.json?q={search-term}&page_limit={results-per-page}&page={page-number} - request.get(ApiRoot + 'movies.json', { - 'qs': { - 'q': event.input[1], - 'page_limit': 1, - 'apikey': this.config.apikey - }, - 'json': true - }, function(error, response, body) { - if(_.isObject(body) && _.has(body, 'movies')) { - event.reply(this.internalAPI.formatLink(body.movies[0])); - } else { - event.reply(dbot.t('rt_noresults')); - } - }.bind(this)); - } - }; - this.commands['~film'].regex = [/^~film (.+)$/, 2]; -}; - -exports.fetch = function(dbot) { - return new rt(dbot); -}; diff --git a/modules/rt/strings.json b/modules/rt/strings.json deleted file mode 100644 index 45813ae..0000000 --- a/modules/rt/strings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "rt_film": { - "en": "[{title} -{rating} - {year}] - {link}" - }, - "rt_noresults": { - "en": "No films found." - } -}