From 1a377f55b5a8f329012731f691b06aeeb4c5987e Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Fri, 13 Oct 2017 20:41:05 +0000 Subject: [PATCH] Cool pad thing --- commands/games/whos-that-pokemon.js | 13 ++++--------- commands/image-edit/pokemon-fusion.js | 2 +- commands/search/pokedex.js | 4 ++-- commands/text-edit/binary.js | 3 ++- structures/Util.js | 4 ++++ 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/commands/games/whos-that-pokemon.js b/commands/games/whos-that-pokemon.js index 713b16bc..d7865f7c 100644 --- a/commands/games/whos-that-pokemon.js +++ b/commands/games/whos-that-pokemon.js @@ -1,7 +1,6 @@ const { Command } = require('discord.js-commando'); -const { MessageEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); -const { filterPkmn } = require('../../structures/Util'); +const { filterPkmn, pad } = require('../../structures/Util'); module.exports = class WhosThatPokemonCommand extends Command { constructor(client) { @@ -11,7 +10,7 @@ module.exports = class WhosThatPokemonCommand extends Command { group: 'games', memberName: 'whos-that-pokemon', description: 'Guess who that Pokémon is.', - clientPermissions: ['EMBED_LINKS'] + clientPermissions: ['ATTACH_FILES'] }); } @@ -21,12 +20,8 @@ module.exports = class WhosThatPokemonCommand extends Command { const { body } = await snekfetch.get(`https://pokeapi.co/api/v2/pokemon-species/${pokemon}/`); const names = body.names.map(name => name.name.toLowerCase()); const displayName = filterPkmn(body.names).name; - const id = `${'000'.slice(body.id.toString().length)}${body.id}`; - const embed = new MessageEmbed() - .setColor(0xED1C24) - .setTitle('You have 15 seconds, who\'s that Pokémon?') - .setImage(`https://www.serebii.net/sunmoon/pokemon/${id}.png`); - await msg.embed(embed); + const image = `https://www.serebii.net/sunmoon/pokemon/${pad(body.id.toString(), '000')}.png`; + await msg.say('**You have 15 seconds, who\'s that Pokémon?**', { files: [image] }); const msgs = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, { max: 1, time: 15000 diff --git a/commands/image-edit/pokemon-fusion.js b/commands/image-edit/pokemon-fusion.js index e6691be3..b6d8513d 100644 --- a/commands/image-edit/pokemon-fusion.js +++ b/commands/image-edit/pokemon-fusion.js @@ -36,6 +36,6 @@ module.exports = class PokemonFusionCommand extends Command { } run(msg, { body, palette }) { - return msg.say(`http://images.alexonsager.net/pokemon/fused/${body}/${body}.${palette}.png`); + return msg.say({ files: [`http://images.alexonsager.net/pokemon/fused/${body}/${body}.${palette}.png`] }); } }; diff --git a/commands/search/pokedex.js b/commands/search/pokedex.js index 301e0ca1..a6d28143 100644 --- a/commands/search/pokedex.js +++ b/commands/search/pokedex.js @@ -2,7 +2,7 @@ const { Command } = require('discord.js-commando'); const { MessageEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); const { stripIndents } = require('common-tags'); -const { filterPkmn } = require('../../structures/Util'); +const { filterPkmn, pad } = require('../../structures/Util'); module.exports = class PokedexCommand extends Command { constructor(client) { @@ -27,7 +27,7 @@ module.exports = class PokedexCommand extends Command { async run(msg, { pokemon }) { try { const { body } = await snekfetch.get(`https://pokeapi.co/api/v2/pokemon-species/${pokemon}/`); - const id = `${'000'.slice(body.id.toString().length)}${body.id}`; + const id = pad(body.id.toString(), '000'); const embed = new MessageEmbed() .setColor(0xED1C24) .setAuthor(`#${id} - ${filterPkmn(body.names).name}`, `https://www.serebii.net/pokedex-sm/icon/${id}.png`) diff --git a/commands/text-edit/binary.js b/commands/text-edit/binary.js index 02dd045f..759bfc8b 100644 --- a/commands/text-edit/binary.js +++ b/commands/text-edit/binary.js @@ -1,4 +1,5 @@ const { Command } = require('discord.js-commando'); +const { pad } = require('../../structures/Util'); module.exports = class BinaryCommand extends Command { constructor(client) { @@ -28,7 +29,7 @@ module.exports = class BinaryCommand extends Command { binary(text) { return text.split('').map(str => { const converted = str.charCodeAt(0).toString(2); - return `${'00000000'.slice(converted.length)}${converted}`; + return pad(converted, '00000000'); }).join(''); } }; diff --git a/structures/Util.js b/structures/Util.js index 7c44b859..ed7071e6 100644 --- a/structures/Util.js +++ b/structures/Util.js @@ -56,6 +56,10 @@ class Util { format: () => `${hrs < 10 ? `0${hrs}` : hrs}:${min < 10 ? `0${min}` : min}:${sec < 10 ? `0${sec}` : sec}` }; } + + static pad(text, prefix) { + return `${prefix.slice(text.length)}${text}`; + } } module.exports = Util;