mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-05 00:06:42 +02:00
Convert Image Command
This commit is contained in:
@@ -224,7 +224,7 @@ in the appropriate channel's topic to use it.
|
||||
|
||||
## Commands
|
||||
|
||||
Total: 457
|
||||
Total: 458
|
||||
|
||||
### Utility:
|
||||
|
||||
@@ -541,6 +541,7 @@ Total: 457
|
||||
* **circle:** Draws an image or a user's avatar as a circle.
|
||||
* **color:** Sends an image of the color you choose.
|
||||
* **contrast:** Draws an image or a user's avatar but with contrast.
|
||||
* **convert-image:** Converts an image or user's avatar from one format to another.
|
||||
* **create-qr-code:** Converts text to a QR Code.
|
||||
* **dexter:** Draws an image or a user's avatar over the screen of Dexter from Pokémon.
|
||||
* **distort:** Draws an image or a user's avatar but distorted.
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { createCanvas, loadImage } = require('canvas');
|
||||
const request = require('node-superfetch');
|
||||
const { list } = require('../../util/Util');
|
||||
const formats = {
|
||||
jpg: 'image/jpeg',
|
||||
jpeg: 'image/jpeg',
|
||||
png: 'image/png'
|
||||
};
|
||||
|
||||
module.exports = class ConvertImageCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'convert-image',
|
||||
aliases: ['convert-img', 'image-convert', 'img-convert'],
|
||||
group: 'edit-image',
|
||||
memberName: 'convert-image',
|
||||
description: 'Converts an image or user\'s avatar from one format to another.',
|
||||
throttling: {
|
||||
usages: 1,
|
||||
duration: 10
|
||||
},
|
||||
clientPermissions: ['ATTACH_FILES'],
|
||||
args: [
|
||||
{
|
||||
key: 'format',
|
||||
prompt: `What format do you want to convert the image to? Either ${list(Object.keys(formats), 'or')}.`,
|
||||
type: 'string',
|
||||
oneOf: Object.keys(formats),
|
||||
parse: format => format.toLowerCase()
|
||||
},
|
||||
{
|
||||
key: 'image',
|
||||
prompt: 'Which image would you like to edit?',
|
||||
type: 'image',
|
||||
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 })
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { format, 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');
|
||||
ctx.drawImage(data, 0, 0);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(formats[format]), name: `convert-image.${format}` }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "116.2.5",
|
||||
"version": "116.3.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
@@ -60,7 +60,7 @@
|
||||
"utf-8-validate": "^5.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^7.0.0",
|
||||
"eslint": "^7.2.0",
|
||||
"eslint-config-amber": "^2.0.3",
|
||||
"eslint-plugin-json": "^2.1.1"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user