diff --git a/README.md b/README.md index cfd24a6d..e8240eba 100644 --- a/README.md +++ b/README.md @@ -651,7 +651,7 @@ Total: 504 * **demotivational:** Draws an image or a user's avatar and the text you specify as a demotivational poster. * **dislike:** Sends an "Everyone Disliked That" meme with the image of your choice. * **distracted-boyfriend:** Draws three user's avatars over the "Distracted Boyfriend" meme. -* **drakeposting:** Draws two user's avatars over the "Drakeposting" meme. +* **drakeposting:** Sends a "Drakeposting" meme with the text of your choice. * **edd-facts-book:** Sends a "Double D's Facts Book" meme with the fact of your choice. * **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. @@ -1044,6 +1044,7 @@ here. * change-my-mind ([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/)) * edd-facts-book ([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)) diff --git a/commands/edit-meme/drakeposting.js b/commands/edit-meme/drakeposting.js index 2878c74f..5fab5215 100644 --- a/commands/edit-meme/drakeposting.js +++ b/commands/edit-meme/drakeposting.js @@ -1,7 +1,10 @@ const Command = require('../../structures/Command'); -const { createCanvas, loadImage } = require('canvas'); -const request = require('node-superfetch'); +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 DrakepostingCommand extends Command { constructor(client) { @@ -10,7 +13,7 @@ module.exports = class DrakepostingCommand extends Command { aliases: ['drake'], group: 'edit-meme', memberName: 'drakeposting', - description: 'Draws two user\'s avatars over the "Drakeposting" meme.', + description: 'Sends a "Drakeposting" meme with the text of your choice.', throttling: { usages: 1, duration: 10 @@ -22,37 +25,63 @@ module.exports = class DrakepostingCommand extends Command { url: 'https://drakeofficial.com/', reason: 'Original "Hotline Bling" Music Video', reasonURL: 'https://youtu.be/uxpDa-c-4Mc' + }, + { + name: 'Google', + url: 'https://www.google.com/', + reason: 'Noto Font', + reasonURL: 'https://www.google.com/get/noto/' } ], args: [ { key: 'nah', - prompt: 'Which user should be the "nah"?', - type: 'user' + prompt: 'What text should be the "nah"?', + type: 'string', + max: 500 }, { key: 'yeah', - prompt: 'Which user should be the "yeah"?', - type: 'user' + prompt: 'What text should be the "yeah"?', + type: 'string', + max: 500 } ] }); } async run(msg, { nah, yeah }) { - const nahAvatarURL = nah.displayAvatarURL({ format: 'png', size: 512 }); - const yeahAvatarURL = yeah.displayAvatarURL({ format: 'png', size: 512 }); try { const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'drakeposting.png')); - const nahAvatarData = await request.get(nahAvatarURL); - const nahAvatar = await loadImage(nahAvatarData.body); - const yeahAvatarData = await request.get(yeahAvatarURL); - const yeahAvatar = await loadImage(yeahAvatarData.body); const canvas = createCanvas(base.width, base.height); const ctx = canvas.getContext('2d'); ctx.drawImage(base, 0, 0); - ctx.drawImage(nahAvatar, 512, 0, 512, 512); - ctx.drawImage(yeahAvatar, 512, 512, 512, 512); + ctx.textAlign = 'center'; + ctx.textBaseline = 'top'; + ctx.font = '50px Noto'; + let fontSize = 50; + while (ctx.measureText(nah).width > 3003) { + fontSize--; + ctx.font = `${fontSize}px Noto`; + } + const nahLines = await wrapText(ctx, nah, 462); + const nahTopMost = 256 - (((fontSize * nahLines.length) / 2) + ((10 * (nahLines.length - 1)) / 2)); + for (let i = 0; i < nahLines.length; i++) { + const height = nahTopMost + ((fontSize + 10) * i); + ctx.fillText(nahLines[i], 768, height); + } + ctx.font = '50px Noto'; + fontSize = 50; + while (ctx.measureText(yea).width > 3003) { + fontSize--; + ctx.font = `${fontSize}px Noto`; + } + const yeahLines = await wrapText(ctx, yeah, 462); + const yeahTopMost = 768 - (((fontSize * yeahLines.length) / 2) + ((10 * (yeahLines.length - 1)) / 2)); + for (let i = 0; i < yeahLines.length; i++) { + const height = yeahTopMost + ((fontSize + 10) * i); + ctx.fillText(yeahLines[i], 768, height); + } return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'drakeposting.png' }] }); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/package.json b/package.json index d7ff728f..ac74fb1b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "116.41.0", + "version": "117.0.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {