From b3ff627c177156ac6915df38100774a79229f3be Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sun, 2 Apr 2017 03:02:52 +0000 Subject: [PATCH] Change IMDB to Manual Request Beta --- commands/search/image.js | 2 +- commands/search/imdb.js | 44 +++++++++++++++++++++----------------- commands/search/osu.js | 2 +- commands/search/wattpad.js | 2 +- commands/textedit/yoda.js | 4 ++-- package.json | 1 - 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/commands/search/image.js b/commands/search/image.js index 30ddf228..dd4c3eac 100644 --- a/commands/search/image.js +++ b/commands/search/image.js @@ -31,7 +31,7 @@ module.exports = class ImageSearchCommand extends commando.Command { let searchMsg = await message.say('Searching...'); try { let response = await request - .get(`https://www.google.com/search?tbm=isch&gs_l=img&q=${encodeURI(thingToSearch)}`); + .get(`https://www.google.com/search?tbm=isch&gs_l=img&q=${thingToSearch}`); const $ = cheerio.load(response.text); const result = $('.images_table').find('img').first().attr('src'); return searchMsg.edit(result); diff --git a/commands/search/imdb.js b/commands/search/imdb.js index a177aa85..84aefab1 100644 --- a/commands/search/imdb.js +++ b/commands/search/imdb.js @@ -1,6 +1,6 @@ const commando = require('discord.js-commando'); const Discord = require('discord.js'); -const imdb = require('imdb-api'); +const request = require('superagent'); module.exports = class IMDBCommand extends commando.Command { constructor(Client) { @@ -23,39 +23,43 @@ module.exports = class IMDBCommand extends commando.Command { }); } - run(message, args) { + async run(message, args) { if (message.channel.type !== 'dm') { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES', 'EMBED_LINKS'])) return; } console.log(`[Command] ${message.content}`); - let queryMovie = args.movie; - let movie; - imdb.getReq({ - name: queryMovie - }, (err, response) => { - movie = response; - if (!movie) return message.say(":x: Error! Movie not found!"); + let queryMovie = encodeURI(args.movie); + try { + let response = await request + .get(`http://www.omdbapi.com/`) + .query({ + t: queryMovie, + plot: 'full' + }); const embed = new Discord.RichEmbed() .setColor(0xDBA628) .setAuthor('IMDB', 'http://static.wixstatic.com/media/c65cbf_31901b544fe24f1890134553bf40c8be.png') - .setURL(movie.imdburl) - .setTitle(`${movie.title} (${movie.rating} Score)`) - .setDescription(`${movie.plot.substr(0, 1500)} [Read the Rest Here!](${movie.imdburl})`) + .setURL(`http://www.imdb.com/title/${response.body.imdbID}`) + .setTitle(`${response.body.Title} (${response.body.imdbRating} Score)`) + .setDescription(`${response.body.Plot.substr(0, 1500)} [Read the Rest Here!](http://www.imdb.com/title/${response.body.imdbID})`) .addField('**Genres:**', - movie.genres) + response.body.Genre) .addField('**Year:**', - movie.year, true) + response.body.Year, true) .addField('**Rated:**', - movie.rated, true) + response.body.Rated, true) .addField('**Runtime:**', - movie.runtime, true) + response.body.Runtime, true) .addField('**Directors:**', - movie.director) + response.body.Director) .addField('**Writers:**', - movie.writer) + response.body.Writer) .addField('**Actors:**', - movie.actors); + response.body.Actors); return message.embed(embed); - }); + } + catch (err) { + return message.say(':x: Error! Movie not found!'); + } } }; diff --git a/commands/search/osu.js b/commands/search/osu.js index 3afcc031..a975dca6 100644 --- a/commands/search/osu.js +++ b/commands/search/osu.js @@ -29,7 +29,7 @@ module.exports = class OsuCommand extends commando.Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES', 'EMBED_LINKS'])) return; } console.log(`[Command] ${message.content}`); - let usernameToSearch = args.username; + let usernameToSearch = encodeURI(args.username); try { let response = await request .get('https://osu.ppy.sh/api/get_user') diff --git a/commands/search/wattpad.js b/commands/search/wattpad.js index 63a184da..59e3d9c9 100644 --- a/commands/search/wattpad.js +++ b/commands/search/wattpad.js @@ -24,7 +24,7 @@ module.exports = class WattpadCommand extends commando.Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES', 'EMBED_LINKS'])) return; } console.log(`[Command] ${message.content}`); - let queryBook = args.book; + let queryBook = encodeURI(args.book); try { let response = await request .get('https://api.wattpad.com:443/v4/stories') diff --git a/commands/textedit/yoda.js b/commands/textedit/yoda.js index c568ba73..47794b9a 100644 --- a/commands/textedit/yoda.js +++ b/commands/textedit/yoda.js @@ -23,7 +23,7 @@ module.exports = class YodaCommand extends commando.Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; } console.log(`[Command] ${message.content}`); - let turnToYoda = args.text; + let turnToYoda = encodeURI(args.text); try { let response = await request .get('https://yoda.p.mashape.com/yoda') @@ -32,7 +32,7 @@ module.exports = class YodaCommand extends commando.Command { 'Accept': 'text/plain' }) .query({ - sentence: encodeURI(turnToYoda) + sentence: turnToYoda }); if (!response.text) return message.say(':x: Error! Something went wrong! Keep it simple to avoid this error.'); return message.say(response.text); diff --git a/package.json b/package.json index 635547e0..f39d79f9 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ "discord.js-commando": "gawdl3y/discord.js-commando", "google-translate-api": "^2.2.2", "hepburn": "^1.0.0", - "imdb-api": "^2.2.1", "jimp": "^0.2.27", "mathjs": "^3.10.0", "moment": "^2.17.1",