diff --git a/README.md b/README.md index fbe052ed..7e20b2f6 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Xiao is a Discord bot coded in JavaScript with The bot is no longer available for invite. You can self-host the bot, or use her on the [home server](https://discord.gg/sbMe32W). -## Commands (311) +## Commands (312) ### Utility: * **eval:** Executes JavaScript code. @@ -93,6 +93,7 @@ on the [home server](https://discord.gg/sbMe32W). * **can-you-not:** Can YOU not? * **dark-theme-light-theme:** Determines whether you use dark or light theme. * **eat-pant:** Eat pant. +* **eggs-get-laid:**: Sends the ultimate roast. * **give-flower:** Gives Xiao Pai a flower. * **hi:** Hello. * **isnt-joke:** Isn't joke... diff --git a/assets/images/eggs-get-laid.png b/assets/images/eggs-get-laid.png new file mode 100644 index 00000000..df7f05ba Binary files /dev/null and b/assets/images/eggs-get-laid.png differ diff --git a/commands/image-edit/be-like-bill.js b/commands/image-edit/be-like-bill.js index 2402e7ba..cce0b528 100644 --- a/commands/image-edit/be-like-bill.js +++ b/commands/image-edit/be-like-bill.js @@ -39,7 +39,7 @@ module.exports = class BeLikeBillCommand extends Command { const ctx = canvas.getContext('2d'); ctx.drawImage(base, 0, 0); ctx.font = '23px Noto'; - const text = wrapText(ctx, texts[Math.floor(Math.random() * texts.length)].replace(/{{name}}/gi, name), 600 - 31); + const text = await wrapText(ctx, texts[Math.floor(Math.random() * texts.length)].replace(/{{name}}/gi, name), 569); ctx.fillText(stripIndents` This is ${name}. diff --git a/commands/image-edit/gru-plan.js b/commands/image-edit/gru-plan.js index 32d4350e..48cbcbdc 100644 --- a/commands/image-edit/gru-plan.js +++ b/commands/image-edit/gru-plan.js @@ -26,21 +26,21 @@ module.exports = class GruPlanCommand extends Command { label: 'step 1', prompt: 'What should the first step of Gru\'s plan be?', type: 'string', - max: 500 + max: 150 }, { key: 'step2', label: 'step 2', prompt: 'What should the second step of Gru\'s plan be?', type: 'string', - max: 500 + max: 150 }, { key: 'step3', label: 'step 3', prompt: 'What should the third step of Gru\'s plan be?', type: 'string', - max: 500 + max: 150 } ] }); @@ -63,7 +63,8 @@ module.exports = class GruPlanCommand extends Command { fontSize -= 1; ctx.font = `${fontSize}px Noto`; } - ctx.fillText(wrapText(ctx, step, 252).join('\n'), x, y); + const lines = await wrapText(ctx, step, 252); + ctx.fillText(lines.join('\n'), x, y); i++; } return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'gru-plan.png' }] }); diff --git a/commands/image-edit/illegal.js b/commands/image-edit/illegal.js index d3ecf54f..dd877ba7 100644 --- a/commands/image-edit/illegal.js +++ b/commands/image-edit/illegal.js @@ -52,7 +52,8 @@ module.exports = class IllegalCommand extends Command { fontSize -= 1; ctx.font = `${fontSize}px Noto`; } - ctx.fillText(wrapText(ctx, illegalText, 200).join('\n'), 750, 290); + const lines = await wrapText(ctx, illegalText, 200); + ctx.fillText(lines.join('\n'), 750, 290); ctx.rotate(-7 * (Math.PI / 180)); return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'illegal.png' }] }); } diff --git a/commands/image-edit/nike-ad.js b/commands/image-edit/nike-ad.js index d84129f3..3db9c450 100644 --- a/commands/image-edit/nike-ad.js +++ b/commands/image-edit/nike-ad.js @@ -60,7 +60,7 @@ module.exports = class NikeAdCommand extends Command { ctx.font = `${fontSize}px Noto`; ctx.fillStyle = 'white'; ctx.textAlign = 'center'; - const lines = wrapText(ctx, `Believe in ${something}. Even if it means ${sacrifice}.`, data.width - 20); + const lines = await wrapText(ctx, `Believe in ${something}. Even if it means ${sacrifice}.`, data.width - 20); const initial = data.height / 2; for (let i = 0; i < lines.length; i++) { const textHeight = initial + (i * fontSize) + (i * 10); diff --git a/commands/single/eggs-get-laid.js b/commands/single/eggs-get-laid.js new file mode 100644 index 00000000..7b7b694b --- /dev/null +++ b/commands/single/eggs-get-laid.js @@ -0,0 +1,19 @@ +const Command = require('../../structures/Command'); +const path = require('path'); + +module.exports = class EggsGetLaidCommand extends Command { + constructor(client) { + super(client, { + name: 'eggs-get-laid', + aliases: ['eggs-gets-laid'], + group: 'single', + memberName: 'eggs-get-laid', + description: 'Sends the ultimate roast.', + clientPermissions: ['ATTACH_FILES'] + }); + } + + run(msg) { + return msg.say({ files: [path.join(__dirname, '..', '..', 'assets', 'images', 'eggs-get-laid.png')] }); + } +}; diff --git a/package.json b/package.json index f63235a6..bb6936bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "91.5.3", + "version": "91.6.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/util/Canvas.js b/util/Canvas.js index 3a1ead53..e88b56ef 100644 --- a/util/Canvas.js +++ b/util/Canvas.js @@ -97,30 +97,32 @@ module.exports = class CanvasUtil { } static wrapText(ctx, text, maxWidth) { - if (ctx.measureText(text).width < maxWidth) return [text]; - const words = text.split(' '); - const lines = []; - let line = ''; - while (words.length > 0) { - let split = false; - while (ctx.measureText(words[0]).width >= maxWidth) { - const temp = words[0]; - words[0] = temp.slice(0, -1); - if (split) { - words[1] = `${temp.slice(-1)}${words[1]}`; - } else { - split = true; - words.splice(1, 0, temp.slice(-1)); + return new Promise(resolve => { + if (ctx.measureText(text).width < maxWidth) return resolve([text]); + const words = text.split(' '); + const lines = []; + let line = ''; + while (words.length > 0) { + let split = false; + while (ctx.measureText(words[0]).width >= maxWidth) { + const temp = words[0]; + words[0] = temp.slice(0, -1); + if (split) { + words[1] = `${temp.slice(-1)}${words[1]}`; + } else { + split = true; + words.splice(1, 0, temp.slice(-1)); + } } + if (ctx.measureText(`${line}${words[0]}`).width < maxWidth) { + line += `${words.shift()} `; + } else { + lines.push(line.trim()); + line = ''; + } + if (words.length === 0) lines.push(line.trim()); } - if (ctx.measureText(`${line}${words[0]}`).width < maxWidth) { - line += `${words.shift()} `; - } else { - lines.push(line.trim()); - line = ''; - } - if (words.length === 0) lines.push(line.trim()); - } - return lines; + return resolve(lines); + }); } };