diff --git a/README.md b/README.md index e296506c..3579702d 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 (308) +## Commands (309) ### Utility: * **eval:** Executes JavaScript code. @@ -242,6 +242,7 @@ on the [home server](https://discord.gg/sbMe32W). * **frame:** Draws a frame around an image or a user's avatar. * **glitch:** Draws an image or a user's avatar but glitched. * **greyscale:** Draws an image or a user's avatar in greyscale. +* **gru-plan:** Sends a Gru's Plan meme with steps of your choice. * **ifunny:** Draws an image with the iFunny logo. * **illegal:** Makes President Trump make your text illegal. * **invert:** Draws an image or a user's avatar but inverted. diff --git a/assets/images/gru-plan.png b/assets/images/gru-plan.png new file mode 100644 index 00000000..21ea2ddb Binary files /dev/null and b/assets/images/gru-plan.png differ diff --git a/commands/image-edit/gru-plan.js b/commands/image-edit/gru-plan.js new file mode 100644 index 00000000..fbdfc1f1 --- /dev/null +++ b/commands/image-edit/gru-plan.js @@ -0,0 +1,70 @@ +const Command = require('../../structures/Command'); +const { createCanvas, loadImage, registerFont } = require('canvas'); +const path = require('path'); +const { wrapText } = require('../../util/Canvas'); +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-Emoji.ttf'), { family: 'Noto' }); +const coord = [[443, 139], [1200, 143], [443, 637], [1200, 637]]; + +module.exports = class GruPlanCommand extends Command { + constructor(client) { + super(client, { + name: 'gru-plan', + aliases: ['grus-plan', 'gru', 'plan'], + group: 'image-edit', + memberName: 'gru-plan', + description: 'Sends a Gru\'s Plan meme with steps of your choice.', + throttling: { + usages: 1, + duration: 10 + }, + clientPermissions: ['ATTACH_FILES'], + args: [ + { + key: 'step1', + label: 'step 1', + prompt: 'What should the first step of Gru\'s plan be?', + type: 'string', + max: 500 + }, + { + key: 'step2', + label: 'step 2', + prompt: 'What should the second step of Gru\'s plan be?', + type: 'string', + max: 500 + }, + { + key: 'step3', + label: 'step 3', + prompt: 'What should the third step of Gru\'s plan be?', + type: 'string', + max: 500 + } + ] + }); + } + + async run(msg, { step1, step2, step3 }) { + const steps = [step1, step2, step3, step3]; + const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'gru-plan.png')); + const canvas = createCanvas(base.width, base.height); + const ctx = canvas.getContext('2d'); + ctx.drawImage(base, 0, 0); + ctx.fillStyle = 'black'; + ctx.textBaseline = 'top'; + let i = 0; + for (const [x, y] of coord) { + const step = steps[i]; + let fontSize = 50; + while (ctx.measureText(step).width > 1500) { + fontSize -= 1; + ctx.font = `${fontSize}px Noto`; + } + ctx.fillText(wrapText(ctx, step, 252).join('\n'), x, y); + i++; + } + return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'gru-plan.png' }] }); + } +}; diff --git a/commands/number-edit/prime.js b/commands/number-edit/prime.js index 4a890b08..97f64cc7 100644 --- a/commands/number-edit/prime.js +++ b/commands/number-edit/prime.js @@ -24,10 +24,10 @@ module.exports = class PrimeCommand extends Command { } isPrime(number) { - if (number < 1) return false; + if (number < 2) return false; for (let i = 2; i < number; i++) { if (number % i === 0) return false; } - return number !== 1 && number !== 0; + return true; } }; diff --git a/package.json b/package.json index e395f6ab..37241fda 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "91.3.1", + "version": "91.3.2", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {