From 4674fc8d45dd3c89bc379cf1cb92cba657d1f417 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sat, 30 Mar 2024 00:11:31 -0400 Subject: [PATCH] Use flags --- commands/edit-meme/challenger.js | 17 +++++---- commands/games-mp/apples-to-apples.js | 18 ++++++---- commands/games-mp/cards-against-humanity.js | 18 ++++++---- commands/pokedex/pokedex-box-sprite.js | 39 +++++++++++++-------- commands/random-res/draw-cards.js | 20 ++++++----- 5 files changed, 72 insertions(+), 40 deletions(-) diff --git a/commands/edit-meme/challenger.js b/commands/edit-meme/challenger.js index 44a6088a..0047851b 100644 --- a/commands/edit-meme/challenger.js +++ b/commands/edit-meme/challenger.js @@ -31,13 +31,17 @@ module.exports = class ChallengerCommand extends Command { reasonURL: 'https://www.smashbros.com/en_US/index.html' } ], - args: [ + flags: [ { - key: 'silhouetted', - prompt: 'Should the image be silhouetted?', - type: 'boolean', - default: true + key: 'show', + description: 'Does not silhouette the image.' }, + { + key: 's', + description: 'Alias for show.' + } + ], + args: [ { key: 'image', prompt: 'What image would you like to edit?', @@ -48,7 +52,8 @@ module.exports = class ChallengerCommand extends Command { }); } - async run(msg, { image, silhouetted }) { + async run(msg, { image, flags }) { + const silhouetted = flags.show || flags.s; const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'challenger.png')); const { body } = await request.get(image); const data = await loadImage(body); diff --git a/commands/games-mp/apples-to-apples.js b/commands/games-mp/apples-to-apples.js index ef1f2b54..65a1d0d6 100644 --- a/commands/games-mp/apples-to-apples.js +++ b/commands/games-mp/apples-to-apples.js @@ -28,6 +28,16 @@ module.exports = class ApplesToApplesCommand extends Command { reason: 'Card Data' } ], + flags: [ + { + key: 'bot', + description: 'Adds the bot as a player.' + }, + { + key: 'b', + description: 'Alias for bot.' + } + ], args: [ { key: 'maxPts', @@ -37,16 +47,12 @@ module.exports = class ApplesToApplesCommand extends Command { max: 20, min: 1 }, - { - key: 'bot', - prompt: 'Do you want me to play as well?', - type: 'boolean' - } ] }); } - async run(msg, { maxPts, bot }) { + async run(msg, { maxPts, flags }) { + const bot = flags.bot || flags.b; const current = this.client.games.get(msg.channel.id); if (current) return msg.reply(`Please wait until the current game of \`${current.name}\` is finished.`); this.client.games.set(msg.channel.id, diff --git a/commands/games-mp/cards-against-humanity.js b/commands/games-mp/cards-against-humanity.js index e7a03d06..740f54b0 100644 --- a/commands/games-mp/cards-against-humanity.js +++ b/commands/games-mp/cards-against-humanity.js @@ -28,6 +28,16 @@ module.exports = class CardsAgainstHumanityCommand extends Command { reason: 'Card Data' } ], + flags: [ + { + key: 'bot', + description: 'Adds the bot as a player.' + }, + { + key: 'b', + description: 'Alias for bot.' + } + ], args: [ { key: 'maxPts', @@ -36,17 +46,13 @@ module.exports = class CardsAgainstHumanityCommand extends Command { type: 'integer', max: 20, min: 1 - }, - { - key: 'bot', - prompt: 'Do you want me to play as well?', - type: 'boolean' } ] }); } - async run(msg, { maxPts, bot }) { + async run(msg, { maxPts, flags }) { + const bot = flags.bot || flags.b; const current = this.client.games.get(msg.channel.id); if (current) return msg.reply(`Please wait until the current game of \`${current.name}\` is finished.`); this.client.games.set(msg.channel.id, diff --git a/commands/pokedex/pokedex-box-sprite.js b/commands/pokedex/pokedex-box-sprite.js index 99e259ad..79870d6a 100644 --- a/commands/pokedex/pokedex-box-sprite.js +++ b/commands/pokedex/pokedex-box-sprite.js @@ -55,6 +55,16 @@ module.exports = class PokedexBoxSpriteCommand extends Command { reasonURL: 'https://play.pokemonshowdown.com/sprites/' } ], + flags: [ + { + key: 'small', + description: 'Generates the image with the original 40x30 size.' + }, + { + key: 's', + description: 'Alias for small.' + } + ], args: [ { key: 'pokemon', @@ -65,22 +75,23 @@ module.exports = class PokedexBoxSpriteCommand extends Command { }); } - async run(msg, { pokemon }) { + async run(msg, { pokemon, flags }) { if (!this.client.pokemon.sprites) await this.client.pokemon.loadSprites(); const canvas = createCanvas(250, 250); const ctx = canvas.getContext('2d'); - const x = 40 * (pokemon.id % 12); - const y = Math.floor(pokemon.id / 12) * 30; - ctx.imageSmoothingEnabled = false; - const ratio = 250 / 40; - const height = 30 * ratio; - ctx.drawImage(this.client.pokemon.sprites, x, y, 40, 30, 0, 0, 250, height); - cropToContent(ctx, canvas, canvas.width, canvas.height); - return msg.say(`#${pokemon.displayID} - ${pokemon.name}`, { - files: [{ - attachment: canvas.toBuffer(), - name: 'box.png' - }] - }); + let attachment; + if (flags.small || flags.s) { + attachment = await pokemon.generateBoxImage(); + } else { + const x = 40 * (pokemon.id % 12); + const y = Math.floor(pokemon.id / 12) * 30; + ctx.imageSmoothingEnabled = false; + const ratio = 250 / 40; + const height = 30 * ratio; + ctx.drawImage(this.client.pokemon.sprites, x, y, 40, 30, 0, 0, 250, height); + cropToContent(ctx, canvas, canvas.width, canvas.height); + attachment = canvas.toBuffer(); + } + return msg.say(`#${pokemon.displayID} - ${pokemon.name}`, { files: [{ attachment, name: 'box.png' }] }); } }; diff --git a/commands/random-res/draw-cards.js b/commands/random-res/draw-cards.js index 7d5c614b..1236cd65 100644 --- a/commands/random-res/draw-cards.js +++ b/commands/random-res/draw-cards.js @@ -9,6 +9,16 @@ module.exports = class DrawCardsCommand extends Command { group: 'random-res', memberName: 'draw-cards', description: 'Draws a random hand of playing cards.', + flags: [ + { + key: 'jokers', + description: 'Includes jokers in the deck.' + }, + { + key: 'j', + description: 'Alias for bot.' + } + ], args: [ { key: 'amount', @@ -17,19 +27,13 @@ module.exports = class DrawCardsCommand extends Command { type: 'integer', max: 10, min: 1 - }, - { - key: 'jokers', - prompt: 'Do you want the deck to include jokers?', - type: 'boolean', - default: false } ] }); } - run(msg, { amount, jokers }) { - const deck = new Deck({ includeJokers: jokers }); + run(msg, { amount, flags }) { + const deck = new Deck({ includeJokers: Boolean(flags.jokers || flags.j) }); const cards = deck.draw(amount); const display = Array.isArray(cards) ? cards.map(c => c.display).join('\n') : cards.display; return msg.reply(`${amount === 1 ? '' : '\n'}${display}`);