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
+61
View File
@@ -0,0 +1,61 @@
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-image',
memberName: 'bob-ross',
description: 'Draws an image or a user\'s avatar over Bob Ross\' canvas.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'Know Your Meme',
url: 'https://knowyourmeme.com/',
reason: 'Image',
reasonURL: 'https://knowyourmeme.com/photos/1160348'
},
{
name: 'Bob Ross',
url: 'https://www.bobross.com/',
reason: 'Himself'
}
],
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', 'bob-ross.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 = 'white';
ctx.fillRect(0, 0, base.width, base.height);
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) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+81
View File
@@ -0,0 +1,81 @@
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 SteamCardCommand extends Command {
constructor(client) {
super(client, {
name: 'steam-card',
aliases: ['valve-card'],
group: 'edit-image',
memberName: 'steam-card',
description: 'Draws an image or a user\'s avatar on a Steam Trading Card.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'Steam',
url: 'https://store.steampowered.com/',
reason: 'Original Design',
reasonURL: 'https://steamcommunity.com/tradingcards/'
},
{
name: 'SinKillerJ Tachikawa',
url: 'https://www.deviantart.com/sinkillerj',
reason: 'Template',
reasonURL: 'https://www.deviantart.com/sinkillerj/art/Steam-Trading-Card-Template-GIMP-372156984'
},
{
name: 'Google',
url: 'https://www.google.com/',
reason: 'Noto Font',
reasonURL: 'https://www.google.com/get/noto/'
}
],
args: [
{
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, { name, image }) {
try {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'steam-card.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 = '#feb2c1';
ctx.fillRect(0, 0, base.width, base.height);
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(name, 16, 25);
ctx.fillStyle = 'white';
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!`);
}
}
};
+55
View File
@@ -0,0 +1,55 @@
const Command = require('../../structures/Command');
const { createCanvas, loadImage } = require('canvas');
const request = require('node-superfetch');
const path = require('path');
const { sepia, centerImagePart } = require('../../util/Canvas');
module.exports = class WantedCommand extends Command {
constructor(client) {
super(client, {
name: 'wanted',
aliases: ['wanted-poster'],
group: 'edit-image',
memberName: 'wanted',
description: 'Draws an image or a user\'s avatar over a wanted poster.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'Tim\'s Printables',
url: 'https://www.timvandevall.com/',
reason: 'Image',
reasonURL: 'https://www.pinterest.com/pin/365002744774849370/'
}
],
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', 'wanted.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.drawImage(base, 0, 0);
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!`);
}
}
};