From 1b09d8843cba6aeac8e317be568ceb3878eae2d0 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sun, 24 Sep 2017 20:10:22 +0000 Subject: [PATCH] Rotten Tomatoes Command --- commands/search/rotten-tomatoes.js | 49 ++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 commands/search/rotten-tomatoes.js diff --git a/commands/search/rotten-tomatoes.js b/commands/search/rotten-tomatoes.js new file mode 100644 index 00000000..57d8ac65 --- /dev/null +++ b/commands/search/rotten-tomatoes.js @@ -0,0 +1,49 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const snekfetch = require('snekfetch'); + +module.exports = class RottenTomatoesCommand extends Command { + constructor(client) { + super(client, { + name: 'rotten-tomatoes', + aliases: ['tomato-meter'], + group: 'search', + memberName: 'rotten-tomatoes', + description: 'Searches Rotten Tomatoes for your query.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'query', + prompt: 'What movie would you like to search for?', + type: 'string' + } + ] + }); + } + + async run(msg, { query }) { + try { + const { body } = 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]; + const embed = new MessageEmbed() + .setColor(0xFFEC02) + .setTitle(data.name) + .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); + 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 c2bff5b6..a098ed0d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "42.9.0", + "version": "42.10.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {