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
+2 -1
View File
@@ -16,9 +16,10 @@ module.exports = class SketchCommand extends Command {
description: 'Draws an image or a user\'s avatar but sketched.',
throttling: {
usages: 1,
duration: 60
duration: 120
},
clientPermissions: [PermissionFlagsBits.AttachFiles],
maxAttachmentSize: 2e+6,
args: [
{
key: 'image',
+1
View File
@@ -11,6 +11,7 @@ module.exports = class Argument {
this.min = typeof options.min === 'undefined' ? null : options.min;
this.max = typeof options.max === 'undefined' ? null : options.max;
this.oneOf = typeof options.oneOf === 'undefined' ? null : options.oneOf;
this.maxAttachmentSize = typeof options.maxAttachmentSize === 'undefined' ? null : options.maxAttachmentSize;
this.default = typeof options.default === 'undefined' ? null : options.default;
this.infinite = options.infinite || false;
this.avatarSize = options.avatarSize || 2048;
+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;
}