Meme Gen Group

This commit is contained in:
Dragon Fire
2019-12-03 17:02:32 -05:00
parent 6ba24f0e0d
commit d5cffb0012
27 changed files with 54 additions and 50 deletions
-60
View File
@@ -1,60 +0,0 @@
const Command = require('../../structures/Command');
const { createCanvas, loadImage, registerFont } = require('canvas');
const { stripIndents } = require('common-tags');
const path = require('path');
const { wrapText } = require('../../util/Canvas');
const texts = require('../../assets/json/be-like-bill');
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 BeLikeBillCommand extends Command {
constructor(client) {
super(client, {
name: 'be-like-bill',
aliases: ['be-like'],
group: 'image-edit',
memberName: 'be-like-bill',
description: 'Sends a "Be Like Bill" meme with the name of your choice.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'Google Noto Fonts',
url: 'https://www.google.com/get/noto/'
}
],
args: [
{
key: 'name',
prompt: 'What should the name on the meme be?',
type: 'string',
default: 'Bill',
max: 20
}
]
});
}
async run(msg, { name }) {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'be-like-bill.png'));
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(base, 0, 0);
ctx.font = '23px Noto';
const text = await wrapText(ctx, texts[Math.floor(Math.random() * texts.length)].replace(/{{name}}/gi, name), 569);
ctx.fillText(stripIndents`
This is ${name}.
${text.join('\n')}
${name} is smart.
Be like ${name}.
`, 31, 80);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'be-like-bill.png' }] });
}
};
-45
View File
@@ -1,45 +0,0 @@
const Command = require('../../structures/Command');
const { createCanvas, loadImage } = require('canvas');
const path = require('path');
module.exports = class CursedSpongeCommand extends Command {
constructor(client) {
super(client, {
name: 'cursed-sponge',
aliases: ['sponge-snail'],
group: 'image-edit',
memberName: 'cursed-sponge',
description: 'Sends a cursed sponge duplicated however many times you want.',
throttling: {
usages: 1,
duration: 30
},
clientPermissions: ['ATTACH_FILES'],
args: [
{
key: 'amount',
prompt: 'How many times do you want to duplicate the cursed sponge?',
type: 'integer',
max: 100,
min: 1
}
]
});
}
async run(msg, { amount }) {
const sponge = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'cursed-sponge.png'));
const rows = Math.ceil(amount / 10);
const canvas = createCanvas(sponge.width * (rows > 1 ? 10 : amount), sponge.height * rows);
const ctx = canvas.getContext('2d');
let width = 0;
for (let i = 0; i < amount; i++) {
const row = Math.ceil((i + 1) / 10);
ctx.drawImage(sponge, width, sponge.height * (row - 1));
if ((width + sponge.width) === (sponge.width * (rows > 1 ? 10 : amount))) width = 0;
else width += sponge.width;
}
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'cursed-sponge.png' }] });
}
};
-95
View File
@@ -1,95 +0,0 @@
const Command = require('../../structures/Command');
const { createCanvas, loadImage, registerFont } = require('canvas');
const request = require('node-superfetch');
const path = require('path');
const { shortenText } = 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 DemotivationalCommand extends Command {
constructor(client) {
super(client, {
name: 'demotivational',
aliases: ['demotivational-poster'],
group: 'image-edit',
memberName: 'demotivational',
description: 'Draws an image or a user\'s avatar and the text you specify as a demotivational poster.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'Google Noto Fonts',
url: 'https://www.google.com/get/noto/'
}
],
args: [
{
key: 'title',
prompt: 'What should the title of the poster be?',
type: 'string',
max: 50,
parse: title => title.toUpperCase()
},
{
key: 'text',
prompt: 'What should the text of the poster be?',
type: 'string',
max: 100
},
{
key: 'image',
prompt: 'What image would you like to edit?',
type: 'image',
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 })
}
]
});
}
async run(msg, { title, text, image }) {
try {
const { body } = await request.get(image);
const data = await loadImage(body);
const canvas = createCanvas(750, 600);
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'black';
ctx.fillRect(0, 0, canvas.width, canvas.height);
let { width, height } = data;
const maxWidth = 602;
if (width > maxWidth) {
const ratio = maxWidth / width;
width = maxWidth;
height *= ratio;
}
const maxHeight = 402;
if (height > maxHeight) {
const ratio = maxHeight / height;
height = maxHeight;
width *= ratio;
}
const x = (canvas.width / 2) - (width / 2);
const y = 44 + ((402 / 2) - (height / 2));
ctx.fillStyle = 'white';
ctx.fillRect(x - 4, y - 4, width + 8, height + 8);
ctx.fillStyle = 'black';
ctx.fillRect(x - 2, y - 2, width + 4, height + 4);
ctx.fillStyle = 'white';
ctx.fillRect(x, y, width, height);
ctx.drawImage(data, x, y, width, height);
ctx.textAlign = 'center';
ctx.font = '60px Noto';
ctx.fillStyle = 'aquamarine';
ctx.fillText(shortenText(ctx, title, 610), 375, 518);
ctx.font = '27px Noto';
ctx.fillStyle = 'white';
ctx.fillText(shortenText(ctx, text, 610), 375, 565);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'demotivational-poster.png' }] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
-82
View File
@@ -1,82 +0,0 @@
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 = [[450, 129], [1200, 134], [450, 627], [1200, 627]];
module.exports = class GruPlanCommand extends Command {
constructor(client) {
super(client, {
name: 'gru-plan',
aliases: ['grus-plan', 'gru'],
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'],
credit: [
{
name: 'Despicable Me',
url: 'http://www.despicable.me/'
},
{
name: 'Google Noto Fonts',
url: 'https://www.google.com/get/noto/'
}
],
args: [
{
key: 'step1',
label: 'step 1',
prompt: 'What should the first step of Gru\'s plan be?',
type: 'string',
max: 150
},
{
key: 'step2',
label: 'step 2',
prompt: 'What should the second step of Gru\'s plan be?',
type: 'string',
max: 150
},
{
key: 'step3',
label: 'step 3',
prompt: 'What should the third step of Gru\'s plan be?',
type: 'string',
max: 150
}
]
});
}
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) {
ctx.font = '35px Noto';
const step = steps[i];
let fontSize = 35;
while (ctx.measureText(step).width > 1100) {
fontSize -= 1;
ctx.font = `${fontSize}px Noto`;
}
const lines = await wrapText(ctx, step, 252);
ctx.fillText(lines.join('\n'), x, y);
i++;
}
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'gru-plan.png' }] });
}
};
-70
View File
@@ -1,70 +0,0 @@
const { Command } = require('discord.js-commando');
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 IllegalCommand extends Command {
constructor(client) {
super(client, {
name: 'illegal',
aliases: ['is-now-illegal', 'trump'],
group: 'image-edit',
memberName: 'illegal',
description: 'Makes President Trump make your text illegal.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'Donald J. Trump',
url: 'https://www.donaldjtrump.com/'
},
{
name: 'Google Noto Fonts',
url: 'https://www.google.com/get/noto/'
}
],
args: [
{
key: 'text',
prompt: 'What should the text of the bill be?',
type: 'string',
max: 20,
parse: text => text.toUpperCase()
},
{
key: 'verb',
prompt: 'Should the text use is, are, or am?',
type: 'string',
default: 'IS',
oneOf: ['is', 'are', 'am'],
parse: verb => verb.toUpperCase()
}
]
});
}
async run(msg, { text, verb }) {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'illegal.png'));
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(base, 0, 0);
ctx.rotate(7 * (Math.PI / 180));
const illegalText = `${text} ${verb} NOW ILLEGAL.`;
let fontSize = 45;
ctx.font = `${fontSize}px Noto`;
while (ctx.measureText(illegalText).width > 550) {
fontSize -= 1;
ctx.font = `${fontSize}px Noto`;
}
const lines = await wrapText(ctx, illegalText, 200);
ctx.fillText(lines.join('\n'), 750, 290);
ctx.rotate(-7 * (Math.PI / 180));
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'illegal.png' }] });
}
};
-54
View File
@@ -1,54 +0,0 @@
const Command = require('../../structures/Command');
const { createCanvas, loadImage } = require('canvas');
const request = require('node-superfetch');
const path = require('path');
module.exports = class KyonGunCommand extends Command {
constructor(client) {
super(client, {
name: 'kyon-gun',
aliases: ['kyon-snapped'],
group: 'image-edit',
memberName: 'kyon-gun',
description: 'Draws an image or a user\'s avatar behind Kyon shooting a gun.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'The Melancholy of Haruhi Suzumiya',
url: 'http://www.haruhi.tv/'
}
],
args: [
{
key: 'image',
prompt: 'What image would you like to edit?',
type: 'image',
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 })
}
]
});
}
async run(msg, { image }) {
try {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'kyon-gun.png'));
const { body } = await request.get(image);
const data = await loadImage(body);
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'black';
ctx.fillRect(0, 0, base.width, base.height);
const ratio = data.width / data.height;
const width = Math.round(base.height * ratio);
ctx.drawImage(data, (base.width / 2) - (width / 2), 0, width, base.height);
ctx.drawImage(base, 0, 0);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'kyon-gun.png' }] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
-62
View File
@@ -1,62 +0,0 @@
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 LisaPresentationCommand extends Command {
constructor(client) {
super(client, {
name: 'lisa-presentation',
aliases: ['lisa'],
group: 'image-edit',
memberName: 'lisa-presentation',
description: 'Sends a "Lisa Presentation" meme with the presentation of your choice.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'The Simpsons',
url: 'http://www.simpsonsworld.com/'
},
{
name: 'Google Noto Fonts',
url: 'https://www.google.com/get/noto/'
}
],
args: [
{
key: 'text',
prompt: 'What should the text of the presentation be?',
type: 'string',
max: 500
}
]
});
}
async run(msg, { text }) {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'lisa-presentation.png'));
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(base, 0, 0);
ctx.textAlign = 'center';
ctx.font = '40px Noto';
let fontSize = 40;
while (ctx.measureText(text).width > 1320) {
fontSize -= 1;
ctx.font = `${fontSize}px Noto`;
}
const lines = await wrapText(ctx, text, 330);
for (let i = 0; i < lines.length; i++) {
const textHeight = 95 + (i * fontSize) + (i * 10);
ctx.fillText(lines[i], base.width / 2, textHeight);
}
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'lisa-presentation.png' }] });
}
};
-93
View File
@@ -1,93 +0,0 @@
const Command = require('../../structures/Command');
const { createCanvas, loadImage, registerFont } = require('canvas');
const request = require('node-superfetch');
const path = require('path');
const { wrapText } = require('../../util/Canvas');
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Impact.ttf'), { family: 'Impact' });
module.exports = class MemeGenCommand extends Command {
constructor(client) {
super(client, {
name: 'meme-gen',
aliases: ['meme-generator', 'create-meme'],
group: 'image-edit',
memberName: 'meme-gen',
description: 'Sends a meme with the text and background of your choice.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'Impact Font',
url: 'https://www.wfonts.com/font/impact'
}
],
args: [
{
key: 'top',
prompt: 'What should the top row of the meme to be?',
type: 'string',
max: 50,
parse: top => top.toUpperCase()
},
{
key: 'bottom',
prompt: 'What should the bottom row of the meme to be?',
type: 'string',
max: 50,
parse: bottom => bottom.toUpperCase()
},
{
key: 'image',
prompt: 'What image would you like to edit?',
type: 'image',
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 2048 })
}
]
});
}
async run(msg, { top, bottom, image }) {
try {
const { body } = await request.get(image);
const base = await loadImage(body);
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(base, 0, 0);
const fontSize = Math.round(base.height / 10);
ctx.font = `${fontSize}px Impact`;
ctx.fillStyle = 'white';
ctx.textAlign = 'center';
ctx.textBaseline = 'top';
const topLines = await wrapText(ctx, top, base.width - 10);
if (!topLines) return msg.reply('There\'s not enough width to make a meme with this image.');
for (let i = 0; i < topLines.length; i++) {
const textHeight = (i * fontSize) + (i * 10);
ctx.strokeStyle = 'black';
ctx.lineWidth = 5;
ctx.strokeText(topLines[i], base.width / 2, textHeight);
ctx.fillStyle = 'white';
ctx.fillText(topLines[i], base.width / 2, textHeight);
}
const bottomLines = await wrapText(ctx, bottom, base.width - 10);
if (!bottomLines) return msg.reply('There\'s not enough width to make a meme with this image.');
ctx.textBaseline = 'bottom';
const initial = base.height - ((bottomLines.length - 1) * fontSize) - ((bottomLines.length - 1) * 10);
for (let i = 0; i < bottomLines.length; i++) {
const textHeight = initial + (i * fontSize) + (i * 10);
ctx.strokeStyle = 'black';
ctx.lineWidth = 5;
ctx.strokeText(bottomLines[i], base.width / 2, textHeight);
ctx.fillStyle = 'white';
ctx.fillText(bottomLines[i], base.width / 2, textHeight);
}
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: 'meme-gen.png' }] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
-55
View File
@@ -1,55 +0,0 @@
const Command = require('../../structures/Command');
const { createCanvas, loadImage, registerFont } = require('canvas');
const path = require('path');
const { shortenText } = 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 NewPasswordCommand extends Command {
constructor(client) {
super(client, {
name: 'new-password',
aliases: ['strong-password', 'new-pswd', 'strong-pswd'],
group: 'image-edit',
memberName: 'new-password',
description: 'Sends a "Weak Password/Strong Password" meme with the passwords of your choice.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'Google Noto Fonts',
url: 'https://www.google.com/get/noto/'
}
],
args: [
{
key: 'weak',
prompt: 'What should the text of the weak password be?',
type: 'string',
max: 50
},
{
key: 'strong',
prompt: 'What should the text of the strong password be?',
type: 'string',
max: 50
}
]
});
}
async run(msg, { weak, strong }) {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'new-password.png'));
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(base, 0, 0);
ctx.font = '25px Noto';
ctx.fillText(shortenText(ctx, weak, 390), 40, 113);
ctx.fillText(shortenText(ctx, strong, 390), 40, 351);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'new-password.png' }] });
}
};
-87
View File
@@ -1,87 +0,0 @@
const Command = require('../../structures/Command');
const { createCanvas, loadImage, registerFont } = require('canvas');
const request = require('node-superfetch');
const path = require('path');
const { wrapText, greyscale, drawImageWithTint } = 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 NikeAdCommand extends Command {
constructor(client) {
super(client, {
name: 'nike-ad',
aliases: ['believe-in-something', 'believe-in'],
group: 'image-edit',
memberName: 'nike-ad',
description: 'Sends a "Believe in Something" Nike Ad meme with the text of your choice.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'Nike',
url: 'https://www.nike.com/'
},
{
name: 'Google Noto Fonts',
url: 'https://www.google.com/get/noto/'
}
],
args: [
{
key: 'something',
prompt: 'What should the something to believe in be?',
type: 'string',
max: 50
},
{
key: 'sacrifice',
prompt: 'What should believing result in (e.g. sacrificing everything)?',
type: 'string',
max: 50
},
{
key: 'image',
prompt: 'What image would you like to edit?',
type: 'image',
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 2048 })
}
]
});
}
async run(msg, { image, something, sacrifice }) {
try {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'nike-ad.png'));
const { body } = await request.get(image);
const data = await loadImage(body);
const canvas = createCanvas(data.width, data.height);
const ctx = canvas.getContext('2d');
drawImageWithTint(ctx, data, 'black', 0, 0, data.width, data.height);
greyscale(ctx, 0, 0, data.width, data.height);
const ratio = base.width / base.height;
const width = data.width / 3;
const height = Math.round(width / ratio);
ctx.drawImage(base, (data.width / 2) - (width / 2), data.height - height, width, height);
const fontSize = Math.round(data.height / 25);
ctx.font = `${fontSize}px Noto`;
ctx.fillStyle = 'white';
ctx.textAlign = 'center';
const lines = await wrapText(ctx, `Believe in ${something}. Even if it means ${sacrifice}.`, data.width - 20);
if (!lines) return msg.reply('There\'s not enough width to make a Nike ad with this image.');
const initial = data.height / 2;
for (let i = 0; i < lines.length; i++) {
const textHeight = initial + (i * fontSize) + (i * 10);
ctx.fillText(lines[i], data.width / 2, textHeight);
}
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: 'nike-ad.png' }] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
-82
View File
@@ -1,82 +0,0 @@
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 = [[240, 63], [689, 63], [705, 383], [220, 380]];
module.exports = class PlanktonPlanCommand extends Command {
constructor(client) {
super(client, {
name: 'plankton-plan',
aliases: ['planktons-plan', 'plankton'],
group: 'image-edit',
memberName: 'plankton-plan',
description: 'Sends a Plankton\'s Plan meme with steps of your choice.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'Spongebob',
url: 'https://www.nick.com/shows/spongebob-squarepants'
},
{
name: 'Google Noto Fonts',
url: 'https://www.google.com/get/noto/'
}
],
args: [
{
key: 'step1',
label: 'step 1',
prompt: 'What should the first step of Plankton\'s plan be?',
type: 'string',
max: 150
},
{
key: 'step2',
label: 'step 2',
prompt: 'What should the second step of Plankton\'s plan be?',
type: 'string',
max: 150
},
{
key: 'step3',
label: 'step 3',
prompt: 'What should the third step of Plankton\'s plan be?',
type: 'string',
max: 150
}
]
});
}
async run(msg, { step1, step2, step3 }) {
const steps = [step1, step2, step3, step3];
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'plankton-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) {
ctx.font = '35px Noto';
const step = steps[i];
let fontSize = 35;
while (ctx.measureText(step).width > 420) {
fontSize -= 1;
ctx.font = `${fontSize}px Noto`;
}
const lines = await wrapText(ctx, step, 155);
ctx.fillText(lines.join('\n'), x, y);
i++;
}
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'plankton-plan.png' }] });
}
};
-53
View File
@@ -1,53 +0,0 @@
const Command = require('../../structures/Command');
const { createCanvas, loadImage } = require('canvas');
const request = require('node-superfetch');
const path = require('path');
module.exports = class SoraSelfieCommand extends Command {
constructor(client) {
super(client, {
name: 'sora-selfie',
group: 'image-edit',
memberName: 'sora-selfie',
description: 'Draws an image or a user\'s avatar behind Sora taking a selfie.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'Kingdom Hearts',
url: 'https://www.kingdomhearts.com/home/us/'
}
],
args: [
{
key: 'image',
prompt: 'What image would you like to edit?',
type: 'image',
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 })
}
]
});
}
async run(msg, { image }) {
try {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'sora-selfie.png'));
const { body } = await request.get(image);
const data = await loadImage(body);
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'black';
ctx.fillRect(0, 0, base.width, base.height);
const ratio = data.width / data.height;
const width = Math.round(base.height * ratio);
ctx.drawImage(data, (base.width / 2) - (width / 2), 0, width, base.height);
ctx.drawImage(base, 0, 0);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'sora-selfie.png' }] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
-72
View File
@@ -1,72 +0,0 @@
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 SpongebobBurnCommand extends Command {
constructor(client) {
super(client, {
name: 'spongebob-burn',
aliases: ['sponge-burn', 'spongebob-fire', 'sponge-fire'],
group: 'image-edit',
memberName: 'spongebob-burn',
description: 'Sends a "Spongebob Throwing Something into a Fire" meme with words of your choice.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'Spongebob',
url: 'https://www.nick.com/shows/spongebob-squarepants'
},
{
name: 'Google Noto Fonts',
url: 'https://www.google.com/get/noto/'
}
],
args: [
{
key: 'burn',
label: 'thing to burn',
prompt: 'What should Spongebob burn?',
type: 'string',
max: 150
},
{
key: 'person',
prompt: 'What should Spongebob be labelled as?',
type: 'string',
max: 15
}
]
});
}
async run(msg, { burn, person }) {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'spongebob-burn.png'));
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(base, 0, 0);
ctx.fillStyle = 'black';
ctx.textBaseline = 'top';
ctx.font = '35px Noto';
let fontSize = 35;
while (ctx.measureText(burn).width > 400) {
fontSize -= 1;
ctx.font = `${fontSize}px Noto`;
}
const lines = await wrapText(ctx, burn, 180);
ctx.fillText(lines.join('\n'), 55, 103);
ctx.font = '25px Noto';
ctx.fillText(person, 382, 26);
ctx.font = '20px Noto';
ctx.fillText(person, 119, 405);
ctx.fillText(person, 439, 434);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'spongebob-burn.png' }] });
}
};
-56
View File
@@ -1,56 +0,0 @@
const Command = require('../../structures/Command');
const { createCanvas, loadImage } = require('canvas');
const request = require('node-superfetch');
const path = require('path');
const { greyscale } = require('../../util/Canvas');
module.exports = class ThugLifeCommand extends Command {
constructor(client) {
super(client, {
name: 'thug-life',
group: 'image-edit',
memberName: 'thug-life',
description: 'Draws "Thug Life" over an image or a user\'s avatar.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'pngimg.com',
url: 'https://pngimg.com/'
}
],
args: [
{
key: 'image',
prompt: 'What image would you like to edit?',
type: 'image',
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 2048 })
}
]
});
}
async run(msg, { image }) {
try {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'thug-life.png'));
const { body } = await request.get(image);
const data = await loadImage(body);
const canvas = createCanvas(data.width, data.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(data, 0, 0);
greyscale(ctx, 0, 0, data.width, data.height);
const ratio = base.width / base.height;
const width = data.width / 2;
const height = Math.round(width / ratio);
ctx.drawImage(base, (data.width / 2) - (width / 2), data.height - height, width, height);
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: 'thug-life.png' }] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
-55
View File
@@ -1,55 +0,0 @@
const Command = require('../../structures/Command');
const { createCanvas, loadImage } = require('canvas');
const request = require('node-superfetch');
const path = require('path');
const { drawImageWithTint } = require('../../util/Canvas');
module.exports = class ToBeContinuedCommand extends Command {
constructor(client) {
super(client, {
name: 'to-be-continued',
group: 'image-edit',
memberName: 'to-be-continued',
description: 'Draws an image with the "To Be Continued..." arrow.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'JoJo\'s Bizzare Adventure',
url: 'http://www.araki-jojo.com/'
}
],
args: [
{
key: 'image',
prompt: 'What image would you like to edit?',
type: 'image',
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 })
}
]
});
}
async run(msg, { image }) {
try {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'to-be-continued.png'));
const { body } = await request.get(image);
const data = await loadImage(body);
const canvas = createCanvas(data.width, data.height);
const ctx = canvas.getContext('2d');
drawImageWithTint(ctx, data, '#704214', 0, 0, data.width, data.height);
const ratio = base.width / base.height;
const width = canvas.width / 2;
const height = Math.round(width / ratio);
ctx.drawImage(base, 0, canvas.height - height, width, height);
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: 'to-be-continued.png' }] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
-55
View File
@@ -1,55 +0,0 @@
const Command = require('../../structures/Command');
const { createCanvas, loadImage } = require('canvas');
const request = require('node-superfetch');
const path = require('path');
module.exports = class VietnamFlashbacksCommand extends Command {
constructor(client) {
super(client, {
name: 'vietnam-flashbacks',
aliases: ['nam-flashbacks', 'vietnam'],
group: 'image-edit',
memberName: 'vietnam-flashbacks',
description: 'Edits Vietnam flashbacks behind an image or a user\'s avatar.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'Horst Faas',
url: 'https://en.wikipedia.org/wiki/Horst_Faas'
}
],
args: [
{
key: 'image',
prompt: 'What image would you like to edit?',
type: 'image',
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 2048 })
}
]
});
}
async run(msg, { image }) {
try {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'vietnam-flashbacks.png'));
const { body } = await request.get(image);
const data = await loadImage(body);
const canvas = createCanvas(data.width, data.height);
const ctx = canvas.getContext('2d');
const ratio = base.width / base.height;
const width = Math.round(data.height * ratio);
ctx.drawImage(base, (data.width / 2) - (width / 2), 0, width, data.height);
ctx.globalAlpha = 0.675;
ctx.drawImage(data, 0, 0);
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: 'vietnam-flashbacks.png' }] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};