Support images is bob-ross, steam-card, wanted, look-what-karen-have

This commit is contained in:
Dragon Fire
2020-07-06 10:22:26 -04:00
parent c6a3bec3ac
commit f4b66966c7
6 changed files with 61 additions and 53 deletions
@@ -2,15 +2,16 @@ const Command = require('../../structures/Command');
const { createCanvas, loadImage } = require('canvas');
const request = require('node-superfetch');
const path = require('path');
const { centerImagePart } = require('../../util/Canvas');
module.exports = class BobRossCommand extends Command {
constructor(client) {
super(client, {
name: 'bob-ross',
aliases: ['ross'],
group: 'edit-avatar',
group: 'edit-image',
memberName: 'bob-ross',
description: 'Draws a user\'s avatar over Bob Ross\' canvas.',
description: 'Draws an image or a user\'s avatar over Bob Ross\' canvas.',
throttling: {
usages: 1,
duration: 10
@@ -31,26 +32,26 @@ module.exports = class BobRossCommand extends Command {
],
args: [
{
key: 'user',
prompt: 'Which user would you like to edit the avatar of?',
type: 'user',
default: msg => msg.author
key: 'image',
prompt: 'What image would you like to edit?',
type: 'image',
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 })
}
]
});
}
async run(msg, { user }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 });
async run(msg, { image }) {
try {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'bob-ross.png'));
const { body } = await request.get(avatarURL);
const avatar = await loadImage(body);
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 = 'white';
ctx.fillRect(0, 0, base.width, base.height);
ctx.drawImage(avatar, 15, 20, 440, 440);
const { x, y, width, height } = centerImagePart(data, 440, 440, 15, 20);
ctx.drawImage(data, x, y, width, height);
ctx.drawImage(base, 0, 0);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'bob-ross.png' }] });
} catch (err) {
@@ -11,9 +11,9 @@ module.exports = class SteamCardCommand extends Command {
super(client, {
name: 'steam-card',
aliases: ['valve-card'],
group: 'edit-avatar',
group: 'edit-image',
memberName: 'steam-card',
description: 'Draws a user\'s avatar on a Steam Trading Card.',
description: 'Draws an image or a user\'s avatar on a Steam Trading Card.',
throttling: {
usages: 1,
duration: 10
@@ -41,32 +41,38 @@ module.exports = class SteamCardCommand extends Command {
],
args: [
{
key: 'user',
prompt: 'Which user would you like to edit the avatar of?',
type: 'user',
default: msg => msg.author
key: 'name',
prompt: 'What do you want the card to be named?',
type: 'string',
max: 50
},
{
key: 'image',
prompt: 'What image would you like to edit?',
type: 'image',
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 256 })
}
]
});
}
async run(msg, { user }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 256 });
async run(msg, { name, image }) {
try {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'steam-card.png'));
const { body } = await request.get(avatarURL);
const avatar = await loadImage(body);
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 = '#feb2c1';
ctx.fillRect(0, 0, base.width, base.height);
ctx.drawImage(avatar, 12, 19, 205, 205);
const height = 205 / data.width;
ctx.drawImage(data, 12, 19, 205, height * data.height);
ctx.drawImage(base, 0, 0);
ctx.font = '14px Noto';
ctx.fillStyle = 'black';
ctx.fillText(user.username, 16, 25);
ctx.fillText(name, 16, 25);
ctx.fillStyle = 'white';
ctx.fillText(user.username, 15, 24);
ctx.fillText(name, 15, 24);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'steam-card.png' }] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
@@ -2,16 +2,16 @@ const Command = require('../../structures/Command');
const { createCanvas, loadImage } = require('canvas');
const request = require('node-superfetch');
const path = require('path');
const { sepia } = require('../../util/Canvas');
const { sepia, centerImagePart } = require('../../util/Canvas');
module.exports = class WantedCommand extends Command {
constructor(client) {
super(client, {
name: 'wanted',
aliases: ['wanted-poster'],
group: 'edit-avatar',
group: 'edit-image',
memberName: 'wanted',
description: 'Draws a user\'s avatar over a wanted poster.',
description: 'Draws an image or a user\'s avatar over a wanted poster.',
throttling: {
usages: 1,
duration: 10
@@ -27,26 +27,26 @@ module.exports = class WantedCommand extends Command {
],
args: [
{
key: 'user',
prompt: 'Which user would you like to edit the avatar of?',
type: 'user',
default: msg => msg.author
key: 'image',
prompt: 'What image would you like to edit?',
type: 'image',
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 })
}
]
});
}
async run(msg, { user }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 });
async run(msg, { image }) {
try {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'wanted.png'));
const { body } = await request.get(avatarURL);
const avatar = await loadImage(body);
const { body } = await request.get(image);
const data = await loadImage(body);
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(base, 0, 0);
ctx.drawImage(avatar, 150, 360, 430, 430);
sepia(ctx, 150, 360, 430, 430);
const { x, y, width, height } = centerImagePart(data, 430, 430, 150, 360);
ctx.drawImage(data, x, y, width, height);
sepia(ctx, x, y, width, height);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'wanted.png' }] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
@@ -2,15 +2,16 @@ const Command = require('../../structures/Command');
const { createCanvas, loadImage } = require('canvas');
const request = require('node-superfetch');
const path = require('path');
const { centerImagePart } = require('../../util/Canvas');
module.exports = class LookWhatKarenHaveCommand extends Command {
constructor(client) {
super(client, {
name: 'look-what-karen-have',
aliases: ['look-at-what-karen-has', 'look-what-karen-has'],
group: 'edit-avatar',
group: 'edit-meme',
memberName: 'look-what-karen-have',
description: 'Draws a user\'s avatar over Karen\'s piece of paper.',
description: 'Draws an image or a user\'s avatar over Karen\'s piece of paper.',
throttling: {
usages: 1,
duration: 10
@@ -31,27 +32,27 @@ module.exports = class LookWhatKarenHaveCommand extends Command {
],
args: [
{
key: 'user',
prompt: 'Which user would you like to edit the avatar of?',
type: 'user',
default: msg => msg.author
key: 'image',
prompt: 'What image would you like to edit?',
type: 'image',
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 })
}
]
});
}
async run(msg, { user }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 });
async run(msg, { image }) {
try {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'look-what-karen-have.png'));
const { body } = await request.get(avatarURL);
const avatar = await loadImage(body);
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 = 'white';
ctx.fillRect(0, 0, base.width, base.height);
ctx.rotate(-6.5 * (Math.PI / 180));
ctx.drawImage(avatar, 514, 50, 512, 512);
const { x, y, width, height } = centerImagePart(data, 512, 512, 514, 50);
ctx.drawImage(data, x, y, width, height);
ctx.rotate(6.5 * (Math.PI / 180));
ctx.drawImage(base, 0, 0);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'look-what-karen-have.png' }] });