Modern Meme Gen Command

This commit is contained in:
Dragon Fire
2020-05-31 12:05:59 -04:00
parent 952ab116ee
commit 994584cc2a
4 changed files with 88 additions and 3 deletions
+3 -1
View File
@@ -224,7 +224,7 @@ in the appropriate channel's topic to use it.
## Commands
Total: 448
Total: 449
### Utility:
@@ -611,6 +611,7 @@ Total: 448
* **like:** Sends an "Everyone Liked That" meme with the image of your choice.
* **lisa-presentation:** Sends a "Lisa Presentation" meme with the presentation of your choice.
* **look-at-this-photograph:** Draws an image or a user's avatar over Nickelback's photograph.
* **meme-gen-modern:** Sends a meme with the text and image of your choice.
* **meme-gen:** Sends a meme with the text and background of your choice.
* **new-password:** Sends a "Weak Password/Strong Password" meme with the passwords of your choice.
* **nike-ad:** Sends a "Believe in Something" Nike Ad meme with the text of your choice.
@@ -960,6 +961,7 @@ here.
* illegal ([Noto Font](https://www.google.com/get/noto/))
* lisa-presentation ([Noto Font](https://www.google.com/get/noto/))
* map ([Maps Static API](https://developers.google.com/maps/documentation/maps-static/intro))
* modern-meme-gen ([Noto Font](https://www.google.com/get/noto/))
* new-password ([Noto Font](https://www.google.com/get/noto/))
* nike-ad ([Noto Font](https://www.google.com/get/noto/))
* periodic-table ([Noto Font](https://www.google.com/get/noto/))
+1 -1
View File
@@ -68,7 +68,7 @@ module.exports = class TweetCommand extends Command {
const ctx = canvas.getContext('2d');
ctx.font = '23px Noto';
const lines = await wrapText(ctx, text, 710);
const linesLen = (23 * lines.length) + (9 * (lines.length - 1));
const linesLen = (23 * lines.length) + (23 * (text.split('\n').length - 1)) + (9 * (lines.length - 1));
canvas.height += linesLen;
const likes = Math.floor(Math.random() * 100000) + 1;
const retweets = Math.floor(Math.random() * 100000) + 1;
+83
View File
@@ -0,0 +1,83 @@
const Command = require('../../structures/Command');
const { createCanvas, loadImage, registerFont } = require('canvas');
const request = require('node-superfetch');
const path = require('path');
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 MemeGenModernCommand extends Command {
constructor(client) {
super(client, {
name: 'meme-gen-modern',
aliases: [
'meme-generator-modern',
'create-meme-modern',
'meme-gen-m',
'modern-meme-gen',
'modern-meme-generator',
'create-modern-meme',
'm-meme-gen',
'm-meme-generator',
'create-m-meme',
],
group: 'edit-meme',
memberName: 'meme-gen-modern',
description: 'Sends a meme with the text and image 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 should the text of the meme be?',
type: 'string'
},
{
key: 'image',
prompt: 'What image would you like to edit?',
type: 'image',
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 1024 })
}
]
});
}
async run(msg, { text, image }) {
try {
const { body } = await request.get(image);
const base = await loadImage(body);
const scaleH = plate.width / base.width;
const height = Math.round(base.height * scaleH);
const canvas = createCanvas(plate.width, plate.height + height);
const ctx = canvas.getContext('2d');
ctx.font = '23px Noto';
ctx.fillStyle = 'black';
ctx.textBaseline = 'top';
const lines = await wrapText(ctx, text, plate.width - 10);
const linesLen = (23 * lines.length) + (23 * (text.split('\n').length - 1)) + (9 * lines.length);
canvas.height += linesLen;
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, base.width, height);
ctx.fillStyle = 'black';
ctx.fillText(lines.join('\n'), 5, 5);
ctx.drawImage(base, 0, height + 1);
const attachment = canvas.toBuffer();
if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
return msg.say({ files: [{ attachment, name: 'modern-meme-gen.png' }] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "114.33.1",
"version": "114.34.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {