Files
xiao/commands/search/imdb.js
T
Daniel Odendahl Jr cf87f126d6 Make Code Prettier
2017-05-04 02:40:56 +00:00

57 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`);
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('An Error Occurred. The film may not have been found.');
}
}
};