Move some functions to Util, Bug Fixes, new stuff

This commit is contained in:
Dragon Fire
2020-03-13 22:59:22 -04:00
parent bf7579c4ac
commit 0edac3e86d
14 changed files with 99 additions and 92 deletions
+16 -20
View File
@@ -43,26 +43,22 @@ module.exports = class SosCommand extends Command {
}
async run(msg, { message }) {
try {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'sos.png'));
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(base, 0, 0);
ctx.font = '90px Noto';
ctx.fillStyle = 'black';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.rotate(15 * (Math.PI / 180));
let fontSize = 90;
while (ctx.measureText(message).width > 140) {
fontSize -= 1;
ctx.font = `${fontSize}px Noto`;
}
ctx.fillText(message.toUpperCase(), 362, 522);
ctx.rotate(-15 * (Math.PI / 180));
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'sos.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', 'sos.png'));
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(base, 0, 0);
ctx.font = '90px Noto';
ctx.fillStyle = 'black';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.rotate(15 * (Math.PI / 180));
let fontSize = 90;
while (ctx.measureText(message).width > 140) {
fontSize -= 1;
ctx.font = `${fontSize}px Noto`;
}
ctx.fillText(message.toUpperCase(), 362, 522);
ctx.rotate(-15 * (Math.PI / 180));
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'sos.png' }] });
}
};