From d77f71b66aee6683d2211f3f41708a94ecdc870f Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Wed, 19 Apr 2017 18:55:26 +0000 Subject: [PATCH] Better Validators and More Destucturing --- commands/avataredit/3000years.js | 4 +--- commands/avataredit/beautiful.js | 4 +--- commands/avataredit/bobross.js | 4 +--- commands/avataredit/rip.js | 4 +--- commands/avataredit/steamcard.js | 7 ++----- commands/games/lottery.js | 5 ++--- commands/games/quiz.js | 4 ++-- commands/games/slots.js | 7 +++---- commands/imageedit/meme.js | 6 +++--- commands/moderation/ban.js | 4 ++-- commands/moderation/kick.js | 4 ++-- commands/moderation/lockdown.js | 2 +- commands/moderation/prune.js | 2 +- commands/moderation/unban.js | 6 +++--- commands/moderation/warn.js | 4 ++-- commands/random/strawpoll.js | 21 +++++++++++++-------- commands/random/today.js | 10 +++++----- commands/random/wouldyourather.js | 9 ++++----- commands/search/botinfo.js | 15 +++++++-------- commands/search/define.js | 4 ++-- commands/search/discrim.js | 2 +- commands/search/forecast.js | 4 ++-- commands/search/google.js | 4 ++-- commands/search/imdb.js | 26 +++++++++++++------------- commands/search/map.js | 4 ++-- commands/search/neopet.js | 4 ++-- commands/search/osu.js | 4 ++-- commands/search/urban.js | 8 ++++---- commands/search/wattpad.js | 6 +++--- commands/search/weather.js | 4 ++-- commands/search/wikipedia.js | 6 +++--- commands/search/youtube.js | 4 ++-- commands/search/yugioh.js | 4 ++-- commands/textedit/binary.js | 6 +++--- commands/textedit/cowsay.js | 2 +- commands/textedit/morse.js | 4 ++-- commands/textedit/pirate.js | 6 +++--- commands/textedit/temmie.js | 6 +++--- commands/textedit/zalgo.js | 6 +++--- package.json | 2 +- 40 files changed, 114 insertions(+), 124 deletions(-) diff --git a/commands/avataredit/3000years.js b/commands/avataredit/3000years.js index 28d49390..228203b7 100644 --- a/commands/avataredit/3000years.js +++ b/commands/avataredit/3000years.js @@ -26,9 +26,7 @@ module.exports = class YearsCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission('ATTACH_FILES')) return message.say(':x: Error! I don\'t have the Attach Files Permission!'); } const { user } = args; - let userAvatar = user.displayAvatarURL; - userAvatar = userAvatar.replace('.jpg', '.png'); - userAvatar = userAvatar.replace('.gif', '.png'); + const userAvatar = user.displayAvatarURL.replace('.jpg', '.png').replace('.gif', '.png'); let images = []; images.push(Jimp.read(userAvatar)); images.push(Jimp.read('./images/3000years.png')); diff --git a/commands/avataredit/beautiful.js b/commands/avataredit/beautiful.js index e2a528b0..2c62d12b 100644 --- a/commands/avataredit/beautiful.js +++ b/commands/avataredit/beautiful.js @@ -26,9 +26,7 @@ module.exports = class BeautifulCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission('ATTACH_FILES')) return message.say(':x: Error! I don\'t have the Attach Files Permission!'); } const { user } = args; - let userAvatar = user.displayAvatarURL; - userAvatar = userAvatar.replace('.jpg', '.png'); - userAvatar = userAvatar.replace('.gif', '.png'); + const userAvatar = user.displayAvatarURL.replace('.jpg', '.png').replace('.gif', '.png'); let images = []; images.push(Jimp.read(userAvatar)); images.push(Jimp.read('./images/beautiful.jpg')); diff --git a/commands/avataredit/bobross.js b/commands/avataredit/bobross.js index f9ffa82a..8c6fe086 100644 --- a/commands/avataredit/bobross.js +++ b/commands/avataredit/bobross.js @@ -27,9 +27,7 @@ module.exports = class BobRossCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission('ATTACH_FILES')) return message.say(':x: Error! I don\'t have the Attach Files Permission!'); } const { user } = args; - let userAvatar = user.displayAvatarURL; - userAvatar = userAvatar.replace('.jpg', '.png'); - userAvatar = userAvatar.replace('.gif', '.png'); + const userAvatar = user.displayAvatarURL.replace('.jpg', '.png').replace('.gif', '.png'); let images = []; images.push(Jimp.read(userAvatar)); images.push(Jimp.read('./images/BobRoss.png')); diff --git a/commands/avataredit/rip.js b/commands/avataredit/rip.js index a0d994cd..89f88382 100644 --- a/commands/avataredit/rip.js +++ b/commands/avataredit/rip.js @@ -27,9 +27,7 @@ module.exports = class RIPCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission('ATTACH_FILES')) return message.say(':x: Error! I don\'t have the Attach Files Permission!'); } const { user } = args; - let userAvatar = user.displayAvatarURL; - userAvatar = userAvatar.replace('.jpg', '.png'); - userAvatar = userAvatar.replace('.gif', '.png'); + const userAvatar = user.displayAvatarURL.replace('.jpg', '.png').replace('.gif', '.png'); let images = []; images.push(Jimp.read(userAvatar)); images.push(Jimp.read('./images/gravestone.jpg')); diff --git a/commands/avataredit/steamcard.js b/commands/avataredit/steamcard.js index 7beb25da..7347eb08 100644 --- a/commands/avataredit/steamcard.js +++ b/commands/avataredit/steamcard.js @@ -26,10 +26,7 @@ module.exports = class SteamCardCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission('ATTACH_FILES')) return message.say(':x: Error! I don\'t have the Attach Files Permission!'); } const { user } = args; - const userDisplayName = user.username; - let userAvatar = user.displayAvatarURL; - userAvatar = userAvatar.replace('.jpg', '.png'); - userAvatar = userAvatar.replace('.gif', '.png'); + const userAvatar = user.displayAvatarURL.replace('.jpg', '.png').replace('.gif', '.png'); let images = []; images.push(Jimp.read(userAvatar)); images.push(Jimp.read('./images/SteamCard.png')); @@ -39,7 +36,7 @@ module.exports = class SteamCardCommand extends Command { avatar.resize(450, 450); nothing.composite(avatar, 25, 25); nothing.composite(steamcard, 0, 0); - nothing.print(font, 38, 20, userDisplayName); + nothing.print(font, 38, 20, user.username); nothing.getBuffer(Jimp.MIME_PNG, (err, buff) => { if (err) return message.say(':x: Error! Something went wrong!'); return message.channel.send({file: {attachment: buff}}); diff --git a/commands/games/lottery.js b/commands/games/lottery.js index a5225e9b..d0e5dfed 100644 --- a/commands/games/lottery.js +++ b/commands/games/lottery.js @@ -16,8 +16,7 @@ module.exports = class LotteryCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; } const lottery = Math.floor(Math.random() * 100) + 1; - const userName = message.author.username; - if (lottery < 100) return message.say(`Nope, sorry ${userName}, you lost.`); - return message.say(`Wow ${userName}! You actually won! Great job!`); + if (lottery < 99) return message.say(`Nope, sorry ${message.author.username}, you lost.`); + return message.say(`Wow ${message.author.username}! You actually won! Great job!`); } }; diff --git a/commands/games/quiz.js b/commands/games/quiz.js index 65866d15..379c3060 100644 --- a/commands/games/quiz.js +++ b/commands/games/quiz.js @@ -22,9 +22,9 @@ module.exports = class QuizCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!'); } try { - const response = await request + const { body } = await request .get('http://jservice.io/api/random?count=1'); - const data = response.body[0]; + const data = body[0]; const answer = data.answer.toLowerCase().replace(/(|<\/i>)/g, ''); const embed = new RichEmbed() .setTitle('You have **fifteen** seconds to answer this question:') diff --git a/commands/games/slots.js b/commands/games/slots.js index 1c924a04..86096f7b 100644 --- a/commands/games/slots.js +++ b/commands/games/slots.js @@ -19,10 +19,9 @@ module.exports = class SlotsCommand extends Command { const slotOne = slotThing[Math.floor(Math.random() * slotThing.length)]; const slotTwo = slotThing[Math.floor(Math.random() * slotThing.length)]; const slotThree = slotThing[Math.floor(Math.random() * slotThing.length)]; - const slotFour = slotThing[Math.floor(Math.random() * slotThing.length)]; - if (slotOne === slotTwo && slotOne === slotThree && slotOne === slotFour) { - return message.say(`${slotOne}|${slotTwo}|${slotThree}|${slotFour}\nWow! You won! Great job... er... luck!`); + if (slotOne === slotTwo && slotOne === slotThree) { + return message.say(`${slotOne}|${slotTwo}|${slotThree}\nWow! You won! Great job... er... luck!`); } - return message.say(`${slotOne}|${slotTwo}|${slotThree}|${slotFour}\nAww... You lost... Guess it's just bad luck, huh?`); + return message.say(`${slotOne}|${slotTwo}|${slotThree}\nAww... You lost... Guess it's just bad luck, huh?`); } }; diff --git a/commands/imageedit/meme.js b/commands/imageedit/meme.js index 24d3a136..6bec0a9b 100644 --- a/commands/imageedit/meme.js +++ b/commands/imageedit/meme.js @@ -21,7 +21,7 @@ module.exports = class MemeCommand extends Command { if (memecodes.includes(type.toLowerCase())) { return true; } - return 'Please enter a valid meme type. Use `;help meme` to view a list of types.'; + return `${type.toLowerCase()} is not a valid meme type. Use \`;help meme\` to view a list of types.`; }, parse: text => { return text.toLowerCase(); @@ -34,7 +34,7 @@ module.exports = class MemeCommand extends Command { if (toprow.match(/^[a-zA-Z0-9.,!?'\s]+$/) && toprow.length < 101) { return true; } - return 'Please do not use special characters and keep the rows under 100 characters each.'; + return `Please do not use special characters and keep the rows under 100 characters each, you have ${toprow.length}.`; }, parse: text => { return text.replace(/[ ]/g, '-').replace(/[?]/g, '~q'); @@ -47,7 +47,7 @@ module.exports = class MemeCommand extends Command { if (bottomrow.match(/^[a-zA-Z0-9.,!?'\s]+$/) && bottomrow.length < 101) { return true; } - return 'Please do not use special characters and keep the rows under 100 characters each.'; + return `Please do not use special characters and keep the rows under 100 characters each, you have ${bottomrow.length}.`; }, parse: text => { return text.replace(/[ ]/g, '-').replace(/[?]/g, '~q'); diff --git a/commands/moderation/ban.js b/commands/moderation/ban.js index 6ea0de74..a412f9b4 100644 --- a/commands/moderation/ban.js +++ b/commands/moderation/ban.js @@ -22,10 +22,10 @@ module.exports = class BanCommand extends Command { prompt: 'What do you want to set the reason as?', type: 'string', validate: reason => { - if (reason.length < 141) { + if (reason.length < 140) { return true; } - return 'Please keep your reason under 140 characters.'; + return `Please keep your reason under 140 characters, you have ${reason.length}.`; } }] }); diff --git a/commands/moderation/kick.js b/commands/moderation/kick.js index 313ed56f..978e4b2b 100644 --- a/commands/moderation/kick.js +++ b/commands/moderation/kick.js @@ -19,10 +19,10 @@ module.exports = class KickCommand extends Command { prompt: 'What do you want to set the reason as?', type: 'string', validate: reason => { - if (reason.length < 141) { + if (reason.length < 140) { return true; } - return 'Please keep your reason under 140 characters.'; + return `Please keep your reason under 140 characters, you have ${reason.length}.`; } }] }); diff --git a/commands/moderation/lockdown.js b/commands/moderation/lockdown.js index 18ec378c..c1a5fe47 100644 --- a/commands/moderation/lockdown.js +++ b/commands/moderation/lockdown.js @@ -17,7 +17,7 @@ module.exports = class LockdownCommand extends Command { if (type.toLowerCase() === 'start' || type.toLowerCase() === 'stop') { return true; } - return 'Please enter either start or stop.'; + return 'Please enter either `start` or `stop`.'; }, parse: text => { return text.toLowerCase(); diff --git a/commands/moderation/prune.js b/commands/moderation/prune.js index 7f58315e..3ad52ee2 100644 --- a/commands/moderation/prune.js +++ b/commands/moderation/prune.js @@ -29,7 +29,7 @@ module.exports = class PruneCommand extends Command { if (count < 100 && count > 0) { return true; } - return 'Too many or two few messages to delete. Limit 1-99.'; + return `${count} is not a valid amount of messages. Limit 1-99.`; } }] }); diff --git a/commands/moderation/unban.js b/commands/moderation/unban.js index e9a1b44f..9c6a72c7 100644 --- a/commands/moderation/unban.js +++ b/commands/moderation/unban.js @@ -21,17 +21,17 @@ module.exports = class UnbanCommand extends Command { if (userID.length === 18) { return true; } - return 'Invalid ID. Please enter the user you wish to unban\'s ID.'; + return `${userID} is not a valid ID. Please enter the user you wish to unban's ID.`; } }, { key: 'reason', prompt: 'What do you want to set the reason as?', type: 'string', validate: reason => { - if (reason.length < 141) { + if (reason.length < 140) { return true; } - return 'Please keep your reason under 140 characters.'; + return `Please keep your reason under 140 characters, you have ${reason.length}.`; } }] }); diff --git a/commands/moderation/warn.js b/commands/moderation/warn.js index 9b2def51..0b868d8c 100644 --- a/commands/moderation/warn.js +++ b/commands/moderation/warn.js @@ -19,10 +19,10 @@ module.exports = class WarnCommand extends Command { prompt: 'What do you want to set the reason as?', type: 'string', validate: reason => { - if (reason.length < 141) { + if (reason.length < 140) { return true; } - return 'Please keep your reason under 140 characters.'; + return `Please keep your reason under 140 characters, you have ${reason.length}.`; } }] }); diff --git a/commands/random/strawpoll.js b/commands/random/strawpoll.js index fa671738..13aab58c 100644 --- a/commands/random/strawpoll.js +++ b/commands/random/strawpoll.js @@ -18,16 +18,22 @@ module.exports = class StrawpollCommand extends Command { prompt: 'What would you like the title of the Strawpoll to be?', type: 'string', validate: title => { - if (title.length > 200) { - return 'Please limit your title to 200 characters.'; + if (title.length < 200) { + return true; } - return true; + return `Please keep your title under 200 characters, you have ${title.length}.`; } }, { key: 'choices', - prompt: 'What choices do you want me pick from?', + prompt: 'What choices do you want me pick from? Maximum of 31.', type: 'string', - infinite: true + infinite: true, + validate: choice => { + if (choice.length < 160) { + return true; + } + return `Please keep your choices under 160 characters each, you have ${choice.length}.`; + } }] }); } @@ -40,14 +46,13 @@ module.exports = class StrawpollCommand extends Command { if (choices.length < 2) return message.say(':x: Error! You provided less than two choices!'); if (choices.length > 31) return message.say(':x: Error! You provided more than thirty choices!'); try { - const response = await request + const { body } = await request .post('https://strawpoll.me/api/v2/polls') .send({ title: title, options: choices }); - const data = response.body; - return message.say(`${data.title}\nhttp://strawpoll.me/${data.id}`); + return message.say(`${body.title}\nhttp://strawpoll.me/${body.id}`); } catch (err) { return message.say(':x: Error! Something went wrong!'); diff --git a/commands/random/today.js b/commands/random/today.js index 4bb0214d..fa27c4ec 100644 --- a/commands/random/today.js +++ b/commands/random/today.js @@ -22,16 +22,16 @@ module.exports = class TodayCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!'); } try { - const response = await request + const { text } = await request .get('http://history.muffinlabs.com/date') .buffer(true); - const parsedResponse = JSON.parse(response.text); - const events = parsedResponse.data.Events; + const data = JSON.parse(text); + const events = data.data.Events; const randomNumber = Math.floor(Math.random() * events.length); const embed = new RichEmbed() .setColor(0x9797FF) - .setURL(parsedResponse.url) - .setTitle(`On this day (${parsedResponse.date})...`) + .setURL(data.url) + .setTitle(`On this day (${data.date})...`) .setTimestamp() .setDescription(`${events[randomNumber].text} (${events[randomNumber].year})`); return message.embed(embed); diff --git a/commands/random/wouldyourather.js b/commands/random/wouldyourather.js index 4adbd8ca..a1d7bb7d 100644 --- a/commands/random/wouldyourather.js +++ b/commands/random/wouldyourather.js @@ -23,14 +23,13 @@ module.exports = class WouldYouRatherCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!'); } try { - const response = await request + const { body } = await request .get('http://www.rrrather.com/botapi'); - const data = response.body; const embed = new RichEmbed() - .setTitle(`${data.title}...`) - .setURL(data.link) + .setTitle(`${body.title}...`) + .setURL(body.link) .setColor(0x9797FF) - .setDescription(`${data.choicea} OR ${data.choiceb}?`); + .setDescription(`${body.choicea} OR ${body.choiceb}?`); return message.embed(embed); } catch (err) { return message.say(':x: Error! Something went wrong!'); diff --git a/commands/search/botinfo.js b/commands/search/botinfo.js index f0470f52..29b3b208 100644 --- a/commands/search/botinfo.js +++ b/commands/search/botinfo.js @@ -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!'); diff --git a/commands/search/define.js b/commands/search/define.js index b5fcc993..37fc9e49 100644 --- a/commands/search/define.js +++ b/commands/search/define.js @@ -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) diff --git a/commands/search/discrim.js b/commands/search/discrim.js index 6eaecf68..3f7084c9 100644 --- a/commands/search/discrim.js +++ b/commands/search/discrim.js @@ -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.`; } }] }); diff --git a/commands/search/forecast.js b/commands/search/forecast.js index a4d5a7e9..f1d134e6 100644 --- a/commands/search/forecast.js +++ b/commands/search/forecast.js @@ -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) diff --git a/commands/search/google.js b/commands/search/google.js index e3d591d8..a8ea256f 100644 --- a/commands/search/google.js +++ b/commands/search/google.js @@ -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); diff --git a/commands/search/imdb.js b/commands/search/imdb.js index e7087a28..455a8199 100644 --- a/commands/search/imdb.js +++ b/commands/search/imdb.js @@ -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!'); diff --git a/commands/search/map.js b/commands/search/map.js index e6bedfa5..5d46a933 100644 --- a/commands/search/map.js +++ b/commands/search/map.js @@ -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!'); } diff --git a/commands/search/neopet.js b/commands/search/neopet.js index ad897c0f..cd61ba5e 100644 --- a/commands/search/neopet.js +++ b/commands/search/neopet.js @@ -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); diff --git a/commands/search/osu.js b/commands/search/osu.js index 299d2ca2..1c51faef 100644 --- a/commands/search/osu.js +++ b/commands/search/osu.js @@ -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') diff --git a/commands/search/urban.js b/commands/search/urban.js index 134ded71..3398e93e 100644 --- a/commands/search/urban.js +++ b/commands/search/urban.js @@ -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!'); diff --git a/commands/search/wattpad.js b/commands/search/wattpad.js index d3b810d8..383a14a3 100644 --- a/commands/search/wattpad.js +++ b/commands/search/wattpad.js @@ -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:**', diff --git a/commands/search/weather.js b/commands/search/weather.js index 788c6487..7d0ce340 100644 --- a/commands/search/weather.js +++ b/commands/search/weather.js @@ -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') diff --git a/commands/search/wikipedia.js b/commands/search/wikipedia.js index bf5c083f..b14daf38 100644 --- a/commands/search/wikipedia.js +++ b/commands/search/wikipedia.js @@ -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) diff --git a/commands/search/youtube.js b/commands/search/youtube.js index 0fffde63..9f47ab70 100644 --- a/commands/search/youtube.js +++ b/commands/search/youtube.js @@ -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) diff --git a/commands/search/yugioh.js b/commands/search/yugioh.js index 626bd8d7..8437549a 100644 --- a/commands/search/yugioh.js +++ b/commands/search/yugioh.js @@ -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) diff --git a/commands/textedit/binary.js b/commands/textedit/binary.js index ee4a6976..d7e38862 100644 --- a/commands/textedit/binary.js +++ b/commands/textedit/binary.js @@ -21,10 +21,10 @@ module.exports = class BinaryCommand extends Command { prompt: 'What text would you like to convert to binary?', type: 'string', validate: content => { - if (stringToBinary(content).length > 1950) { - return 'Your message content is too long.'; + if (stringToBinary(content).length < 2000) { + return true; } - return true; + return 'Your message content is too long.'; }, parse: text => { return stringToBinary(text); diff --git a/commands/textedit/cowsay.js b/commands/textedit/cowsay.js index 57a4813e..0715ac2c 100644 --- a/commands/textedit/cowsay.js +++ b/commands/textedit/cowsay.js @@ -16,7 +16,7 @@ module.exports = class CowsayCommand extends Command { if (text.length < 1500) { return true; } - return 'Your message content is too long.'; + return `Please keep your content under 1500 characters, you have ${text.length}.`; } }] }); diff --git a/commands/textedit/morse.js b/commands/textedit/morse.js index b7f3f7c6..7c9f4a09 100644 --- a/commands/textedit/morse.js +++ b/commands/textedit/morse.js @@ -18,10 +18,10 @@ module.exports = class MorseCommand extends Command { prompt: 'What text would you like to convert to morse?', type: 'string', validate: content => { - if (translator.letterTrans(content, dictionary, ' ').length < 1900) { + if (translator.letterTrans(content, dictionary, ' ').length < 1999) { return true; } - return 'Your text to encode is too long.'; + return 'Your message content is too long.'; }, parse: text => { return translator.letterTrans(text.toLowerCase(), dictionary, ' '); diff --git a/commands/textedit/pirate.js b/commands/textedit/pirate.js index fc251330..39ab06f8 100644 --- a/commands/textedit/pirate.js +++ b/commands/textedit/pirate.js @@ -19,10 +19,10 @@ module.exports = class PirateCommand extends Command { prompt: 'What text would you like to convert to pirate?', type: 'string', validate: content => { - if (translator.wordTrans(content, dictionary).length > 1950) { - return 'Your message content is too long.'; + if (translator.wordTrans(content, dictionary).length < 1999) { + return true; } - return true; + return 'Your message content is too long.'; }, parse: text => { return translator.wordTrans(text, dictionary); diff --git a/commands/textedit/temmie.js b/commands/textedit/temmie.js index dd42df12..e1584467 100644 --- a/commands/textedit/temmie.js +++ b/commands/textedit/temmie.js @@ -15,10 +15,10 @@ module.exports = class TemmieCommand extends Command { prompt: 'What text would you like to convert to Temmie speak?', type: 'string', validate: content => { - if (translator.wordTrans(content, dictionary).length > 1950) { - return 'Your message content is too long.'; + if (translator.wordTrans(content, dictionary).length < 1999) { + return true; } - return true; + return 'Your message content is too long.'; }, parse: text => { return translator.wordTrans(text, dictionary); diff --git a/commands/textedit/zalgo.js b/commands/textedit/zalgo.js index fa8682ad..35f5c39d 100644 --- a/commands/textedit/zalgo.js +++ b/commands/textedit/zalgo.js @@ -14,10 +14,10 @@ module.exports = class ZalgoCommand extends Command { prompt: 'What text would you like to convert to zalgo?', type: 'string', validate: content => { - if (zalgo(content).length > 1950) { - return 'Your message content is too long.'; + if (content.length > 500) { + return true; } - return true; + return `Please keep your text under 500 characters, you have ${content.length}.`; }, parse: text => { return zalgo(text); diff --git a/package.json b/package.json index 620cd9cd..81737a0e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "29.0.0", + "version": "30.0.0", "description": "A Discord Bot", "main": "shardingmanager.js", "scripts": {