Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix max file size limit in MessageAction #2017

Merged
merged 4 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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