From 3dc47731e5ec2a3c3c1f833e8bec228f35d500c2 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Mon, 20 Nov 2017 22:42:53 +0000 Subject: [PATCH] Demotivational with image support --- commands/avatar-edit/pixelize.js | 2 +- .../demotivational-poster.js | 32 ++++++++++--------- package.json | 2 +- types/image.js | 4 +-- 4 files changed, 21 insertions(+), 19 deletions(-) rename commands/{avatar-edit => image-edit}/demotivational-poster.js (76%) diff --git a/commands/avatar-edit/pixelize.js b/commands/avatar-edit/pixelize.js index 4f47b7a7..78952d5c 100644 --- a/commands/avatar-edit/pixelize.js +++ b/commands/avatar-edit/pixelize.js @@ -8,7 +8,7 @@ module.exports = class PixelizeCommand extends Command { name: 'pixelize', group: 'avatar-edit', memberName: 'pixelize', - description: 'Draws a user\'s avatar but pixelized.', + description: 'Draws a user\'s avatar pixelized.', throttling: { usages: 1, duration: 15 diff --git a/commands/avatar-edit/demotivational-poster.js b/commands/image-edit/demotivational-poster.js similarity index 76% rename from commands/avatar-edit/demotivational-poster.js rename to commands/image-edit/demotivational-poster.js index 7f331932..2df4bbdd 100644 --- a/commands/avatar-edit/demotivational-poster.js +++ b/commands/image-edit/demotivational-poster.js @@ -11,9 +11,9 @@ module.exports = class DemotivationalPosterCommand extends Command { super(client, { name: 'demotivational-poster', aliases: ['demotivational'], - group: 'avatar-edit', + group: 'image-edit', memberName: 'demotivational-poster', - description: 'Draws a user\'s avatar and the text you specify as a demotivational poster.', + description: 'Draws an image or a user\'s avatar and the text you specify as a demotivational poster.', throttling: { usages: 1, duration: 15 @@ -32,30 +32,32 @@ module.exports = class DemotivationalPosterCommand extends Command { type: 'string' }, { - key: 'user', - prompt: 'Which user would you like to edit the avatar of?', - type: 'user', - default: '' + key: 'image', + prompt: 'What image would you like to edit?', + type: 'image', + default: '', + avatarSize: 1024 } ] }); } - async run(msg, { title, text, user }) { - if (!user) user = msg.author; - const avatarURL = user.displayAvatarURL({ - format: 'png', - size: 1024 - }); + async run(msg, { title, text, image }) { + if (!image) { + image = msg.author.displayAvatarURL({ + format: 'png', + size: 1024 + }); + } try { const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'demotivational-poster.png')); - const { body } = await snekfetch.get(avatarURL); - const avatar = await loadImage(body); + const { body } = await snekfetch.get(image); + const data = await loadImage(body); const canvas = createCanvas(base.width, base.height); const ctx = canvas.getContext('2d'); ctx.fillStyle = 'white'; ctx.fillRect(0, 0, base.width, base.height); - ctx.drawImage(avatar, 68, -57, 612, 612); + ctx.drawImage(data, 69, 44, 612, data.height > 412 ? data.height : 412); ctx.drawImage(base, 0, 0); ctx.textAlign = 'center'; ctx.font = '60px Noto'; diff --git a/package.json b/package.json index 6be5f722..0594315b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "55.1.2", + "version": "55.1.3", "description": "Your personal server companion.", "main": "XiaoBot.js", "scripts": { diff --git a/types/image.js b/types/image.js index 87d3aa09..16b90a86 100644 --- a/types/image.js +++ b/types/image.js @@ -16,11 +16,11 @@ class ImageArgumentType extends ArgumentType { return true; } - parse(value, msg) { + parse(value, msg, arg) { if (!msg.attachments.size) { return this.client.registry.types.get('user').parse(value, msg).displayAvatarURL({ format: 'png', - size: 512 + size: arg.avatarSize || 512 }); } return msg.attachments.first().url;