diff --git a/README.md b/README.md index cbfc57e2..eeded0e5 100644 --- a/README.md +++ b/README.md @@ -479,6 +479,7 @@ Total: 402 * **distracted-boyfriend:** Draws three user's avatars over the "Distracted Boyfriend" meme. * **drakeposting:** Draws two user's avatars over the "Drakeposting" meme. * **food-broke:** Draws a user's avatar over the "Food Broke" meme. +* **genie-rules:** Sends a "There are 4 rules" meme with the text of your choice. * **girl-worth-fighting-for:** Draws an image or a user's avatar as the object of Ling's affection. * **gru-plan:** Sends a Gru's Plan meme with steps of your choice. * **illegal:** Makes President Trump make your text illegal. @@ -777,6 +778,7 @@ here. * calendar ([Calendar API](https://developers.google.com/calendar/)) * dear-liberals ([Oswald Font](https://fonts.google.com/specimen/Oswald)) * demotivational ([Noto Font](https://www.google.com/get/noto/)) + * genie-rules ([Noto Font](https://www.google.com/get/noto/)) * google ([Custom Search API](https://cse.google.com/cse/all)) * google-autofill (Autofill API) * google-doodle ([Google Doodles API](https://www.google.com/doodles)) diff --git a/assets/images/genie-rules.png b/assets/images/genie-rules.png new file mode 100644 index 00000000..55ea62c4 Binary files /dev/null and b/assets/images/genie-rules.png differ diff --git a/commands/edit-meme/genie-rules.js b/commands/edit-meme/genie-rules.js new file mode 100644 index 00000000..0d1f2edf --- /dev/null +++ b/commands/edit-meme/genie-rules.js @@ -0,0 +1,62 @@ +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' }); + +module.exports = class GenieRulesCommand extends Command { + constructor(client) { + super(client, { + name: 'genie-rules', + aliases: ['genie', '4-rules', 'four-rules', 'there-are-four-rules', 'there-are-4-rules'], + group: 'edit-meme', + memberName: 'genie-rules', + description: 'Sends a "There are 4 rules" meme with the text of your choice.', + throttling: { + usages: 1, + duration: 10 + }, + clientPermissions: ['ATTACH_FILES'], + credit: [ + { + name: 'Google', + url: 'https://www.google.com/', + reason: 'Noto Font', + reasonURL: 'https://www.google.com/get/noto/' + } + ], + args: [ + { + key: 'text', + prompt: 'What do you want to wish for?', + type: 'string', + max: 500 + } + ] + }); + } + + async run(msg, { text }) { + const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'genie-rules.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 = '40px Noto'; + let fontSize = 40; + while (ctx.measureText(text).width > 1143) { + fontSize -= 1; + ctx.font = `${fontSize}px Noto`; + } + const lines = await wrapText(ctx, text, 381); + const topMost = 580 - (((fontSize * lines.length) / 2) + ((20 * (lines.length - 1)) / 2)); + for (let i = 0; i < lines.length; i++) { + const height = topMost + ((fontSize + 20) * i); + ctx.fillText(lines[i], 220, height); + } + return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'genie-rules.png' }] }); + } +}; diff --git a/package.json b/package.json index 92a69ca6..cc8b7707 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "113.16.0", + "version": "113.17.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {