mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-26 22:32:52 +02:00
Begin migrating away from stupid "Oh no, an error occurred!"
This commit is contained in:
@@ -49,32 +49,28 @@ module.exports = class DemotivationalCommand extends Command {
|
||||
}
|
||||
|
||||
async run(msg, { title, text, image }) {
|
||||
try {
|
||||
const { body } = await request.get(image);
|
||||
const data = await loadImage(body);
|
||||
const canvas = createCanvas(750, 600);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.fillStyle = 'black';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
const { y, width, height } = centerImagePart(data, 602, 402, 0, 44);
|
||||
const x = (canvas.width / 2) - (width / 2);
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.fillRect(x - 4, y - 4, width + 8, height + 8);
|
||||
ctx.fillStyle = 'black';
|
||||
ctx.fillRect(x - 2, y - 2, width + 4, height + 4);
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.fillRect(x, y, width, height);
|
||||
ctx.drawImage(data, x, y, width, height);
|
||||
ctx.textAlign = 'center';
|
||||
ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(60);
|
||||
ctx.fillStyle = 'aquamarine';
|
||||
ctx.fillText(shortenText(ctx, title, 610), 375, 518);
|
||||
ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(27);
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.fillText(shortenText(ctx, text, 610), 375, 565);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'demotivational-poster.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 canvas = createCanvas(750, 600);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.fillStyle = 'black';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
const { y, width, height } = centerImagePart(data, 602, 402, 0, 44);
|
||||
const x = (canvas.width / 2) - (width / 2);
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.fillRect(x - 4, y - 4, width + 8, height + 8);
|
||||
ctx.fillStyle = 'black';
|
||||
ctx.fillRect(x - 2, y - 2, width + 4, height + 4);
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.fillRect(x, y, width, height);
|
||||
ctx.drawImage(data, x, y, width, height);
|
||||
ctx.textAlign = 'center';
|
||||
ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(60);
|
||||
ctx.fillStyle = 'aquamarine';
|
||||
ctx.fillText(shortenText(ctx, title, 610), 375, 518);
|
||||
ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(27);
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.fillText(shortenText(ctx, text, 610), 375, 565);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'demotivational-poster.png' }] });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user