diff --git a/commands/games/whos-that-pokemon.js b/commands/games/whos-that-pokemon.js new file mode 100644 index 00000000..67e778a1 --- /dev/null +++ b/commands/games/whos-that-pokemon.js @@ -0,0 +1,37 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const snekfetch = require('snekfetch'); +const { filterPkmn } = require('../../structures/Util'); + +module.exports = class WhosThatPokemonCommand extends Command { + constructor(client) { + super(client, { + name: 'whos-that-pokemon', + aliases: ['who-pokmeon', '', 'whos-that-pokémon', 'who-pokémon'], + group: 'games', + memberName: 'whos-that-pokemon', + description: 'Guess who that Pokémon is.', + clientPermissions: ['EMBED_LINKS'] + }); + } + + async run(msg) { + const pokemon = Math.floor(Math.random() * 721) + 1; + const { body } = await snekfetch + .get(`https://pokeapi.co/api/v2/pokemon-species/${pokemon}`); + const name = filterPkmn(body.names).name.toLowerCase(); + const id = `${'000'.slice(body.id.toString().length)}${body.id}`; + const embed = new MessageEmbed() + .setTitle('You have 15 seconds, who\'s that Pokémon?') + .setColor(0xED1C24) + .setImage(`https://www.serebii.net/sunmoon/pokemon/${id}.png`); + await msg.embed(embed); + const msgs = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, { + max: 1, + time: 15000 + }); + if (!msgs.size) return msg.say(`Time! It was ${name}, sorry!`); + if (msgs.first().content.toLowerCase() !== name) return msg.say(`Nope, sorry, it's ${name}.`); + return msg.say('Nice job! 10/10! You deserve some cake!'); + } +}; diff --git a/commands/search/osu.js b/commands/search/osu.js index 2df48c75..fefc5ca9 100644 --- a/commands/search/osu.js +++ b/commands/search/osu.js @@ -48,7 +48,7 @@ module.exports = class OsuCommand extends Command { .addField('❯ Play Count', body[0].playcount, true) .addField('❯ Country', - body[0].country, true) + body[0].country || 'N/A', true) .addField('❯ Ranked Score', body[0].ranked_score, true) .addField('❯ Total Score', diff --git a/commands/search/pokedex.js b/commands/search/pokedex.js index fd433031..93778d39 100644 --- a/commands/search/pokedex.js +++ b/commands/search/pokedex.js @@ -2,6 +2,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); const { stripIndents } = require('common-tags'); +const { filterPkmn } = require('../../structures/Util'); module.exports = class PokedexCommand extends Command { constructor(client) { @@ -31,11 +32,11 @@ module.exports = class PokedexCommand extends Command { const id = `${'000'.slice(body.id.toString().length)}${body.id}`; const embed = new MessageEmbed() .setColor(0xED1C24) - .setAuthor(`#${id} - ${this.filter(body.names).name}`, `https://www.serebii.net/pokedex-sm/icon/${id}.png`) + .setAuthor(`#${id} - ${filterPkmn(body.names).name}`, `https://www.serebii.net/pokedex-sm/icon/${id}.png`) .setURL(`https://www.serebii.net/pokedex-sm/${id}.shtml`) .setDescription(stripIndents` - **The ${this.filter(body.genera).genus} Pokémon** - ${this.filter(body.flavor_text_entries).flavor_text.replace(/(\n|\f|\r)/g, ' ')} + **The ${filterPkmn(body.genera).genus} Pokémon** + ${filterPkmn(body.flavor_text_entries).flavor_text.replace(/(\n|\f|\r)/g, ' ')} `) .setThumbnail(`https://www.serebii.net/sunmoon/pokemon/${id}.png`); return msg.embed(embed); @@ -44,9 +45,4 @@ module.exports = class PokedexCommand extends Command { throw err; } } - - filter(arr) { - const filtered = arr.filter(entry => entry.language.name === 'en'); - return filtered[Math.floor(Math.random() * filtered.length)]; - } }; diff --git a/commands/search/reddit.js b/commands/search/reddit.js index 0c71b00a..9abb8786 100644 --- a/commands/search/reddit.js +++ b/commands/search/reddit.js @@ -45,6 +45,7 @@ module.exports = class RedditCommand extends Command { post.data.score, true); return msg.embed(embed); } catch (err) { + if (err.status === 403) return msg.say('This Subreddit is Private.'); if (err.status === 404) return msg.say('Subreddit Not Found.'); throw err; } diff --git a/package.json b/package.json index 22ce93a3..c8a24718 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "31.0.2", + "version": "31.1.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": { diff --git a/structures/Util.js b/structures/Util.js index cdd45d4a..ec93c6a4 100644 --- a/structures/Util.js +++ b/structures/Util.js @@ -79,6 +79,11 @@ class Util { static shorten(text, maxLen = 2000) { return text.length > maxLen ? `${text.substr(0, maxLen - 3)}...` : text; } + + static filterPkmn(arr) { + const filtered = arr.filter(entry => entry.language.name === 'en'); + return filtered[Math.floor(Math.random() * filtered.length)]; + } } module.exports = Util;