Cool pad thing

This commit is contained in:
Daniel Odendahl Jr
2017-10-13 20:41:05 +00:00
parent 19482a1a47
commit 1a377f55b5
5 changed files with 13 additions and 13 deletions
+4 -9
View File
@@ -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
+1 -1
View File
@@ -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`] });
}
};
+2 -2
View File
@@ -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`)
+2 -1
View File
@@ -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('');
}
};
+4
View File
@@ -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;