Files
xiao/types/image.js
T
Daniel Odendahl Jr 1e270ace06 isEmpty
2017-11-19 20:48:44 +00:00

37 lines
887 B
JavaScript

const { ArgumentType } = require('discord.js-commando');
class ImageArgumentType extends ArgumentType {
constructor(client) {
super(client, 'image');
}
async validate(value, msg) {
const attachment = msg.attachments.first();
if (!attachment) {
const valid = await this.client.registry.types.get('user').validate(value, msg);
return valid;
}
if (!attachment.height || !attachment.width) return false;
if (attachment.size > 8e+6) return false;
return true;
}
parse(value, msg) {
if (!msg.attachments.size) {
return this.client.registry.types.get('user').parse(value, msg).displayAvatarURL({
format: 'png',
size: 512
});
}
return msg.attachments.first().url;
}
isEmpty(value, msg) {
console.log('isEmpty ran');
if (!msg.attachments.size) return !value;
return Boolean(msg.attachments.size);
}
}
module.exports = ImageArgumentType;