diff --git a/modules/imdb/README.md b/modules/imdb/README.md deleted file mode 100644 index dac2fbd..0000000 --- a/modules/imdb/README.md +++ /dev/null @@ -1,32 +0,0 @@ -## IMDB - -Adds various IMDB functionalities. - -### Description - -This module provides a command which allows users to search IMDB for a movie. - -### Dependencies - -It has following dependencies: -+ [request](https://github.com/mikeal/request) - -### config.json - -output prefix can be set. -``` -{ - "outputPrefix": "\u00033IMDB\u000f" -} - -``` - -### Commands - - -#### ~imdb [movie] -Searches IMDB for a movie. -Example: -+ ~imdb Fear and Loathing in Las Vegas - -### TODO \ No newline at end of file diff --git a/modules/imdb/config.json b/modules/imdb/config.json deleted file mode 100644 index 48f4b6e..0000000 --- a/modules/imdb/config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "outputPrefix": "\u00033IMDB\u000f" -} diff --git a/modules/imdb/imdb.js b/modules/imdb/imdb.js deleted file mode 100644 index 0010f4b..0000000 --- a/modules/imdb/imdb.js +++ /dev/null @@ -1,73 +0,0 @@ -/** - * 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 = { - '~imdb': function(event) { - request.get(ApiRoot, { - '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['~imdb'].regex = [/^imdb (.+)$/, 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) { - return new imdb(dbot); -}; diff --git a/modules/rt/README.md b/modules/rt/README.md new file mode 100644 index 0000000..18c32f8 --- /dev/null +++ b/modules/rt/README.md @@ -0,0 +1,33 @@ +## RT + +Adds various RottenTomatoes functionalities. + +### Description + +This module provides a command which allows users to search RT for a movie. + +### Dependencies + +It has following dependencies: ++ [request](https://github.com/mikeal/request) + +### config.json + +output prefix can be set, and an API key must be obtained from +http://developer.rottentomatoes.com/ +``` +{ + "outputPrefix": "\u00033RT\u000f" +} + +``` + +### Commands + + +#### ~rt [movie] +Searches IMDB for a movie. +Example: ++ ~rt Fear and Loathing in Las Vegas + +### TODO diff --git a/modules/rt/config.json b/modules/rt/config.json new file mode 100644 index 0000000..bcbd70b --- /dev/null +++ b/modules/rt/config.json @@ -0,0 +1,4 @@ +{ + "outputPrefix": "\u00033RT\u000f", + "api_key": "http://developer.rottentomatoes.com" +} diff --git a/modules/rt/rt.js b/modules/rt/rt.js new file mode 100644 index 0000000..ca70c70 --- /dev/null +++ b/modules/rt/rt.js @@ -0,0 +1,60 @@ +/** + * Module Name: RT + * Description: Various RT 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; + var rColour = (rating <= 5) ? '\u00033 ' : '\u00034 '; + rating = rColour + String(rating) + '%\u000f'; + + var mString = dbot.t('rt_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, 'synopsis') && m.synopsis != '') { + mString += ' [Synopsis: ' + m.synopsis + ']'; + } else if(_.has(m, 'critics_consensus')) { + mString += ' [Review: ' + m.critics_consensus + ']'; + } + mString += ' - ' + m.links.alternate; + + return mString; + } + }; + + this.commands = { + '~rt': function(event) { + request.get(ApiRoot + 'movies.json', { + 'qs': { + 'q': event.input[1], + 'page_limit': 1, + 'apikey': this.config.api_key + }, + 'json': true + }, function(error, response, body) { + if(_.isObject(body) && _.has(body, 'movies') && !_.isUndefined(body.movies[0])) { + event.reply(this.internalAPI.formatLink(body.movies[0])); + } else { + event.reply(dbot.t('rt_noresults')); + } + }.bind(this)); + } + }; + this.commands['~rt'].regex = [/^rt (.+)$/, 2]; +}; + +exports.fetch = function(dbot) { + return new rt(dbot); +}; diff --git a/modules/imdb/strings.json b/modules/rt/strings.json similarity index 80% rename from modules/imdb/strings.json rename to modules/rt/strings.json index 9fb2ecd..db1f16b 100644 --- a/modules/imdb/strings.json +++ b/modules/rt/strings.json @@ -1,9 +1,9 @@ { - "imdb_film": { + "rt_film": { "en": "[{title} -{rating} - {year}]", "de": "[{title} -{rating} - {year}]" }, - "imdb_noresults": { + "rt_noresults": { "en": "No films found.", "de": "Kein Film gefunden." }