Add max attachment size argument option

This commit is contained in:
Dragon Fire
2024-05-08 23:51:54 -04:00
parent 21c1d717c4
commit 29bdfbd83b
3 changed files with 8 additions and 3 deletions
+5 -2
View File
@@ -8,10 +8,13 @@ module.exports = class ImageArgument extends Argument {
super(client, 'image');
}
async validate(value, msg) {
async validate(value, msg, arg) {
const attachment = msg.attachments.first();
if (attachment) {
if (attachment.size > 8e+6) return 'Image size is above 8 MB.';
if (attachment.size > arg.maxAttachmentSize) {
const displaySize = Math.floor(arg.maxAttachmentSize / 1000000);
return `Image size is above ${displaySize} MB.`;
}
if (!fileTypeRe.test(attachment.name)) return 'Provided attachment is not an image.';
return true;
}