Dexter Command

This commit is contained in:
Daniel Odendahl Jr
2017-05-17 01:42:17 +00:00
parent 34c9fce972
commit 652176857b
3 changed files with 55 additions and 1 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

+54
View File
@@ -0,0 +1,54 @@
const { Command } = require('discord.js-commando');
const Canvas = require('canvas');
const snekfetch = require('snekfetch');
const { promisifyAll } = require('tsubaki');
const fs = promisifyAll(require('fs'));
const path = require('path');
module.exports = class DexterCommand extends Command {
constructor(client) {
super(client, {
name: 'dexter',
group: 'avataredit',
memberName: 'dexter',
description: 'Who\'s that pokemon?',
args: [
{
key: 'user',
prompt: 'Which user would you like to edit the avatar of?',
type: 'user'
}
]
});
}
async run(msg, args) {
if (msg.channel.type !== 'dm')
if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES'))
return msg.say('This Command requires the `Attach Files` Permission.');
const { user } = args;
const avatarURL = user.avatarURL('png', 256);
if (!avatarURL) return msg.say('This user has no avatar.');
try {
const Image = Canvas.Image;
const canvas = new Canvas(744, 554);
const ctx = canvas.getContext('2d');
const base = new Image();
const avatar = new Image();
const generate = () => {
ctx.drawImage(base, 0, 0);
ctx.rotate(-10 * Math.PI / 180);
ctx.drawImage(avatar, 279, 179, 225, 225);
ctx.rotate(10 * Math.PI / 180);
};
base.src = await fs.readFileAsync(path.join(__dirname, '..', '..', 'assets', 'images', 'dexter.png'));
const { body } = await snekfetch.get(avatarURL);
avatar.src = body;
generate();
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'dexter.png' }] })
.catch(err => msg.say(`${err.name}: ${err.message}`));
} catch (err) {
return msg.say(`${err.name}: ${err.message}`);
}
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "19.6.3",
"version": "19.7.0",
"description": "A Discord Bot",
"main": "shardingmanager.js",
"scripts": {