mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-21 14:04:38 +02:00
Begin migrating away from stupid "Oh no, an error occurred!"
This commit is contained in:
@@ -48,40 +48,36 @@ module.exports = class DrakepostingCommand extends Command {
|
||||
}
|
||||
|
||||
async run(msg, { nah, yeah }) {
|
||||
try {
|
||||
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'drakeposting.png'));
|
||||
const canvas = createCanvas(base.width, base.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(base, 0, 0);
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'top';
|
||||
ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(50);
|
||||
let fontSize = 50;
|
||||
while (ctx.measureText(nah).width > 3003) {
|
||||
fontSize--;
|
||||
ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
|
||||
}
|
||||
const nahLines = await wrapText(ctx, nah, 462);
|
||||
const nahTopMost = 256 - (((fontSize * nahLines.length) / 2) + ((10 * (nahLines.length - 1)) / 2));
|
||||
for (let i = 0; i < nahLines.length; i++) {
|
||||
const height = nahTopMost + ((fontSize + 10) * i);
|
||||
ctx.fillText(nahLines[i], 768, height);
|
||||
}
|
||||
ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(50);
|
||||
fontSize = 50;
|
||||
while (ctx.measureText(yeah).width > 3003) {
|
||||
fontSize--;
|
||||
ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
|
||||
}
|
||||
const yeahLines = await wrapText(ctx, yeah, 462);
|
||||
const yeahTopMost = 768 - (((fontSize * yeahLines.length) / 2) + ((10 * (yeahLines.length - 1)) / 2));
|
||||
for (let i = 0; i < yeahLines.length; i++) {
|
||||
const height = yeahTopMost + ((fontSize + 10) * i);
|
||||
ctx.fillText(yeahLines[i], 768, height);
|
||||
}
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'drakeposting.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', 'drakeposting.png'));
|
||||
const canvas = createCanvas(base.width, base.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(base, 0, 0);
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'top';
|
||||
ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(50);
|
||||
let fontSize = 50;
|
||||
while (ctx.measureText(nah).width > 3003) {
|
||||
fontSize--;
|
||||
ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
|
||||
}
|
||||
const nahLines = await wrapText(ctx, nah, 462);
|
||||
const nahTopMost = 256 - (((fontSize * nahLines.length) / 2) + ((10 * (nahLines.length - 1)) / 2));
|
||||
for (let i = 0; i < nahLines.length; i++) {
|
||||
const height = nahTopMost + ((fontSize + 10) * i);
|
||||
ctx.fillText(nahLines[i], 768, height);
|
||||
}
|
||||
ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(50);
|
||||
fontSize = 50;
|
||||
while (ctx.measureText(yeah).width > 3003) {
|
||||
fontSize--;
|
||||
ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
|
||||
}
|
||||
const yeahLines = await wrapText(ctx, yeah, 462);
|
||||
const yeahTopMost = 768 - (((fontSize * yeahLines.length) / 2) + ((10 * (yeahLines.length - 1)) / 2));
|
||||
for (let i = 0; i < yeahLines.length; i++) {
|
||||
const height = yeahTopMost + ((fontSize + 10) * i);
|
||||
ctx.fillText(yeahLines[i], 768, height);
|
||||
}
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'drakeposting.png' }] });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user