mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-23 18:05:01 +02:00
Mirror Command
This commit is contained in:
@@ -132,7 +132,7 @@ in the appropriate channel's topic to use it.
|
|||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
Total: 386
|
Total: 387
|
||||||
|
|
||||||
### Utility:
|
### Utility:
|
||||||
|
|
||||||
@@ -422,6 +422,7 @@ Total: 386
|
|||||||
* **ifunny:** Draws an image with the iFunny logo.
|
* **ifunny:** Draws an image with the iFunny logo.
|
||||||
* **invert:** Draws an image or a user's avatar but inverted.
|
* **invert:** Draws an image or a user's avatar but inverted.
|
||||||
* **minecraft-skin:** Sends the Minecraft skin for a user.
|
* **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.
|
* **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.
|
* **newspaper:** Creates a fake newspaper with the headline and body of your choice.
|
||||||
* **pixelize:** Draws an image or a user's avatar pixelized.
|
* **pixelize:** Draws an image or a user's avatar pixelized.
|
||||||
|
|||||||
@@ -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
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "113.2.0",
|
"version": "113.3.0",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user