diff --git a/README.md b/README.md index 96b1f837..62677550 100644 --- a/README.md +++ b/README.md @@ -243,7 +243,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 526 +Total: 528 ### Utility: @@ -581,6 +581,7 @@ Total: 526 * **axis-cult-sign-up:** Sends an Axis Cult Sign-Up sheet for you. Join today! * **blur:** Draws an image or a user's avatar but blurred. * **brazzers:** Draws an image with the Brazzers logo in the corner. (NSFW) +* **caution:** Creates a caution sign with the text of your choice. * **certificate:** Sends a certificate of excellence with the name and reason of your choice. * **charcoal:** Draws an image or a user's avatar but with charcoal. * **chinese-restaurant:** Sends a Chinese restaurant sign with the text of your choice. @@ -590,6 +591,7 @@ Total: 526 * **contrast:** Draws an image or a user's avatar but with contrast. * **convert-image:** Converts an image or user's avatar from one format to another. * **create-qr-code:** Converts text to a QR Code. +* **danger:** Creates a danger sign with the text of your choice. * **desaturate:** Draws an image or a user's avatar but desaturated. * **dexter:** Draws an image or a user's avatar over the screen of Dexter from Pokémon. * **distort:** Draws an image or a user's avatar but distorted. @@ -1075,7 +1077,9 @@ here. * book ([Books API](https://developers.google.com/books/)) * calendar ([Calendar API](https://developers.google.com/calendar/)) * catch ([Noto Font](https://www.google.com/get/noto/)) + * caution ([Noto Font](https://www.google.com/get/noto/)) * change-my-mind ([Noto Font](https://www.google.com/get/noto/)) + * danger ([Noto Font](https://www.google.com/get/noto/)) * dear-liberals ([Oswald Font](https://fonts.google.com/specimen/Oswald)) * demotivational ([Noto Font](https://www.google.com/get/noto/)) * drakeposting ([Noto Font](https://www.google.com/get/noto/)) @@ -1655,6 +1659,9 @@ here. * hat ([Anon Hat Image](https://whyweprotest.net/threads/big-ass-guy-fawkes-mask-images-thread.22719/)) - [wikiHow](https://www.wikihow.com/Main-Page) * wikihow ([API](https://www.wikihow.com/api.php)) +- [Wikimedia Commons](https://commons.wikimedia.org/wiki/Main_Page) + * caution ([Image](https://commons.wikimedia.org/wiki/File:Caution_blank.svg)) + * danger ([Image](https://commons.wikimedia.org/wiki/File:Danger_blank.svg)) - [Wikipedia](https://www.wikipedia.org/) * fact ([API](https://en.wikipedia.org/w/api.php)) * idiot (URL) diff --git a/assets/images/caution.png b/assets/images/caution.png new file mode 100644 index 00000000..b5fc9d70 Binary files /dev/null and b/assets/images/caution.png differ diff --git a/assets/images/danger.png b/assets/images/danger.png new file mode 100644 index 00000000..bc289335 Binary files /dev/null and b/assets/images/danger.png differ diff --git a/commands/edit-image/caution.js b/commands/edit-image/caution.js new file mode 100644 index 00000000..a057b3c0 --- /dev/null +++ b/commands/edit-image/caution.js @@ -0,0 +1,66 @@ +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-Bold.ttf'), { family: 'Noto', weight: 'bold' }); + +module.exports = class CautionCommand extends Command { + constructor(client) { + super(client, { + name: 'caution', + aliases: ['caution-sign'], + group: 'edit-image', + memberName: 'caution', + description: 'Creates a caution sign 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/' + }, + { + name: 'Wikimedia Commons', + url: 'https://commons.wikimedia.org/wiki/Main_Page', + reason: 'Image', + reasonURL: 'https://commons.wikimedia.org/wiki/File:Caution_blank.svg' + } + ], + args: [ + { + key: 'text', + prompt: 'What text should the caution sign say?', + type: 'string', + max: 500 + } + ] + }); + } + + async run(msg, { text }) { + const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'caution.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 = 'normal bold 60px Noto'; + let fontSize = 60; + while (ctx.measureText(text).width > 3580) { + fontSize--; + ctx.font = `normal bold ${fontSize}px Noto`; + } + const lines = await wrapText(ctx, text.toUpperCase(), 895); + const topMost = 470 - (((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], base.width / 2, height); + } + return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'caution.png' }] }); + } +}; diff --git a/commands/edit-image/danger.js b/commands/edit-image/danger.js new file mode 100644 index 00000000..613b4e09 --- /dev/null +++ b/commands/edit-image/danger.js @@ -0,0 +1,66 @@ +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-Bold.ttf'), { family: 'Noto', weight: 'bold' }); + +module.exports = class DangerCommand extends Command { + constructor(client) { + super(client, { + name: 'danger', + aliases: ['danger-sign'], + group: 'edit-image', + memberName: 'danger', + description: 'Creates a danger sign 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/' + }, + { + name: 'Wikimedia Commons', + url: 'https://commons.wikimedia.org/wiki/Main_Page', + reason: 'Image', + reasonURL: 'https://commons.wikimedia.org/wiki/File:Danger_blank.svg' + } + ], + args: [ + { + key: 'text', + prompt: 'What text should the danger sign say?', + type: 'string', + max: 500 + } + ] + }); + } + + async run(msg, { text }) { + const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'danger.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 = 'normal bold 60px Noto'; + let fontSize = 60; + while (ctx.measureText(text).width > 2520) { + fontSize--; + ctx.font = `normal bold ${fontSize}px Noto`; + } + const lines = await wrapText(ctx, text.toUpperCase(), 320); + const topMost = 510 - (((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], base.width / 2, height); + } + return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'danger.png' }] }); + } +}; diff --git a/package.json b/package.json index b65aeffb..7ea2505c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "119.8.0", + "version": "119.9.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {