mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-25 22:32:50 +02:00
Fix
This commit is contained in:
@@ -6,10 +6,9 @@ module.exports = class PixelizeCommand extends Command {
|
|||||||
constructor(client) {
|
constructor(client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
name: 'pixelize',
|
name: 'pixelize',
|
||||||
aliases: ['jpeg', 'needs-more-jpeg'],
|
group: 'avatar-edit',
|
||||||
group: 'image-edit',
|
|
||||||
memberName: 'pixelize',
|
memberName: 'pixelize',
|
||||||
description: 'Draws an image or a user\'s avatar but pixelized.',
|
description: 'Draws a user\'s avatar but pixelized.',
|
||||||
throttling: {
|
throttling: {
|
||||||
usages: 1,
|
usages: 1,
|
||||||
duration: 15
|
duration: 15
|
||||||
@@ -17,29 +16,28 @@ module.exports = class PixelizeCommand extends Command {
|
|||||||
clientPermissions: ['ATTACH_FILES'],
|
clientPermissions: ['ATTACH_FILES'],
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
key: 'image',
|
key: 'user',
|
||||||
prompt: 'What image would you like to edit?',
|
prompt: 'Which user would you like to edit the avatar of?',
|
||||||
type: 'image',
|
type: 'user',
|
||||||
default: ''
|
default: ''
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { image }) {
|
async run(msg, { user }) {
|
||||||
if (!image) {
|
if (!user) user = msg.author;
|
||||||
image = msg.author.displayAvatarURL({
|
const avatarURL = user.displayAvatarURL({
|
||||||
format: 'png',
|
format: 'png',
|
||||||
size: 64
|
size: 64
|
||||||
});
|
});
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const { body } = await snekfetch.get(image);
|
const { body } = await snekfetch.get(avatarURL);
|
||||||
const data = await loadImage(body);
|
const avatar = await loadImage(body);
|
||||||
const canvas = createCanvas(512, 512);
|
const canvas = createCanvas(512, 512);
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
ctx.imageSmoothingEnabled = false;
|
ctx.imageSmoothingEnabled = false;
|
||||||
ctx.drawImage(data, 0, 0, 512, 512);
|
ctx.drawImage(avatar, 0, 0, 512, 512);
|
||||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'pixelize.png' }] });
|
return msg.say({ files: [{ attachment: canvas.toBuffer(), 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!`);
|
||||||
Reference in New Issue
Block a user