diff --git a/README.md b/README.md index bac47ecf..3e16fccb 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 386 +Total: 387 ### Utility: @@ -422,6 +422,7 @@ Total: 386 * **ifunny:** Draws an image with the iFunny logo. * **invert:** Draws an image or a user's avatar but inverted. * **minecraft-skin:** Sends the Minecraft skin for a user. +* **mirror:** Draws an image or a user's avatar but mirrored on the X/Y axis (or both). * **needs-more-jpeg:** Draws an image or a user's avatar as a low quality JPEG. * **newspaper:** Creates a fake newspaper with the headline and body of your choice. * **pixelize:** Draws an image or a user's avatar pixelized. diff --git a/commands/edit-image/mirror.js b/commands/edit-image/mirror.js new file mode 100644 index 00000000..5265f23f --- /dev/null +++ b/commands/edit-image/mirror.js @@ -0,0 +1,61 @@ +const Command = require('../../structures/Command'); +const { createCanvas, loadImage } = require('canvas'); +const request = require('node-superfetch'); +const { list } = require('../../util/Util'); +const types = ['x', 'y', 'both']; + +module.exports = class MirrorCommand extends Command { + constructor(client) { + super(client, { + name: 'mirror', + group: 'edit-image', + memberName: 'mirror', + description: 'Draws an image or a user\'s avatar but mirrored on the X/Y axis (or both).', + throttling: { + usages: 1, + duration: 10 + }, + clientPermissions: ['ATTACH_FILES'], + args: [ + { + key: 'type', + prompt: `What axis do you want to mirror? Either ${list(types, 'or')}.`, + type: 'string', + oneOf: types, + parse: type => type.toLowerCase() + }, + { + key: 'image', + prompt: 'What image would you like to edit?', + type: 'image', + default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) + } + ] + }); + } + + async run(msg, { type, image }) { + try { + const { body } = await request.get(image); + const data = await loadImage(body); + const canvas = createCanvas(data.width, data.height); + const ctx = canvas.getContext('2d'); + if (type === 'x') { + ctx.translate(canvas.width, 0); + ctx.scale(-1, 1); + } else if (type === 'y') { + ctx.translate(0, canvas.height); + ctx.scale(1, -1); + } else if (type === 'both') { + ctx.translate(canvas.width, canvas.height); + ctx.scale(-1, -1); + } + ctx.drawImage(data, 0, 0); + const attachment = canvas.toBuffer(); + if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.'); + return msg.say({ files: [{ attachment, name: 'mirror.png' }] }); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 910449a3..afa50b48 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "113.2.0", + "version": "113.3.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {