Skip to content

Commit

Permalink
Fix max file size limit in MessageAction (#2017)
Browse files Browse the repository at this point in the history
* override MessageAction#addFile(byte[], String, AttachmentOption...) overload in MessageActionImpl

* Don't use jetbrains annotation

* Removed unnecessary import

* Removed another import
  • Loading branch information
Xirado authored Feb 11, 2022
1 parent 8988960 commit a77218c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.Arrays;
Expand Down Expand Up @@ -597,13 +596,7 @@ default MessageAction appendFormat(@Nonnull final String format, final Object...
*/
@Nonnull
@CheckReturnValue
default MessageAction addFile(@Nonnull final byte[] data, @Nonnull final String name, @Nonnull AttachmentOption... options)
{
Checks.notNull(data, "Data");
final long maxSize = getJDA().getSelfUser().getAllowedFileSize();
Checks.check(data.length <= maxSize, "File may not exceed the maximum file length of %d bytes!", maxSize);
return addFile(new ByteArrayInputStream(data), name, options);
}
MessageAction addFile(@Nonnull final byte[] data, @Nonnull final String name, @Nonnull AttachmentOption... options);

/**
* Adds the provided {@link java.io.File File} as file data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,16 @@ public MessageActionImpl addFile(@Nonnull final File file, @Nonnull String name,
}
}

@Nonnull
@Override
public MessageAction addFile(@Nonnull byte[] data, @Nonnull String name, @Nonnull AttachmentOption... options)
{
Checks.notNull(data, "Data");
final long maxSize = getMaxFileSize();
Checks.check(data.length <= maxSize, "File may not exceed the maximum file length of %d bytes!", maxSize);
return addFile(new ByteArrayInputStream(data), name, options);
}

@Nonnull
@Override
@CheckReturnValue
Expand Down

0 comments on commit a77218c

Please sign in to comment.