mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-14 08:08:34 +02:00
Stretch and Squish Commands
This commit is contained in:
@@ -132,7 +132,7 @@ in the appropriate channel's topic to use it.
|
|||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
Total: 407
|
Total: 409
|
||||||
|
|
||||||
### Utility:
|
### Utility:
|
||||||
|
|
||||||
@@ -447,6 +447,8 @@ Total: 407
|
|||||||
* **shields-io-badge:** Creates a badge from shields.io.
|
* **shields-io-badge:** Creates a badge from shields.io.
|
||||||
* **silhouette:** Draws a silhouette of an image or a user's avatar.
|
* **silhouette:** Draws a silhouette of an image or a user's avatar.
|
||||||
* **square:** Draws an image or a user's avatar as a square.
|
* **square:** Draws an image or a user's avatar as a square.
|
||||||
|
* **squish:** Draws an image or a user's avatar but squished across the X or Y axis.
|
||||||
|
* **stretch:** Draws an image or a user's avatar but stretched across the X or Y axis.
|
||||||
* **tint:** Draws an image or a user's avatar but tinted a specific color.
|
* **tint:** Draws an image or a user's avatar but tinted a specific color.
|
||||||
* **zero-dialogue:** Sends a text box from Megaman Zero with the quote of your choice.
|
* **zero-dialogue:** Sends a text box from Megaman Zero with the quote of your choice.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
const Command = require('../../structures/Command');
|
||||||
|
const { createCanvas, loadImage } = require('canvas');
|
||||||
|
const request = require('node-superfetch');
|
||||||
|
|
||||||
|
module.exports = class SquishCommand extends Command {
|
||||||
|
constructor(client) {
|
||||||
|
super(client, {
|
||||||
|
name: 'squish',
|
||||||
|
group: 'edit-image',
|
||||||
|
memberName: 'stretch',
|
||||||
|
description: 'Draws an image or a user\'s avatar but squished across the X or Y axis.',
|
||||||
|
throttling: {
|
||||||
|
usages: 1,
|
||||||
|
duration: 10
|
||||||
|
},
|
||||||
|
clientPermissions: ['ATTACH_FILES'],
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
key: 'axis',
|
||||||
|
prompt: 'What axis do you want to squish?',
|
||||||
|
type: 'string',
|
||||||
|
oneOf: ['x', 'y'],
|
||||||
|
parse: axis => axis.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, { axis, image }) {
|
||||||
|
const flipX = axis === 'x';
|
||||||
|
const flipY = axis === 'y';
|
||||||
|
try {
|
||||||
|
const { body } = await request.get(image);
|
||||||
|
const data = await loadImage(body);
|
||||||
|
const canvas = createCanvas(flipX ? data.width / 2 : data.width, flipY ? data.height / 2 : data.height);
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
ctx.drawImage(data, 0, 0, canvas.width, canvas.height);
|
||||||
|
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: 'squish.png' }] });
|
||||||
|
} catch (err) {
|
||||||
|
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
const Command = require('../../structures/Command');
|
||||||
|
const { createCanvas, loadImage } = require('canvas');
|
||||||
|
const request = require('node-superfetch');
|
||||||
|
|
||||||
|
module.exports = class StretchCommand extends Command {
|
||||||
|
constructor(client) {
|
||||||
|
super(client, {
|
||||||
|
name: 'stretch',
|
||||||
|
group: 'edit-image',
|
||||||
|
memberName: 'stretch',
|
||||||
|
description: 'Draws an image or a user\'s avatar but stretched across the X or Y axis.',
|
||||||
|
throttling: {
|
||||||
|
usages: 1,
|
||||||
|
duration: 10
|
||||||
|
},
|
||||||
|
clientPermissions: ['ATTACH_FILES'],
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
key: 'axis',
|
||||||
|
prompt: 'What axis do you want to stretch?',
|
||||||
|
type: 'string',
|
||||||
|
oneOf: ['x', 'y'],
|
||||||
|
parse: axis => axis.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, { axis, image }) {
|
||||||
|
const flipX = axis === 'x';
|
||||||
|
const flipY = axis === 'y';
|
||||||
|
try {
|
||||||
|
const { body } = await request.get(image);
|
||||||
|
const data = await loadImage(body);
|
||||||
|
const canvas = createCanvas(flipX ? data.width * 2 : data.width, flipY ? data.height * 2 : data.height);
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
ctx.drawImage(data, 0, 0, canvas.width, canvas.height);
|
||||||
|
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: 'stretch.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": "114.0.3",
|
"version": "114.1.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