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 handling of passing null to setMessageReference #2749

Merged
merged 1 commit into from
Oct 8, 2024
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 @@ -149,8 +149,13 @@ public MessageCreateAction setMessageReference(@Nonnull MessageReference.Message
@Override
public MessageCreateAction setMessageReference(@Nullable String messageId)
{
if (messageId != null)
Checks.isSnowflake(messageId);
if (messageId == null)
{
this.messageReference = null;
return this;
}

Checks.isSnowflake(messageId);
String guildId = null;
if (channel instanceof GuildChannel)
guildId = ((GuildChannel) channel).getGuild().getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,21 @@ void testFullFromBuilder()
.whenQueueCalled();
}

@Test
void testSetMessageReferenceNull()
{
MessageCreateActionImpl action = new MessageCreateActionImpl(channel);

action.setMessageReference((String) null);
action.setContent("test content");
action.failOnInvalidReply(true);

assertThatRequestFrom(action)
.hasBodyEqualTo(defaultMessageRequest()
.put("content", "test content"))
.whenQueueCalled();
}

@Nonnull
protected DataObject normalizeRequestBody(@Nonnull DataObject body)
{
Expand Down