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
Add application_id support for received messages #2335
Add application_id support for received messages #2335
Conversation
src/main/java/net/dv8tion/jda/internal/entities/ReceivedMessage.java
Outdated
Show resolved
Hide resolved
f3be061
to
f0ee703
Compare
@Nonnull | ||
default String getApplicationId() | ||
{ | ||
return Long.toUnsignedString(getApplicationIdLong()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like our pattern here is normally id
or null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This matches the behavior of MessageChannel#getLatestMessageId
, MessageReference#getMessageId
, MessageReference#getChannelId
and MessageReference#getGuildId
. So I guess those should be changed as well? Maybe in a different PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MessageChannel#getLatestMessageId
This is older code from before we really landed on this pattern. We should update it.
MessageReference#getMessageId
A message will always have an Id. The docs on this method are wrong. It being "0"
would be a bug.
MessageReference#getChannelId
A message will always have a channel. The docs on this method are wrong. It being "0"
would be a bug.
MessageReference#getGuildId
This should be returning null
if getGuildIdLong == 0
, so yeah we need to update it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure we explicitly decided to use "0" for getLatestMessageId
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just looked at the git history:
Originally this method threw an IllegalStateException when you called it if there wasn't a latestMessageId to use. We changed it to instead use String.valueOf(id)
and later Long.toUnsignedString(id)
.
I don't see anything in the history that indicates to me that we chose to explicitly do "0"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember where or when we talked about it, but I definitely remember discussing it when we removed the exception. And I don't really see a valid reason to change it now. Is there any example of where we do return null for missing id?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MessageReference#getMessageId
A message will always have an Id. The docs on this method are wrong. It being
"0"
would be a bug.MessageReference#getChannelId
A message will always have a channel. The docs on this method are wrong. It being
"0"
would be a bug.
According to the docs they are optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those docs are for sending, not receiving.
f0ee703
to
b26d5e6
Compare
Pull Request Etiquette
Changes
Closes Issue: #2311
Description
Adds
Message#getApplicationId
andMessage#getApplicationIdLong
to easily tell which bot sent the message without the need to look up webhooks.