Word wrap in illegal

This commit is contained in:
Daniel Odendahl Jr
2018-09-12 17:34:53 +00:00
parent a1c6d8d155
commit 8b4f00f736
2 changed files with 12 additions and 9 deletions
+11 -8
View File
@@ -1,8 +1,7 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { createCanvas, loadImage, registerFont } = require('canvas'); const { createCanvas, loadImage, registerFont } = require('canvas');
const { stripIndents } = require('common-tags');
const path = require('path'); const path = require('path');
const { shortenText } = require('../../util/Canvas'); const { wrapText } = require('../../util/Canvas');
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Regular.ttf'), { family: 'Noto' }); registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Regular.ttf'), { family: 'Noto' });
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-CJK.otf'), { family: 'Noto' }); registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-CJK.otf'), { family: 'Noto' });
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Emoji.ttf'), { family: 'Noto' }); registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Emoji.ttf'), { family: 'Noto' });
@@ -25,6 +24,7 @@ module.exports = class IllegalCommand extends Command {
key: 'text', key: 'text',
prompt: 'What should the text of the bill be?', prompt: 'What should the text of the bill be?',
type: 'string', type: 'string',
max: 20,
parse: text => text.toUpperCase() parse: text => text.toUpperCase()
}, },
{ {
@@ -45,12 +45,15 @@ module.exports = class IllegalCommand extends Command {
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
ctx.drawImage(base, 0, 0); ctx.drawImage(base, 0, 0);
ctx.rotate(7 * (Math.PI / 180)); ctx.rotate(7 * (Math.PI / 180));
ctx.font = '45px Noto'; const illegalText = `${text} ${verb} NOW ILLEGAL.`;
ctx.fillText(stripIndents` let fontSize = 45;
${shortenText(ctx, text, 200)} ctx.font = `${fontSize}px Noto`;
${verb} NOW while (ctx.measureText(illegalText).width > 550) {
ILLEGAL. fontSize -= 1;
`, 750, 290); ctx.font = `${fontSize}px Noto`;
}
ctx.fillText(wrapText(ctx, illegalText, 200).join('\n'), 750, 290);
ctx.rotate(-7 * (Math.PI / 180));
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'illegal.png' }] }); return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'illegal.png' }] });
} }
}; };
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "91.1.5", "version": "91.1.6",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"scripts": { "scripts": {