This commit is contained in:
Daniel Odendahl Jr
2017-11-19 19:59:00 +00:00
parent c9df6d9a59
commit 36c17d8988
3 changed files with 85 additions and 0 deletions
+1
View File
@@ -7,6 +7,7 @@ class EmojiArgumentType extends ArgumentType {
}
validate(value, msg) {
if (!value) return false;
const matches = value.match(/^(?:<:([a-zA-Z0-9_]+):)?([0-9]+)>?$/);
if (matches && msg.client.emojis.has(matches[2])) return true;
if (!msg.guild) return false;
+30
View File
@@ -0,0 +1,30 @@
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;
}
}
module.exports = ImageArgumentType;