Begin migrating away from stupid "Oh no, an error occurred!"

This commit is contained in:
Dragon Fire
2024-03-29 23:57:49 -04:00
parent 067545b818
commit 0b807767d1
130 changed files with 1692 additions and 2190 deletions
+30 -34
View File
@@ -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' }] });
}
};