mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 15:07:42 +02:00
I wonder if this will work
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 174 KiB |
@@ -0,0 +1,62 @@
|
||||
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 SimbaCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'simba',
|
||||
group: 'avataredit',
|
||||
memberName: 'simba',
|
||||
description: 'Remember who you are...',
|
||||
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(500, 281);
|
||||
const ctx = canvas.getContext('2d');
|
||||
const base = new Image();
|
||||
const avatar = new Image();
|
||||
const generate = () => {
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.fillRect(0, 0, 500, 281);
|
||||
ctx.rotate(-24 * Math.PI / 180);
|
||||
ctx.drawImage(avatar, 115, 63, 200, 220);
|
||||
const imgData = ctx.getImageData(115, 63, 200, 220);
|
||||
const data = imgData.data;
|
||||
for (let i = 0; i < data.length; i += 4) {
|
||||
data[i] = Math.min(255, data[i]);
|
||||
}
|
||||
ctx.putImageData(imgData, 115, 63);
|
||||
ctx.rotate(24 * Math.PI / 180);
|
||||
ctx.drawImage(base, 0, 0);
|
||||
};
|
||||
base.src = await fs.readFileAsync(path.join(__dirname, '..', '..', 'assets', 'images', 'simba.png'));
|
||||
const { body } = await snekfetch.get(avatarURL);
|
||||
avatar.src = body;
|
||||
generate();
|
||||
return msg.channel.send({ files: [{ attachment: canvas.toBuffer(), name: 'simba.png' }] })
|
||||
.catch(err => msg.say(err));
|
||||
} catch (err) {
|
||||
return msg.say('An Error Occurred while creating the image.');
|
||||
}
|
||||
}
|
||||
};
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiaobot",
|
||||
"version": "19.4.0",
|
||||
"version": "19.5.0",
|
||||
"description": "A Discord Bot",
|
||||
"main": "shardingmanager.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user