mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-24 14:19:56 +02:00
Fixes
This commit is contained in:
@@ -6,6 +6,7 @@ module.exports = class PixelizeCommand extends Command {
|
|||||||
constructor(client) {
|
constructor(client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
name: 'pixelize',
|
name: 'pixelize',
|
||||||
|
aliases: ['pixel'],
|
||||||
group: 'image-edit',
|
group: 'image-edit',
|
||||||
memberName: 'pixelize',
|
memberName: 'pixelize',
|
||||||
description: 'Draws an image or a user\'s avatar pixelized.',
|
description: 'Draws an image or a user\'s avatar pixelized.',
|
||||||
@@ -28,15 +29,17 @@ module.exports = class PixelizeCommand extends Command {
|
|||||||
async run(msg, { image }) {
|
async run(msg, { image }) {
|
||||||
try {
|
try {
|
||||||
const { body } = await request.get(image);
|
const { body } = await request.get(image);
|
||||||
const avatar = await loadImage(body);
|
const data = await loadImage(body);
|
||||||
const canvas = createCanvas(512, 512);
|
const canvas = createCanvas(data.width, data.height);
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
ctx.imageSmoothingEnabled = false;
|
ctx.imageSmoothingEnabled = false;
|
||||||
const width = canvas.width * 0.25;
|
const width = canvas.width * 0.15;
|
||||||
const height = canvas.height * 0.25;
|
const height = canvas.height * 0.15;
|
||||||
ctx.drawImage(avatar, 0, 0, width, height);
|
ctx.drawImage(data, 0, 0, width, height);
|
||||||
ctx.drawImage(canvas, 0, 0, width, height, 0, 0, canvas.width, canvas.height);
|
ctx.drawImage(canvas, 0, 0, width, height, 0, 0, canvas.width, canvas.height);
|
||||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'pixelize.png' }] });
|
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: 'pixelize.png' }] });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,12 +31,14 @@ module.exports = class RainbowCommand extends Command {
|
|||||||
try {
|
try {
|
||||||
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'rainbow.png'));
|
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'rainbow.png'));
|
||||||
const { body } = await request.get(image);
|
const { body } = await request.get(image);
|
||||||
const avatar = await loadImage(body);
|
const data = await loadImage(body);
|
||||||
const canvas = createCanvas(avatar.width, avatar.height);
|
const canvas = createCanvas(data.width, data.height);
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
ctx.drawImage(avatar, 0, 0);
|
ctx.drawImage(data, 0, 0);
|
||||||
ctx.drawImage(base, 0, 0, avatar.width, avatar.height);
|
ctx.drawImage(base, 0, 0, data.width, data.height);
|
||||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'rainbow.png' }] });
|
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: 'rainbow.png' }] });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user