Resize Command

This commit is contained in:
Dragon Fire
2020-07-02 17:15:03 -04:00
parent c933124274
commit f6f88225a5
3 changed files with 57 additions and 2 deletions
+2 -1
View File
@@ -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.
+54
View File
@@ -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
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "119.1.0",
"version": "119.2.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {