mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-19 21:40:51 +02:00
Begin migrating away from stupid "Oh no, an error occurred!"
This commit is contained in:
@@ -37,26 +37,22 @@ module.exports = class WorthlessCommand extends Command {
|
||||
}
|
||||
|
||||
async run(msg, { image }) {
|
||||
try {
|
||||
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'worthless.png'));
|
||||
const { body } = await request.get(image);
|
||||
const data = await loadImage(body);
|
||||
const canvas = createCanvas(base.width, base.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(base, 0, 0);
|
||||
ctx.rotate(6 * (Math.PI / 180));
|
||||
const center1 = centerImagePart(data, 400, 400, 496, 183);
|
||||
ctx.drawImage(data, center1.x, center1.y, center1.width, center1.height);
|
||||
ctx.rotate(-6 * (Math.PI / 180));
|
||||
ctx.translate(canvas.width / 2, canvas.height / 2);
|
||||
ctx.rotate(160 * (Math.PI / 180));
|
||||
ctx.translate(-(canvas.width / 2), -(canvas.height / 2));
|
||||
const center2 = centerImagePart(data, 75, 75, 625, 55);
|
||||
ctx.drawImage(data, center2.x, center2.y, center2.width, center2.height);
|
||||
ctx.rotate(-160 * (Math.PI / 180));
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'worthless.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'worthless.png'));
|
||||
const { body } = await request.get(image);
|
||||
const data = await loadImage(body);
|
||||
const canvas = createCanvas(base.width, base.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(base, 0, 0);
|
||||
ctx.rotate(6 * (Math.PI / 180));
|
||||
const center1 = centerImagePart(data, 400, 400, 496, 183);
|
||||
ctx.drawImage(data, center1.x, center1.y, center1.width, center1.height);
|
||||
ctx.rotate(-6 * (Math.PI / 180));
|
||||
ctx.translate(canvas.width / 2, canvas.height / 2);
|
||||
ctx.rotate(160 * (Math.PI / 180));
|
||||
ctx.translate(-(canvas.width / 2), -(canvas.height / 2));
|
||||
const center2 = centerImagePart(data, 75, 75, 625, 55);
|
||||
ctx.drawImage(data, center2.x, center2.y, center2.width, center2.height);
|
||||
ctx.rotate(-160 * (Math.PI / 180));
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'worthless.png' }] });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user