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

Add interaction related message flags #1790

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ebc29cc
Add MessageFlag#EPHEMERAL and MessageFlag#LOADING
freya022 Aug 27, 2021
fd08d8a
Fix ComponentInteraction#getMessage docs
freya022 Aug 27, 2021
8b66729
Merge branch 'DV8FromTheWorld:development' into feature/add-missing-m…
freya022 Aug 27, 2021
8f823ae
Merge remote-tracking branch 'origin/feature/add-missing-message-flag…
freya022 Aug 27, 2021
3c885cf
Enable ButtonInteraction#editButton and SelectionMenuInteraction#edit…
freya022 Aug 27, 2021
430b303
Update src/main/java/net/dv8tion/jda/api/entities/Message.java
freya022 Aug 30, 2021
3c2d228
Update src/main/java/net/dv8tion/jda/api/entities/Message.java
freya022 Aug 30, 2021
a533125
Add MessageFlag#EPHEMERAL and MessageFlag#LOADING
freya022 Aug 27, 2021
a9c2fcb
Fix ComponentInteraction#getMessage docs
freya022 Aug 27, 2021
6cb8412
Enable ButtonInteraction#editButton and SelectionMenuInteraction#edit…
freya022 Aug 27, 2021
8f48ecc
Update src/main/java/net/dv8tion/jda/api/entities/Message.java
freya022 Aug 30, 2021
620a5d3
Update src/main/java/net/dv8tion/jda/api/entities/Message.java
freya022 Aug 30, 2021
804d2f3
Merge remote-tracking branch 'origin/feature/add-missing-message-flag…
freya022 Aug 30, 2021
6c95138
Add exception docs to Message#isEphemeral
freya022 Aug 30, 2021
06fb296
Update src/main/java/net/dv8tion/jda/internal/entities/ReceivedMessag…
freya022 Aug 30, 2021
650dda6
Add missing ephemeral checks (basically on all methods that uses a me…
freya022 Aug 30, 2021
f7b29de
Add Message#getFlagsRaw
freya022 Aug 30, 2021
d968a2c
Better exception wording
freya022 Aug 30, 2021
d59afa8
Update src/main/java/net/dv8tion/jda/internal/entities/ReceivedMessag…
freya022 Aug 31, 2021
e37a87b
Update src/main/java/net/dv8tion/jda/internal/entities/ReceivedMessag…
freya022 Aug 31, 2021
bba6eb9
Update src/main/java/net/dv8tion/jda/internal/entities/ReceivedMessag…
freya022 Aug 31, 2021
3f59126
More better wording
freya022 Aug 31, 2021
b013c36
Remove ephemeral check from Message#getJumpUrl
freya022 Aug 31, 2021
76d993c
Add exceptions to docs
freya022 Aug 31, 2021
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
103 changes: 86 additions & 17 deletions src/main/java/net/dv8tion/jda/api/entities/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -1615,8 +1615,11 @@ default MessageAction reply(@Nonnull byte[] data, @Nonnull String name, @Nonnull
* does not have {@link net.dv8tion.jda.api.Permission#MESSAGE_MANAGE Permission.MESSAGE_MANAGE} in
* the channel.
* @throws java.lang.IllegalStateException
* If this Message was not sent by the currently logged in account and it was <b>not</b> sent in a
* {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}.
* <ul>
* <li>If this Message was not sent by the currently logged in account and it was <b>not</b> sent in a
* {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}.</li>
* <li>If this Message is ephemeral</li>
* </ul>
*
* @return {@link net.dv8tion.jda.api.requests.restaction.AuditableRestAction AuditableRestAction}
*
Expand Down Expand Up @@ -1680,6 +1683,8 @@ default MessageAction reply(@Nonnull byte[] data, @Nonnull String name, @Nonnull
* <li>Missing {@link net.dv8tion.jda.api.Permission#MESSAGE_MANAGE Permission.MESSAGE_MANAGE}.
* <br>Required to actually pin the Message.</li>
* </ul>
* @throws IllegalStateException
* If this Message is ephemeral
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link java.lang.Void}
*/
Expand Down Expand Up @@ -1719,6 +1724,8 @@ default MessageAction reply(@Nonnull byte[] data, @Nonnull String name, @Nonnull
* <li>Missing {@link net.dv8tion.jda.api.Permission#MESSAGE_MANAGE Permission.MESSAGE_MANAGE}.
* <br>Required to actually pin the Message.</li>
* </ul>
* @throws IllegalStateException
* If this Message is ephemeral
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link java.lang.Void}
*/
Expand Down Expand Up @@ -1781,6 +1788,8 @@ default MessageAction reply(@Nonnull byte[] data, @Nonnull String name, @Nonnull
* <li>If the provided {@link net.dv8tion.jda.api.entities.Emote Emote} cannot be used in the current channel.
* See {@link Emote#canInteract(User, MessageChannel)} or {@link Emote#canInteract(Member)} for more information.</li>
* </ul>
* @throws IllegalStateException
* If this message is ephemeral
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link java.lang.Void}
*/
Expand Down Expand Up @@ -1850,6 +1859,8 @@ default MessageAction reply(@Nonnull byte[] data, @Nonnull String name, @Nonnull
* </ul>
* @throws java.lang.IllegalArgumentException
* If the provided unicode emoji is null or empty.
* @throws IllegalStateException
* If this Message is ephemeral
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link java.lang.Void}
*/
Expand Down Expand Up @@ -1888,8 +1899,11 @@ default MessageAction reply(@Nonnull byte[] data, @Nonnull String name, @Nonnull
* and the currently logged in account does not have {@link net.dv8tion.jda.api.Permission#MESSAGE_MANAGE Permission.MESSAGE_MANAGE}
* in the channel.
* @throws java.lang.IllegalStateException
* If this message was <b>not</b> sent in a
* {@link net.dv8tion.jda.api.entities.Guild Guild}.
* <ul>
* <li>If this message was <b>not</b> sent in a {@link net.dv8tion.jda.api.entities.Guild Guild}.</li>
* <li>If this message is ephemeral</li>
* </ul>
*
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link java.lang.Void}
*/
Expand Down Expand Up @@ -1937,8 +1951,11 @@ default MessageAction reply(@Nonnull byte[] data, @Nonnull String name, @Nonnull
* @throws IllegalArgumentException
* If provided with null
* @throws java.lang.IllegalStateException
* If this message was <b>not</b> sent in a
* {@link net.dv8tion.jda.api.entities.Guild Guild}.
* <ul>
* <li>If this message was <b>not</b> sent in a {@link net.dv8tion.jda.api.entities.Guild Guild}.</li>
* <li>If this message is ephemeral</li>
* </ul>
*
*
* @return {@link RestAction}
*
Expand Down Expand Up @@ -1976,8 +1993,10 @@ default MessageAction reply(@Nonnull byte[] data, @Nonnull String name, @Nonnull
* @throws IllegalArgumentException
* If provided with null
* @throws java.lang.IllegalStateException
* If this message was <b>not</b> sent in a
* {@link net.dv8tion.jda.api.entities.Guild Guild}.
* <ul>
* <li>If this message was <b>not</b> sent in a {@link net.dv8tion.jda.api.entities.Guild Guild}.</li>
* <li>If this message is ephemeral</li>
* </ul>
*
* @return {@link RestAction}
*
Expand Down Expand Up @@ -2027,6 +2046,8 @@ default MessageAction reply(@Nonnull byte[] data, @Nonnull String name, @Nonnull
* <li>If the provided {@link net.dv8tion.jda.api.entities.Emote Emote} cannot be used in the current channel.
* See {@link Emote#canInteract(User, MessageChannel)} or {@link Emote#canInteract(Member)} for more information.</li>
* </ul>
* @throws IllegalStateException
* If this is an ephemeral message
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link java.lang.Void}
*
Expand Down Expand Up @@ -2086,9 +2107,13 @@ default MessageAction reply(@Nonnull byte[] data, @Nonnull String name, @Nonnull
* <li>If the provided user is null</li>
* </ul>
* @throws java.lang.IllegalStateException
* If this message was <b>not</b> sent in a
* <ul>
* <li>If this message was <b>not</b> sent in a
* {@link net.dv8tion.jda.api.entities.Guild Guild}
* <b>and</b> the given user is <b>not</b> the {@link net.dv8tion.jda.api.entities.SelfUser SelfUser}.
* <b>and</b> the given user is <b>not</b> the {@link net.dv8tion.jda.api.entities.SelfUser SelfUser}.</li>
* <li>If this message is ephemeral</li>
* </ul>
*
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link java.lang.Void}
*
Expand Down Expand Up @@ -2146,6 +2171,8 @@ default MessageAction reply(@Nonnull byte[] data, @Nonnull String name, @Nonnull
* and the logged in account does not have {@link net.dv8tion.jda.api.Permission#MESSAGE_HISTORY Permission.MESSAGE_HISTORY}
* @throws java.lang.IllegalArgumentException
* If the provided unicode emoji is null or empty.
* @throws IllegalStateException
* If this is an ephemeral message
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link java.lang.Void}
*
Expand Down Expand Up @@ -2206,9 +2233,14 @@ default MessageAction reply(@Nonnull byte[] data, @Nonnull String name, @Nonnull
* @throws java.lang.IllegalArgumentException
* If the provided unicode emoji is null or empty or if the provided user is null.
* @throws java.lang.IllegalStateException
* If this message was <b>not</b> sent in a
* {@link net.dv8tion.jda.api.entities.Guild Guild}
* <b>and</b> the given user is <b>not</b> the {@link net.dv8tion.jda.api.entities.SelfUser SelfUser}.
* If this message:
* <ul>
* <li>Was <b>not</b> sent in a
* {@link net.dv8tion.jda.api.entities.Guild Guild}
* <b>and</b> the given user is <b>not</b> the {@link net.dv8tion.jda.api.entities.SelfUser SelfUser}.</li>
* <li>Is ephemeral</li>
* </ul>
*
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link java.lang.Void}
*
Expand Down Expand Up @@ -2250,7 +2282,8 @@ default MessageAction reply(@Nonnull byte[] data, @Nonnull String name, @Nonnull
* logged in account does not have {@link net.dv8tion.jda.api.Permission#MESSAGE_HISTORY Permission.MESSAGE_HISTORY} in the channel.
* @throws java.lang.IllegalArgumentException
* If the provided {@link net.dv8tion.jda.api.entities.Emote Emote} is null.
*
* @throws IllegalStateException
* If this Message is ephemeral
* @return The {@link net.dv8tion.jda.api.requests.restaction.pagination.ReactionPaginationAction ReactionPaginationAction} of the emote's users.
*
* @since 4.1.0
Expand Down Expand Up @@ -2293,7 +2326,8 @@ default MessageAction reply(@Nonnull byte[] data, @Nonnull String name, @Nonnull
* logged in account does not have {@link net.dv8tion.jda.api.Permission#MESSAGE_HISTORY Permission.MESSAGE_HISTORY} in the channel.
* @throws java.lang.IllegalArgumentException
* If the provided unicode emoji is null or empty.
*
* @throws IllegalStateException
* If this Message is ephemeral
* @return The {@link net.dv8tion.jda.api.requests.restaction.pagination.ReactionPaginationAction ReactionPaginationAction} of the emoji's users.
*
* @since 4.1.0
Expand Down Expand Up @@ -2403,6 +2437,8 @@ default MessageAction reply(@Nonnull byte[] data, @Nonnull String name, @Nonnull
* @throws net.dv8tion.jda.api.exceptions.PermissionException
* If the MessageChannel this message was sent in was a {@link net.dv8tion.jda.api.entities.PrivateChannel PrivateChannel}
* and the message was not sent by the currently logged in account.
* @throws IllegalStateException
* If this Message is ephemeral
* @return {@link net.dv8tion.jda.api.requests.restaction.AuditableRestAction AuditableRestAction} - Type: {@link java.lang.Void}
* @see #isSuppressedEmbeds()
*/
Expand Down Expand Up @@ -2438,7 +2474,10 @@ default MessageAction reply(@Nonnull byte[] data, @Nonnull String name, @Nonnull
* @throws java.lang.UnsupportedOperationException
* If this is a system message
* @throws IllegalStateException
* If the channel is not a text or news channel. See {@link TextChannel#isNews()}.
* <ul>
* <li>If the channel is not a text or news channel. See {@link TextChannel#isNews()}.</li>
* <li>If the message is ephemeral.</li>
* </ul>
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If the currently logged in account does not have
* {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} in this channel
Expand Down Expand Up @@ -2476,6 +2515,27 @@ default MessageAction reply(@Nonnull byte[] data, @Nonnull String name, @Nonnull
@Nonnull
EnumSet<MessageFlag> getFlags();

/**
* Returns the raw message flags of this message
*
* @throws java.lang.UnsupportedOperationException
* If this is a system message
* @return The raw message flags
* @see #getFlags()
*/
long getFlagsRaw();

/**
* Whether this message is ephemeral.
* <br>The message being ephemeral means it is only visible to the bot and the interacting user
* <br>This is a shortcut method for checking if {@link #getFlags()} contains {@link MessageFlag#EPHEMERAL}
*
* @throws java.lang.UnsupportedOperationException
* If this is a system message
* @return Whether the message is ephemeral
*/
boolean isEphemeral();
freya022 marked this conversation as resolved.
Show resolved Hide resolved

/**
* This specifies the {@link net.dv8tion.jda.api.entities.MessageType MessageType} of this Message.
*
Expand Down Expand Up @@ -2583,7 +2643,16 @@ enum MessageFlag
/**
* Indicates, that this Message came from the urgent message system
*/
URGENT(4);
URGENT(4),
/**
* Indicates, that this Message is ephemeral, the Message is only visible to the bot and the interacting user
* @see Message#isEphemeral
*/
EPHEMERAL(6),
/**
* Indicates, that this Message is an interaction response and the bot is "thinking"
*/
LOADING(7);

private final int value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public Component getComponent()
return interaction.getComponent();
}

@Nullable
@Nonnull
@Override
public Message getMessage()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ default Button getComponent()

/**
* Update the button with a new button instance.
* <br>This only works for non-ephemeral messages where {@link #getMessage()} is available!
*
* <p>If this interaction is already acknowledged this will use {@link #getHook()}
* and otherwise {@link #editComponents(Collection)} directly to acknowledge the interaction.
Expand All @@ -71,8 +70,6 @@ default Button getComponent()
default RestAction<Void> editButton(@Nullable Button newButton)
{
Message message = getMessage();
if (message == null)
throw new IllegalStateException("Cannot update button for ephemeral messages! Discord does not provide enough information to perform the update.");
List<ActionRow> components = new ArrayList<>(message.getActionRows());
ComponentLayout.updateComponent(components, getComponentId(), newButton);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ public interface ComponentInteraction extends Interaction

/**
* The {@link Message} instance.
* <br>This is null on interactions for ephemeral messages.
*
* @return The {@link Message}, or null if this message is ephemeral
* @return The {@link Message}
*/
@Nullable
@Nonnull
Message getMessage();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ default List<SelectOption> getSelectedOptions()

/**
* Update the selection menu with a new selection menu instance.
* <br>This only works for non-ephemeral messages where {@link #getMessage()} is available!
*
* <p>If this interaction is already acknowledged this will use {@link #getHook()}
* and otherwise {@link #editComponents(Collection)} directly to acknowledge the interaction.
Expand All @@ -106,8 +105,6 @@ default List<SelectOption> getSelectedOptions()
default RestAction<Void> editSelectionMenu(@Nullable SelectionMenu newMenu)
{
Message message = getMessage();
if (message == null)
throw new IllegalStateException("Cannot update selection menu for ephemeral messages! Discord does not provide enough information to perform the update.");
List<ActionRow> components = new ArrayList<>(message.getActionRows());
ComponentLayout.updateComponent(components, getComponentId(), newMenu);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,20 @@ public EnumSet<MessageFlag> getFlags()
return null;
}

@Override
public long getFlagsRaw()
{
unsupported();
return 0;
}

@Override
public boolean isEphemeral()
{
unsupported();
return false;
}

@Nonnull
@Override
public MessageType getType()
Expand Down
Loading