Files
xiao/commands/avatar-edit/beautiful.js
T
Daniel Odendahl Jr 5e7a8d17ad Remove Stuff
2017-06-22 03:17:03 +00:00

55 lines
1.9 KiB
JavaScript

const Command = require('../../structures/Command');
const Canvas = require('canvas');
const snekfetch = require('snekfetch');
const { promisifyAll } = require('tsubaki');
const fs = promisifyAll(require('fs'));
const path = require('path');
module.exports = class BeautifulCommand extends Command {
constructor(client) {
super(client, {
name: 'beautiful',
aliases: ['grunkle-stan'],
group: 'avatar-edit',
memberName: 'beautiful',
description: 'Draws a user\'s avatar over Gravity Falls\' "Oh, this? This is beautiful." meme.',
throttling: {
usages: 1,
duration: 30
},
clientPermissions: ['ATTACH_FILES'],
args: [
{
key: 'user',
prompt: 'Which user would you like to edit the avatar of?',
type: 'user',
default: ''
}
]
});
}
async run(msg, args) {
const user = args.user || msg.author;
const avatarURL = user.displayAvatarURL({
format: 'png',
size: 256
});
const Image = Canvas.Image;
const canvas = new Canvas(500, 532);
const ctx = canvas.getContext('2d');
const base = new Image();
const avatar = new Image();
const generate = () => {
ctx.drawImage(base, 0, 0);
ctx.drawImage(avatar, 341, 35, 117, 135);
ctx.drawImage(avatar, 343, 301, 117, 135);
};
base.src = await fs.readFileAsync(path.join(__dirname, '..', '..', 'assets', 'images', 'beautiful.png'));
const { body } = await snekfetch.get(avatarURL);
avatar.src = body;
generate();
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'beautiful.png' }] });
}
};