Files
xiao/commands/edit-meme/ugly.js
T
Dragon Fire b03ae1aeaa Ugly Command
2021-04-18 09:50:09 -04:00

55 lines
1.7 KiB
JavaScript

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 UglyCommand extends Command {
constructor(client) {
super(client, {
name: 'ugly',
aliases: ['uglier', 'uglier-up-close'],
group: 'edit-meme',
memberName: 'ugly',
description: 'Draws an image or a user\'s avatar over the "It\'s even uglier up close" meme.',
throttling: {
usages: 2,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'Nickelodeon',
url: 'https://www.nick.com/',
reason: 'Original "Spongebob Squarepants" Show',
reasonURL: 'https://www.nick.com/shows/spongebob-squarepants'
}
],
args: [
{
key: 'image',
prompt: 'What image would you like to edit?',
type: 'image-or-avatar',
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 256 })
}
]
});
}
async run(msg, { image }) {
try {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'ugly.png'));
const { body } = await request.get(image);
const data = await loadImage(body);
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
const { x, y, width, height } = centerImagePart(data, 170, 170, 120, 52);
ctx.drawImage(data, x, y, width, height);
ctx.drawImage(base, 0, 0);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'ugly.png' }] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};