mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-13 00:09:08 +02:00
Begin migrating away from stupid "Oh no, an error occurred!"
This commit is contained in:
@@ -27,20 +27,16 @@ module.exports = class CircleCommand extends Command {
|
||||
}
|
||||
|
||||
async run(msg, { image }) {
|
||||
try {
|
||||
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(canvas.width / 2, canvas.height / 2, canvas.height / 2, 0, Math.PI * 2);
|
||||
ctx.closePath();
|
||||
ctx.clip();
|
||||
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!`);
|
||||
}
|
||||
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(canvas.width / 2, canvas.height / 2, canvas.height / 2, 0, Math.PI * 2);
|
||||
ctx.closePath();
|
||||
ctx.clip();
|
||||
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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user