mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-06 06:10:49 +02:00
Resize Command
This commit is contained in:
@@ -243,7 +243,7 @@ in the appropriate channel's topic to use it.
|
||||
|
||||
## Commands
|
||||
|
||||
Total: 514
|
||||
Total: 515
|
||||
|
||||
### Utility:
|
||||
|
||||
@@ -615,6 +615,7 @@ Total: 514
|
||||
* **police-tape:** Draws police tape over an image or a user's avatar.
|
||||
* **rainbow:** Draws a rainbow over an image or a user's avatar.
|
||||
* **rejected:** Draws a "rejected" stamp over an image or a user's avatar.
|
||||
* **resize:** Draws an image or a user's avatar resized to the size you want.
|
||||
* **robohash:** Creates a robot based on the text you provide.
|
||||
* **sepia:** Draws an image or a user's avatar in sepia.
|
||||
* **shields-io-badge:** Creates a badge from shields.io.
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { createCanvas, loadImage } = require('canvas');
|
||||
const request = require('node-superfetch');
|
||||
|
||||
module.exports = class ResizeCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'resize',
|
||||
group: 'edit-image',
|
||||
memberName: 'resize',
|
||||
description: 'Draws an image or a user\'s avatar resized to the size you want.',
|
||||
throttling: {
|
||||
usages: 1,
|
||||
duration: 10
|
||||
},
|
||||
clientPermissions: ['ATTACH_FILES'],
|
||||
args: [
|
||||
{
|
||||
key: 'width',
|
||||
prompt: 'What do you want the new width of the image to be?',
|
||||
type: 'integer',
|
||||
min: 1,
|
||||
max: 2000
|
||||
},
|
||||
{
|
||||
key: 'height',
|
||||
prompt: 'What do you want the new height of the image to be?',
|
||||
type: 'integer',
|
||||
min: 1,
|
||||
max: 2000
|
||||
},
|
||||
{
|
||||
key: 'image',
|
||||
prompt: 'Which image would you like to edit?',
|
||||
type: 'image',
|
||||
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 2048 })
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { width, height, image }) {
|
||||
try {
|
||||
const { body } = await request.get(image);
|
||||
const data = await loadImage(body);
|
||||
const canvas = createCanvas(width, height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(data, 0, 0, width, height);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'resize.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "119.1.0",
|
||||
"version": "119.2.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user