Change to Films

This commit is contained in:
Daniel Odendahl Jr
2017-09-24 16:51:10 +00:00
parent 5495f06897
commit d8bf936780
+14 -24
View File
@@ -1,20 +1,21 @@
const Command = require('../../structures/Command'); const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js'); const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch'); const snekfetch = require('snekfetch');
const { shorten } = require('../../structures/Util');
module.exports = class GhibliCommand extends Command { module.exports = class GhibliCommand extends Command {
constructor(client) { constructor(client) {
super(client, { super(client, {
name: 'ghibli', name: 'ghibli',
aliases: ['studio-ghibli', 'ghibli-person', 'studio-ghibli-person'], aliases: ['studio-ghibli'],
group: 'search', group: 'search',
memberName: 'ghibli', memberName: 'ghibli',
description: 'Searches Studio Ghibli people for your query.', description: 'Searches Studio Ghibli films for your query.',
clientPermissions: ['EMBED_LINKS'], clientPermissions: ['EMBED_LINKS'],
args: [ args: [
{ {
key: 'query', key: 'query',
prompt: 'What person would you like to search for?', prompt: 'What film would you like to search for?',
type: 'string' type: 'string'
} }
] ]
@@ -24,32 +25,21 @@ module.exports = class GhibliCommand extends Command {
async run(msg, { query }) { async run(msg, { query }) {
try { try {
const { body } = await snekfetch const { body } = await snekfetch
.get('http://ghibliapi.herokuapp.com/people') .get('http://ghibliapi.herokuapp.com/films')
.query({ name: query }); .query({ title: query });
if (!body.length) return msg.say('Could not find any results.'); if (!body.length) return msg.say('Could not find any results.');
const data = body[0]; const data = body[0];
const species = await snekfetch.get(data.species);
const films = [];
for (const film of data.films) {
const movie = await snekfetch.get(film);
films.push(movie.body);
}
const embed = new MessageEmbed() const embed = new MessageEmbed()
.setColor(0xE7E7E7) .setColor(0xE7E7E7)
.setAuthor('Studio Ghibli', 'https://i.imgur.com/P3YafQ3.jpg') .setAuthor('Studio Ghibli', 'https://i.imgur.com/P3YafQ3.jpg')
.setTitle(data.name) .setTitle(data.title)
.addField(' Gender', .setDescription(shorten(data.description))
data.gender || 'N/A', true) .addField(' Release Year',
.addField(' Age', data.release_date || 'N/A', true)
data.age || 'N/A', true) .addField(' Director',
.addField(' Species', data.director || 'N/A', true)
species.body.name || 'N/A', true) .addField(' Rotten Tomatoes Score',
.addField(' Eye Color', data.rt_score ? `${data.rt_score}%` : 'N/A', true);
data.eye_color || 'N/A', true)
.addField(' Hair Color',
data.hair_color || 'N/A', true)
.addField(' Films',
films.map(film => film.title).join('\n') || 'N/A', true);
return msg.embed(embed); return msg.embed(embed);
} catch (err) { } catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);