From 928e3b503bbe0f82d8634281197fbf8602c2344f Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sun, 24 Sep 2017 21:36:54 +0000 Subject: [PATCH] Beep --- commands/search/rotten-tomatoes.js | 23 ++++++++++++++--------- package.json | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/commands/search/rotten-tomatoes.js b/commands/search/rotten-tomatoes.js index 57d8ac65..e41989d8 100644 --- a/commands/search/rotten-tomatoes.js +++ b/commands/search/rotten-tomatoes.js @@ -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!`); diff --git a/package.json b/package.json index a098ed0d..2f8554e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "42.10.0", + "version": "42.10.1", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {