Mirror Command

This commit is contained in:
Dragon Fire
2020-04-19 10:01:11 -04:00
parent bb139beac3
commit d24a413785
3 changed files with 64 additions and 2 deletions
+2 -1
View File
@@ -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.
+61
View File
@@ -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!`);
}
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "113.2.0",
"version": "113.3.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {