Better Validators and More Destucturing

This commit is contained in:
Daniel Odendahl Jr
2017-04-19 18:55:26 +00:00
parent c064401b37
commit d77f71b66a
40 changed files with 114 additions and 124 deletions
+7 -8
View File
@@ -30,24 +30,23 @@ module.exports = class BotSearchCommand extends Command {
let { bot } = args;
bot = bot.id;
try {
const response = await request
const { body } = await request
.get(`https://bots.discord.pw/api/bots/${bot}`)
.set({
'Authorization': process.env.DISCORD_BOTS_KEY
});
const data = response.body;
const embed = new RichEmbed()
.setColor(0x9797FF)
.setAuthor('Discord Bots', 'https://cdn.discordapp.com/icons/110373943822540800/47336ad0631ac7aac0a48a2ba6246c65.jpg')
.setTitle(data.name)
.setTitle(body.name)
.setURL('https://bots.discord.pw/')
.setDescription(data.description)
.setDescription(body.description)
.addField('**Library:**',
data.library, true)
.addField('**Prefix:**',
data.prefix, true)
body.library, true)
.addField('**Invite:**',
`[Here](${data.invite_url})`, true);
`[Here](${body.invite_url})`, true)
.addField('**Prefix:**',
body.prefix, true);
return message.embed(embed);
} catch (err) {
return message.say(':x: Error! Bot not Found!');
+2 -2
View File
@@ -34,9 +34,9 @@ module.exports = class DefineCommand extends Command {
}
const { word } = args;
try {
const response = await request
const { body } = await request
.get(`http://api.wordnik.com:80/v4/word.json/${word}/definitions?limit=1&includeRelated=false&useCanonical=false&api_key=${process.env.WORDNIK_KEY}`);
const data = response.body[0];
const data = body[0];
const embed = new RichEmbed()
.setColor(0x9797FF)
.setTitle(data.word)
+1 -1
View File
@@ -21,7 +21,7 @@ module.exports = class DiscrimCommand extends Command {
if (discrim.match(/^[0-9]+$/) && discrim.length === 4) {
return true;
}
return 'Invalid discriminator.';
return `${discrim} is not a valid discriminator.`;
}
}]
});
+2 -2
View File
@@ -28,9 +28,9 @@ module.exports = class ForecastCommand extends Command {
}
const { location } = args;
try {
const response = await request
const { body } = await request
.get(`https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where u=\'f\' AND woeid in (select woeid from geo.places(1) where text="${location}")&format=json`);
const info = response.body.query.results.channel;
const info = body.query.results.channel;
const data = info.item.forecast;
const embed = new RichEmbed()
.setColor(0x0000FF)
+2 -2
View File
@@ -32,9 +32,9 @@ module.exports = class GoogleCommand extends Command {
const { query } = args;
const msg = await message.say('Searching...');
try {
const response = await request
const { text } = await request
.get(`https://www.google.com/search?q=${query}`);
const $ = cheerio.load(response.text);
const $ = cheerio.load(text);
let href = $('.r').first().find('a').first().attr('href');
href = querystring.parse(href.replace('/url?', ''));
return msg.edit(href.q);
+13 -13
View File
@@ -9,7 +9,8 @@ module.exports = class IMDBCommand extends Command {
aliases: [
'movie',
'tvshow',
'film'
'film',
'omdb'
],
group: 'search',
memberName: 'imdb',
@@ -33,29 +34,28 @@ module.exports = class IMDBCommand extends Command {
}
const { movie } = args;
try {
const response = await request
const { body } = await request
.get(`http://www.omdbapi.com/?t=${movie}&plot=full`);
const data = response.body;
const embed = new RichEmbed()
.setColor(0xDBA628)
.setAuthor('IMDB', 'http://static.wixstatic.com/media/c65cbf_31901b544fe24f1890134553bf40c8be.png')
.setURL(`http://www.imdb.com/title/${data.imdbID}`)
.setTitle(`${data.Title} (${data.imdbRating} Score)`)
.setDescription(data.Plot.substr(0, 1900))
.setURL(`http://www.imdb.com/title/${body.imdbID}`)
.setTitle(`${body.Title} (${body.imdbRating} Score)`)
.setDescription(body.Plot.substr(0, 2000))
.addField('**Genres:**',
data.Genre)
body.Genre)
.addField('**Year:**',
data.Year, true)
body.Year, true)
.addField('**Rated:**',
data.Rated, true)
body.Rated, true)
.addField('**Runtime:**',
data.Runtime, true)
body.Runtime, true)
.addField('**Directors:**',
data.Director)
body.Director)
.addField('**Writers:**',
data.Writer)
body.Writer)
.addField('**Actors:**',
data.Actors);
body.Actors);
return message.embed(embed);
} catch (err) {
return message.say(':x: Error! Movie not found!');
+2 -2
View File
@@ -40,9 +40,9 @@ module.exports = class MapCommand extends Command {
}
const { zoom, location } = args;
try {
const response = await request
const { body } = await request
.get(`https://maps.googleapis.com/maps/api/staticmap?center=${location}&zoom=${zoom}&size=500x500&key=${process.env.GOOGLE_KEY}`);
return message.channel.send({file: {attachment: response.body}});
return message.channel.send({file: {attachment: body}});
} catch (err) {
return message.say(':x: Error! Something went wrong! Make sure you entered the location correctly!');
}
+2 -2
View File
@@ -28,9 +28,9 @@ module.exports = class NeopetCommand extends Command {
}
const { pet } = args;
try {
const response = await request
const { text } = await request
.get(`http://www.sunnyneo.com/petimagefinder.php?name=${pet}&size=5&mood=1`);
const $ = cheerio.load(response.text);
const $ = cheerio.load(text);
const link = $('textarea').first().text();
if (!link.includes('cp')) return message.say(':x: Error! Pet not found!');
return message.say(link);
+2 -2
View File
@@ -33,9 +33,9 @@ module.exports = class OsuCommand extends Command {
}
const { username } = args;
try {
const response = await request
const { body } = await request
.get(`https://osu.ppy.sh/api/get_user?k=${process.env.OSU_KEY}&u=${username}&type=string`);
const data = response.body[0];
const data = body[0];
const embed = new RichEmbed()
.setColor(0xFF66AA)
.setAuthor('osu!', 'http://vignette3.wikia.nocookie.net/osugame/images/c/c9/Logo.png/revision/latest?cb=20151219073209')
+4 -4
View File
@@ -33,17 +33,17 @@ module.exports = class UrbanCommand extends Command {
}
const { word } = args;
try {
const response = await request
const { body } = await request
.get(`http://api.urbandictionary.com/v0/define?term=${word}`);
const data = response.body.list[0];
const data = body.list[0];
const embed = new RichEmbed()
.setColor(0x32a8f0)
.setAuthor('Urban Dictionary', 'http://a1.mzstatic.com/eu/r30/Purple71/v4/66/54/68/6654683f-cacd-4a55-1784-f14257f77874/icon175x175.png')
.setURL(data.permalink)
.setTitle(data.word)
.setDescription(data.definition.substr(0, 1900))
.setDescription(data.definition.substr(0, 2000))
.addField('**Example:**',
data.example.substr(0, 1900) || 'None');
data.example.substr(0, 2000) || 'None');
return message.embed(embed);
} catch (err) {
return message.say(':x: Error! Word not found!');
+3 -3
View File
@@ -28,18 +28,18 @@ module.exports = class WattpadCommand extends Command {
}
const { book } = args;
try {
const response = await request
const { body } = await request
.get(`https://api.wattpad.com:443/v4/stories?query=${book}&limit=1`)
.set({
'Authorization': `Basic ${process.env.WATTPAD_KEY}`
});
const data = response.body.stories[0];
const data = body.stories[0];
const embed = new RichEmbed()
.setColor(0xF89C34)
.setAuthor('Wattpad', 'http://www.selfpubtoolbox.com/wp-content/uploads/2015/05/a6044fd3a88acd5043860484db972ca6.png')
.setURL(data.url)
.setTitle(data.title)
.setDescription(data.description.substr(0, 1500))
.setDescription(data.description.substr(0, 2000))
.addField('**Author:**',
data.user, true)
.addField('**Parts:**',
+2 -2
View File
@@ -25,9 +25,9 @@ module.exports = class WeatherCommand extends Command {
}
const { location } = args;
try {
const response = await request
const { body } = await request
.get(`https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where u=\'f\' AND woeid in (select woeid from geo.places(1) where text="${location}")&format=json`);
const data = response.body.query.results.channel;
const data = body.query.results.channel;
const embed = new RichEmbed()
.setColor(0x0000FF)
.setAuthor(data.title, 'http://media.idownloadblog.com/wp-content/uploads/2013/12/yahoo-weather-213x220.png')
+3 -3
View File
@@ -28,10 +28,10 @@ module.exports = class WikipediaCommand extends Command {
}
const { query } = args;
try {
const response = await request
const { body } = await request
.get(`https://en.wikipedia.org/w/api.php?action=query&prop=extracts&format=json&titles=${query}&exintro=&explaintext=&redirects=&formatversion=2`);
const data = response.body.query.pages[0];
const description = data.extract.substr(0, 1900).split('\n').join('\n\n');
const data = body.query.pages[0];
const description = data.extract.substr(0, 2000).split('\n').join('\n\n');
const embed = new RichEmbed()
.setColor(0xE7E7E7)
.setTitle(data.title)
+2 -2
View File
@@ -31,9 +31,9 @@ module.exports = class YouTubeCommand extends Command {
}
const { video } = args;
try {
const response = await request
const { body } = await request
.get(`https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&maxResults=1&q=${video}&key=${process.env.GOOGLE_KEY}`);
const data = response.body.items[0];
const data = body.items[0];
const embed = new RichEmbed()
.setColor(0xDD2825)
.setTitle(data.snippet.title)
+2 -2
View File
@@ -28,9 +28,9 @@ module.exports = class YuGiOhCommand extends Command {
}
const { card } = args;
try {
const response = await request
const { body } = await request
.get(`http://yugiohprices.com/api/card_data/${card}`);
const data = response.body.data;
const data = body.data;
if (data.card_type === 'monster') {
const embed = new RichEmbed()
.setColor(0xBE5F1F)