This commit is contained in:
Daniel Odendahl Jr
2017-09-24 21:36:54 +00:00
parent 1b09d8843c
commit 928e3b503b
2 changed files with 15 additions and 10 deletions
+14 -9
View File
@@ -1,6 +1,7 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const { shorten } = require('../../structures/Util');
module.exports = class RottenTomatoesCommand extends Command {
constructor(client) {
@@ -23,24 +24,28 @@ module.exports = class RottenTomatoesCommand extends Command {
async run(msg, { query }) {
try {
const { body } = await snekfetch
const search = await snekfetch
.get('https://www.rottentomatoes.com/api/private/v2.0/search/')
.query({
limit: 10,
q: query
});
if (!body.movies.length) return msg.say('Could not find any results.');
const data = body.movies.find(movie => movie.name.toLowerCase() === query.toLowerCase()) || body.movies[0];
if (!search.body.movies.length) return msg.say('Could not find any results.');
const find = search.body.movies.find(m => m.name.toLowerCase() === query.toLowerCase()) || search.body.movies[0];
const { text } = await snekfetch
.get(`https://www.rottentomatoes.com/api/private/v1.0/movies/${find.url.replace('/m/', '')}`);
const data = JSON.parse(text);
const embed = new MessageEmbed()
.setColor(0xFFEC02)
.setTitle(data.name)
.setTitle(`${data.title} (${data.year})`)
.setURL(`https://www.rottentomatoes.com${data.url}`)
.setAuthor('Rotten Tomatoes', 'https://i.imgur.com/YPRQvX8.jpg')
.setThumbnail(data.image || null)
.addField(' Tomatometer',
data.meterScore ? `${data.meterScore}%` : 'N/A', true)
.addField(' Year',
data.year || 'N/A', true);
.setDescription(shorten(data.ratingSummary.consensus))
.setThumbnail(data.posters.original)
.addField(' Critic Score',
data.ratings.critics_score !== -1 ? `${data.ratings.critics_score}%` : 'N/A', true)
.addField(' Audience Score',
data.ratings.audience_score !== -1 ? `${data.ratings.audience_score}%` : 'N/A', true);
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "42.10.0",
"version": "42.10.1",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {