mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 15:07:42 +02:00
Add max attachment size argument option
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user