littlelimedragon, union types

This commit is contained in:
Daniel Odendahl Jr
2018-03-23 11:10:59 +00:00
parent fa18852775
commit ed7b4cb5e1
16 changed files with 40 additions and 33 deletions
+18
View File
@@ -0,0 +1,18 @@
const { ArgumentType } = require('discord.js-commando');
class AvatarArgumentType extends ArgumentType {
constructor(client) {
super(client, 'avatar');
}
validate(value, msg, arg) {
return this.client.types.get('user').validate(value, msg, arg);
}
async parse(value, msg, arg) {
const user = await this.client.types.get('user').parse(value, msg, arg);
return user.displayAvatarURL({ format: 'png', size: 512 });
}
}
module.exports = AvatarArgumentType;
+1 -12
View File
@@ -7,27 +7,16 @@ class ImageArgumentType extends ArgumentType {
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 || !attachment.height || !attachment.width) return false;
if (attachment.size > 8e+6) return 'Please provide an image under 8 MB.';
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) {
if (!msg.attachments.size) return !value;
return !msg.attachments.size;
}
}