From b1f5dbef2478c888e3e78128337a5aec3fa442b8 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sun, 20 Aug 2017 20:29:42 +0000 Subject: [PATCH] Movie, TV Show, Yoda Commands --- commands/search/movie.js | 55 +++++++++++++++++++++++++++++++++++ commands/search/tv-show.js | 59 ++++++++++++++++++++++++++++++++++++++ commands/text-edit/yoda.js | 35 ++++++++++++++++++++++ package.json | 2 +- 4 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 commands/search/movie.js create mode 100644 commands/search/tv-show.js create mode 100644 commands/text-edit/yoda.js diff --git a/commands/search/movie.js b/commands/search/movie.js new file mode 100644 index 00000000..d2cd3614 --- /dev/null +++ b/commands/search/movie.js @@ -0,0 +1,55 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const snekfetch = require('snekfetch'); +const { TMDB_KEY } = process.env; + +module.exports = class MovieCommand extends Command { + constructor(client) { + super(client, { + name: 'movie', + aliases: ['tmdb-movie'], + group: 'search', + memberName: 'movie', + description: 'Searches TMDB for your query, getting movie results.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'query', + prompt: 'What would you like to search for?', + type: 'string' + } + ] + }); + } + + async run(msg, args) { + const { query } = args; + const search = await snekfetch + .get('http://api.themoviedb.org/3/search/movie') + .query({ + api_key: TMDB_KEY, + include_adult: msg.channel.nsfw ? true : false, + query + }); + if (!search.body.results.length) return msg.say('No Results.'); + const { body } = await snekfetch + .get(`https://api.themoviedb.org/3/movie/${search.body.results[0].id}`) + .query({ api_key: TMDB_KEY }); + const embed = new MessageEmbed() + .setColor(0x00D474) + .setTitle(body.title) + .setURL(`https://www.themoviedb.org/movie/${body.id}`) + .setAuthor('TMDB', 'https://i.imgur.com/G9q4DF1.png') + .setDescription(body.overview.substr(0, 2048)) + .setThumbnail(body.poster_path ? `https://image.tmdb.org/t/p/w500${body.poster_path}` : null) + .addField('❯ Runtime', + `${body.runtime} mins.`, true) + .addField('❯ Release Date', + body.release_date, true) + .addField('❯ Genres', + body.genres.map(genre => genre.name).join(', ')) + .addField('❯ Production Companies', + body.production_companies.length ? body.production_companies.map(company => company.name).join(', ') : 'N/A'); + return msg.embed(embed); + } +}; diff --git a/commands/search/tv-show.js b/commands/search/tv-show.js new file mode 100644 index 00000000..b0f875d9 --- /dev/null +++ b/commands/search/tv-show.js @@ -0,0 +1,59 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const snekfetch = require('snekfetch'); +const { TMDB_KEY } = process.env; + +module.exports = class TVShowCommand extends Command { + constructor(client) { + super(client, { + name: 'tv-show', + aliases: ['tmdb-tv-show', 'tv', 'tmdb-tv'], + group: 'search', + memberName: 'tv-show', + description: 'Searches TMDB for your query, getting TV show results.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'query', + prompt: 'What would you like to search for?', + type: 'string' + } + ] + }); + } + + async run(msg, args) { + const { query } = args; + const search = await snekfetch + .get('http://api.themoviedb.org/3/search/tv') + .query({ + api_key: TMDB_KEY, + include_adult: msg.channel.nsfw ? true : false, + query + }); + if (!search.body.results.length) return msg.say('No Results.'); + const { body } = await snekfetch + .get(`https://api.themoviedb.org/3/tv/${search.body.results[0].id}`) + .query({ api_key: TMDB_KEY }); + const embed = new MessageEmbed() + .setColor(0x00D474) + .setTitle(body.name) + .setURL(`https://www.themoviedb.org/tv/${body.id}`) + .setAuthor('TMDB', 'https://i.imgur.com/G9q4DF1.png') + .setDescription(body.overview.substr(0, 2048)) + .setThumbnail(body.poster_path ? `https://image.tmdb.org/t/p/w500${body.poster_path}` : null) + .addField('❯ First Air Date', + body.first_air_date, true) + .addField('❯ Last Air Date', + body.last_air_date, true) + .addField('❯ Seasons', + body.number_of_seasons, true) + .addField('❯ Episodes', + body.number_of_episodes, true) + .addField('❯ Genres', + body.genres.map(genre => genre.name).join(', ')) + .addField('❯ Production Companies', + body.production_companies.length ? body.production_companies.map(company => company.name).join(', ') : 'N/A'); + return msg.embed(embed); + } +}; diff --git a/commands/text-edit/yoda.js b/commands/text-edit/yoda.js new file mode 100644 index 00000000..93b42aa5 --- /dev/null +++ b/commands/text-edit/yoda.js @@ -0,0 +1,35 @@ +const Command = require('../../structures/Command'); +const snekfetch = require('snekfetch'); +const { MASHAPE_KEY } = process.env; + +module.exports = class YodaCommand extends Command { + constructor(client) { + super(client, { + name: 'yoda', + aliases: ['yoda-speak'], + group: 'text-edit', + memberName: 'yoda', + description: 'Converts text to Yoda speak.', + args: [ + { + key: 'sentence', + prompt: 'What text would you like to convert to Yoda speak?', + type: 'string', + validate: sentence => { + if (sentence.length < 500) return true; + return 'Text must be under 500 characters.'; + } + } + ] + }); + } + + async run(msg, args) { + const { sentence } = args; + const { text } = await snekfetch + .get('https://yoda.p.mashape.com/yoda') + .query({ sentence }) + .set({ 'X-Mashape-Key': MASHAPE_KEY }); + return msg.say(text); + } +}; diff --git a/package.json b/package.json index b6023d6b..27413a80 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "30.6.1", + "version": "30.7.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {