Files
xiao/commands/analyze/image-size.js
T
2020-07-04 11:57:26 -04:00

38 lines
1.0 KiB
JavaScript

const Command = require('../../structures/Command');
const { loadImage } = require('canvas');
const request = require('node-superfetch');
module.exports = class ImageSizeCommand extends Command {
constructor(client) {
super(client, {
name: 'image-size',
aliases: ['img-size', 'size', 'dimensions', 'image-dimensions', 'img-dimensions'],
group: 'analyze',
memberName: 'image-size',
description: 'Determines the size of an image.',
throttling: {
usages: 1,
duration: 10
},
args: [
{
key: 'image',
prompt: 'What image would you like to get the size of?',
type: 'image',
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 2048 })
}
]
});
}
async run(msg, { image }) {
try {
const { body } = await request.get(image);
const data = await loadImage(body);
return msg.reply(`This image is ${data.width}x${data.height}.`);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};