Files
xiao/commands/search/imdb.js
T
Daniel Odendahl Jr 82d3c6eeca Local Storage
2017-05-13 18:15:37 +00:00

58 lines
2.1 KiB
JavaScript

const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js');
const request = require('superagent');
module.exports = class IMDBCommand extends Command {
constructor(client) {
super(client, {
name: 'imdb',
group: 'search',
memberName: 'imdb',
description: 'Searches IMDB for a specified movie.',
args: [
{
key: 'query',
prompt: 'What movie or TV Show would you like to search for?',
type: 'string',
parse: query => encodeURIComponent(query)
}
]
});
}
async run(msg, args) {
if (msg.channel.type !== 'dm')
if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS'))
return msg.say('This Command requires the `Embed Links` Permission.');
const { query } = args;
try {
const { body } = await request
.get(`http://www.omdbapi.com/?t=${query}&plot=full`);
if (body.Error) throw new Error('No Results.');
const embed = new RichEmbed()
.setColor(0xDBA628)
.setAuthor('IMDB', 'https://i.imgur.com/sXwwIQs.png')
.setURL(`http://www.imdb.com/title/${body.imdbID}`)
.setTitle(`${body.Title} (${body.imdbRating} Score)`)
.setDescription(body.Plot.substr(0, 2000))
.addField('Genres',
body.Genre)
.addField('Year',
body.Year, true)
.addField('Rated',
body.Rated, true)
.addField('Runtime',
body.Runtime, true)
.addField('Directors',
body.Director)
.addField('Writers',
body.Writer)
.addField('Actors',
body.Actors);
return msg.embed(embed);
} catch (err) {
return msg.say(err);
}
}
};