yugiohtoken accepts images

This commit is contained in:
Dragon Fire
2020-06-14 23:53:47 -04:00
parent 3b57513a81
commit 5dcd367a56
3 changed files with 13 additions and 13 deletions
+1 -1
View File
@@ -102,7 +102,7 @@ module.exports = class YuGiOhGenCommand extends Command {
key: 'image', key: 'image',
prompt: 'What image would you like to edit?', prompt: 'What image would you like to edit?',
type: 'image', type: 'image',
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 256 }) default: msg => msg.author.displayAvatarURL({ format: 'png', size: 1024 })
} }
] ]
}); });
@@ -8,9 +8,9 @@ module.exports = class YuGiOhTokenCommand extends Command {
super(client, { super(client, {
name: 'yu-gi-oh-token', name: 'yu-gi-oh-token',
aliases: ['ygo-token'], aliases: ['ygo-token'],
group: 'edit-avatar', group: 'edit-image',
memberName: 'yu-gi-oh-token', memberName: 'yu-gi-oh-token',
description: 'Draws a user\'s avatar over a blank Yu-Gi-Oh! Token card.', description: 'Draws an image or a user\'s avatar over a blank Yu-Gi-Oh! Token card.',
throttling: { throttling: {
usages: 1, usages: 1,
duration: 10 duration: 10
@@ -26,27 +26,27 @@ module.exports = class YuGiOhTokenCommand extends Command {
], ],
args: [ args: [
{ {
key: 'user', key: 'image',
prompt: 'Which user would you like to edit the avatar of?', prompt: 'What image would you like to edit?',
type: 'user', type: 'image',
default: msg => msg.author default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 })
} }
] ]
}); });
} }
async run(msg, { user }) { async run(msg, { image }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 });
try { try {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'yu-gi-oh-token.png')); const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'yu-gi-oh-token.png'));
const { body } = await request.get(avatarURL); const { body } = await request.get(image);
const avatar = await loadImage(body); const data = await loadImage(body);
const canvas = createCanvas(base.width, base.height); const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
ctx.fillStyle = 'white'; ctx.fillStyle = 'white';
ctx.fillRect(0, 0, base.width, base.height); ctx.fillRect(0, 0, base.width, base.height);
ctx.drawImage(base, 0, 0); ctx.drawImage(base, 0, 0);
ctx.drawImage(avatar, 45, 102, 293, 294); const height = 294 / data.width;
ctx.drawImage(data, 45, 102, 294, data.height * height);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'yu-gi-oh-token.png' }] }); return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'yu-gi-oh-token.png' }] });
} catch (err) { } catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "116.27.1", "version": "116.27.2",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"scripts": { "scripts": {