mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-20 14:00:22 +02:00
Begin migrating away from stupid "Oh no, an error occurred!"
This commit is contained in:
+13
-17
@@ -37,22 +37,18 @@ module.exports = class CrushCommand extends Command {
|
||||
}
|
||||
|
||||
async run(msg, { image }) {
|
||||
try {
|
||||
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'crush.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.fillStyle = 'white';
|
||||
ctx.fillRect(0, 0, base.width, base.height);
|
||||
ctx.rotate(-3.79 * (Math.PI / 180));
|
||||
const { x, y, width, height } = centerImagePart(data, 400, 400, 79, 472);
|
||||
ctx.drawImage(data, x, y, width, height);
|
||||
ctx.rotate(3.79 * (Math.PI / 180));
|
||||
ctx.drawImage(base, 0, 0);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'crush.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', 'crush.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.fillStyle = 'white';
|
||||
ctx.fillRect(0, 0, base.width, base.height);
|
||||
ctx.rotate(-3.79 * (Math.PI / 180));
|
||||
const { x, y, width, height } = centerImagePart(data, 400, 400, 79, 472);
|
||||
ctx.drawImage(data, x, y, width, height);
|
||||
ctx.rotate(3.79 * (Math.PI / 180));
|
||||
ctx.drawImage(base, 0, 0);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'crush.png' }] });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user