mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-21 05:54:33 +02:00
Circle accepts images
This commit is contained in:
@@ -6,10 +6,10 @@ module.exports = class CircleCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'circle',
|
||||
aliases: ['circle-avatar', 'circle-ava'],
|
||||
group: 'avatar-edit',
|
||||
aliases: ['circle-avatar', 'circle-ava', 'circle-image', 'circle-img'],
|
||||
group: 'image-edit',
|
||||
memberName: 'circle',
|
||||
description: 'Draws a user\'s avatar as a circle.',
|
||||
description: 'Draws an image or a user\'s avatar as a circle.',
|
||||
throttling: {
|
||||
usages: 1,
|
||||
duration: 10
|
||||
@@ -17,27 +17,27 @@ module.exports = class CircleCommand extends Command {
|
||||
clientPermissions: ['ATTACH_FILES'],
|
||||
args: [
|
||||
{
|
||||
key: 'user',
|
||||
prompt: 'Which user would you like to edit the avatar of?',
|
||||
type: 'user',
|
||||
default: msg => msg.author
|
||||
key: 'image',
|
||||
prompt: 'Which image would you like to edit?',
|
||||
type: 'image',
|
||||
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 })
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { user }) {
|
||||
const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 });
|
||||
async run(msg, { image }) {
|
||||
try {
|
||||
const { body } = await request.get(avatarURL);
|
||||
const avatar = await loadImage(body);
|
||||
const canvas = createCanvas(avatar.width, avatar.height);
|
||||
const { body } = await request.get(image);
|
||||
const data = await loadImage(body);
|
||||
const dimensions = data.width <= data.height ? data.width : data.height;
|
||||
const canvas = createCanvas(dimensions, dimensions);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.beginPath();
|
||||
ctx.arc(avatar.width / 2, avatar.height / 2, avatar.height / 2, 0, Math.PI * 2);
|
||||
ctx.arc(canvas.width / 2, canvas.height / 2, canvas.height / 2, 0, Math.PI * 2);
|
||||
ctx.closePath();
|
||||
ctx.clip();
|
||||
ctx.drawImage(avatar, 0, 0);
|
||||
ctx.drawImage(data, (canvas.width / 2) - (data.width / 2), (canvas.height / 2) - (data.height / 2));
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'circle.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
Reference in New Issue
Block a user