Skip to content

Commit 12ec636

Browse files
authored
Add a way to retrieve users that used super reaction (#2786)
1 parent 306a1df commit 12ec636

File tree

5 files changed

+251
-19
lines changed

5 files changed

+251
-19
lines changed

src/main/java/net/dv8tion/jda/api/entities/Message.java

+49-1
Original file line numberDiff line numberDiff line change
@@ -2130,6 +2130,10 @@ default MessageCreateAction forwardTo(@Nonnull MessageChannel channel)
21302130
/**
21312131
* This obtains the {@link User users} who reacted using the given {@link Emoji}.
21322132
*
2133+
* <br>By default, this only includes users that reacted with {@link MessageReaction.ReactionType#NORMAL}.
2134+
* Use {@link #retrieveReactionUsers(Emoji, MessageReaction.ReactionType) retrieveReactionUsers(emoji, ReactionType.SUPER)}
2135+
* to retrieve the users that used a super reaction instead.
2136+
*
21332137
* <p>Messages maintain a list of reactions, alongside a list of users who added them.
21342138
*
21352139
* <p>Using this data, we can obtain a {@link ReactionPaginationAction}
@@ -2164,7 +2168,51 @@ default MessageCreateAction forwardTo(@Nonnull MessageChannel channel)
21642168
*/
21652169
@Nonnull
21662170
@CheckReturnValue
2167-
ReactionPaginationAction retrieveReactionUsers(@Nonnull Emoji emoji);
2171+
default ReactionPaginationAction retrieveReactionUsers(@Nonnull Emoji emoji)
2172+
{
2173+
return retrieveReactionUsers(emoji, MessageReaction.ReactionType.NORMAL);
2174+
}
2175+
2176+
/**
2177+
* This obtains the {@link User users} who reacted using the given {@link Emoji}.
2178+
*
2179+
* <p>Messages maintain a list of reactions, alongside a list of users who added them.
2180+
*
2181+
* <p>Using this data, we can obtain a {@link ReactionPaginationAction}
2182+
* of the users who've reacted to this message.
2183+
*
2184+
* <p>The following {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} are possible:
2185+
* <ul>
2186+
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
2187+
* <br>The retrieve request was attempted after the account lost access to the {@link GuildChannel}
2188+
* due to {@link Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} being revoked
2189+
* <br>Also can happen if the account lost the {@link Permission#MESSAGE_HISTORY Permission.MESSAGE_HISTORY}</li>
2190+
*
2191+
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_EMOJI UNKNOWN_EMOJI}
2192+
* <br>The provided emoji was deleted, doesn't exist, or is not available to the currently logged-in account in this channel.</li>
2193+
*
2194+
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}
2195+
* <br>If the message has already been deleted. This might also be triggered for ephemeral messages.</li>
2196+
* </ul>
2197+
*
2198+
* @param emoji
2199+
* The {@link Emoji} to retrieve users for.
2200+
* @param type
2201+
* The specific type of reaction
2202+
*
2203+
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
2204+
* If the MessageChannel this message was sent in was a {@link GuildChannel} and the
2205+
* logged in account does not have {@link Permission#MESSAGE_HISTORY Permission.MESSAGE_HISTORY} in the channel.
2206+
* @throws java.lang.IllegalArgumentException
2207+
* If the provided null is provided.
2208+
* @throws IllegalStateException
2209+
* If this Message is ephemeral
2210+
*
2211+
* @return The {@link ReactionPaginationAction} of the users who reacted with the provided emoji
2212+
*/
2213+
@Nonnull
2214+
@CheckReturnValue
2215+
ReactionPaginationAction retrieveReactionUsers(@Nonnull Emoji emoji, @Nonnull MessageReaction.ReactionType type);
21682216

21692217
/**
21702218
* This obtains the {@link MessageReaction} for the given {@link Emoji} on this message.

src/main/java/net/dv8tion/jda/api/entities/MessageReaction.java

+58-1
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ public long getMessageIdLong()
335335
* Retrieves the {@link net.dv8tion.jda.api.entities.User Users} that
336336
* already reacted with this MessageReaction.
337337
*
338+
* <br>By default, this only includes users that reacted with {@link ReactionType#NORMAL}.
339+
* Use {@link #retrieveUsers(ReactionType) retrieveUsers(ReactionType.SUPER)}
340+
* to retrieve the users that used a super reaction instead.
341+
*
338342
* <p>Possible ErrorResponses include:
339343
* <ul>
340344
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}
@@ -348,6 +352,8 @@ public long getMessageIdLong()
348352
* </ul>
349353
*
350354
* @return {@link ReactionPaginationAction ReactionPaginationAction}
355+
*
356+
* @see #retrieveUsers(ReactionType)
351357
*/
352358
@Nonnull
353359
@CheckReturnValue
@@ -356,6 +362,40 @@ public ReactionPaginationAction retrieveUsers()
356362
return new ReactionPaginationActionImpl(this);
357363
}
358364

365+
/**
366+
* Retrieves the {@link net.dv8tion.jda.api.entities.User Users} that
367+
* already reacted with this MessageReaction.
368+
*
369+
* <p>Possible ErrorResponses include:
370+
* <ul>
371+
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}
372+
* <br>If the message this reaction was attached to got deleted.</li>
373+
*
374+
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL}
375+
* <br>If the channel this reaction was used in got deleted.</li>
376+
*
377+
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
378+
* <br>If we were removed from the channel/guild</li>
379+
* </ul>
380+
*
381+
* @param type
382+
* The specific type of reaction
383+
*
384+
* @throws java.lang.IllegalArgumentException
385+
* If {@code null} is provided.
386+
*
387+
* @return {@link ReactionPaginationAction ReactionPaginationAction}
388+
*
389+
* @see #retrieveUsers()
390+
*/
391+
@Nonnull
392+
@CheckReturnValue
393+
public ReactionPaginationAction retrieveUsers(@Nonnull ReactionType type)
394+
{
395+
Checks.notNull(type, "Type");
396+
return new ReactionPaginationActionImpl(this, type);
397+
}
398+
359399
/**
360400
* Removes this Reaction from the Message.
361401
* <br>This will remove our own reaction as an overload
@@ -511,6 +551,23 @@ public String toString()
511551
*/
512552
public enum ReactionType
513553
{
514-
NORMAL, SUPER
554+
NORMAL(0), SUPER(1);
555+
556+
private final int id;
557+
558+
ReactionType(int id)
559+
{
560+
this.id = id;
561+
}
562+
563+
/**
564+
* The id used to represent this type in requests.
565+
*
566+
* @return The raw id value
567+
*/
568+
public int getId()
569+
{
570+
return id;
571+
}
515572
}
516573
}

src/main/java/net/dv8tion/jda/api/entities/channel/middleman/MessageChannel.java

+114-8
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
*/
1616
package net.dv8tion.jda.api.entities.channel.middleman;
1717

18-
import net.dv8tion.jda.api.entities.Guild;
19-
import net.dv8tion.jda.api.entities.Message;
20-
import net.dv8tion.jda.api.entities.MessageEmbed;
21-
import net.dv8tion.jda.api.entities.MessageHistory;
18+
import net.dv8tion.jda.api.entities.*;
2219
import net.dv8tion.jda.api.entities.channel.Channel;
2320
import net.dv8tion.jda.api.entities.channel.concrete.GroupChannel;
2421
import net.dv8tion.jda.api.entities.channel.concrete.PrivateChannel;
@@ -2122,6 +2119,10 @@ default RestAction<Void> removeReactionById(long messageId, @Nonnull Emoji emoji
21222119
/**
21232120
* This obtains the {@link net.dv8tion.jda.api.entities.User users} who reacted to a message using the given {@link Emoji}.
21242121
*
2122+
* <br>By default, this only includes users that reacted with {@link MessageReaction.ReactionType#NORMAL}.
2123+
* Use {@link #retrieveReactionUsersById(String, Emoji, MessageReaction.ReactionType) retrieveReactionUsersById(messageId, emoji, ReactionType.SUPER)}
2124+
* to retrieve the users that used a super reaction instead.
2125+
*
21252126
* <p>Messages maintain a list of reactions, alongside a list of users who added them.
21262127
*
21272128
* <p>Using this data, we can obtain a {@link ReactionPaginationAction ReactionPaginationAction}
@@ -2164,15 +2165,16 @@ default RestAction<Void> removeReactionById(long messageId, @Nonnull Emoji emoji
21642165
@CheckReturnValue
21652166
default ReactionPaginationAction retrieveReactionUsersById(@Nonnull String messageId, @Nonnull Emoji emoji)
21662167
{
2167-
Checks.isSnowflake(messageId, "Message ID");
2168-
Checks.notNull(emoji, "Emoji");
2169-
2170-
return new ReactionPaginationActionImpl(this, messageId, emoji.getAsReactionCode());
2168+
return retrieveReactionUsersById(messageId, emoji, MessageReaction.ReactionType.NORMAL);
21712169
}
21722170

21732171
/**
21742172
* This obtains the {@link net.dv8tion.jda.api.entities.User users} who reacted to a message using the given {@link Emoji}.
21752173
*
2174+
* <br>By default, this only includes users that reacted with {@link MessageReaction.ReactionType#NORMAL}.
2175+
* Use {@link #retrieveReactionUsersById(long, Emoji, MessageReaction.ReactionType) retrieveReactionUsersById(messageId, emoji, ReactionType.SUPER)}
2176+
* to retrieve the users that used a super reaction instead.
2177+
*
21762178
* <p>Messages maintain a list of reactions, alongside a list of users who added them.
21772179
*
21782180
* <p>Using this data, we can obtain a {@link ReactionPaginationAction ReactionPaginationAction}
@@ -2222,6 +2224,110 @@ default ReactionPaginationAction retrieveReactionUsersById(long messageId, @Nonn
22222224
return retrieveReactionUsersById(Long.toUnsignedString(messageId), emoji);
22232225
}
22242226

2227+
/**
2228+
* This obtains the {@link net.dv8tion.jda.api.entities.User users} who reacted to a message using the given {@link Emoji}.
2229+
*
2230+
* <p>Messages maintain a list of reactions, alongside a list of users who added them.
2231+
*
2232+
* <p>Using this data, we can obtain a {@link ReactionPaginationAction ReactionPaginationAction}
2233+
* of the users who've reacted to the given message.
2234+
*
2235+
* <p>The following {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} are possible:
2236+
* <ul>
2237+
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
2238+
* <br>The retrieve request was attempted after the account lost access to the {@link GuildMessageChannel GuildMessageChannel}
2239+
* due to {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} being revoked
2240+
* <br>Also can happen if the account lost the {@link net.dv8tion.jda.api.Permission#MESSAGE_HISTORY Permission.MESSAGE_HISTORY}</li>
2241+
*
2242+
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_EMOJI UNKNOWN_EMOJI}
2243+
* <br>The provided emoji was deleted, doesn't exist, or is not available to the currently logged-in account in this channel.</li>
2244+
*
2245+
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}
2246+
* <br>The provided {@code messageId} is unknown in this MessageChannel, either due to the id being invalid, or
2247+
* the message it referred to has already been deleted.</li>
2248+
* </ul>
2249+
*
2250+
* @param messageId
2251+
* The messageId to retrieve the users from.
2252+
* @param emoji
2253+
* The {@link Emoji} to retrieve users for.
2254+
* @param type
2255+
* The specific type of reaction
2256+
*
2257+
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
2258+
* If this is a {@link GuildMessageChannel GuildMessageChannel} and the
2259+
* logged in account does not have {@link net.dv8tion.jda.api.Permission#MESSAGE_HISTORY Permission.MESSAGE_HISTORY}.
2260+
* @throws java.lang.IllegalArgumentException
2261+
* <ul>
2262+
* <li>If provided {@code messageId} is {@code null} or not a valid snowflake.</li>
2263+
* <li>If provided {@code emoji} is {@code null}.</li>
2264+
* <li>If provided {@code type} is {@code null}.</li>
2265+
* </ul>
2266+
*
2267+
* @return The {@link ReactionPaginationAction} of the emoji's users.
2268+
*/
2269+
@Nonnull
2270+
@CheckReturnValue
2271+
default ReactionPaginationAction retrieveReactionUsersById(@Nonnull String messageId, @Nonnull Emoji emoji, @Nonnull MessageReaction.ReactionType type)
2272+
{
2273+
Checks.isSnowflake(messageId, "Message ID");
2274+
Checks.notNull(emoji, "Emoji");
2275+
Checks.notNull(type, "ReactionType");
2276+
2277+
return new ReactionPaginationActionImpl(this, messageId, emoji.getAsReactionCode(), type);
2278+
}
2279+
2280+
/**
2281+
* This obtains the {@link net.dv8tion.jda.api.entities.User users} who reacted to a message using the given {@link Emoji}.
2282+
*
2283+
* <p>Messages maintain a list of reactions, alongside a list of users who added them.
2284+
*
2285+
* <p>Using this data, we can obtain a {@link ReactionPaginationAction ReactionPaginationAction}
2286+
* of the users who've reacted to the given message.
2287+
*
2288+
* <p>The following {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} are possible:
2289+
* <ul>
2290+
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
2291+
* <br>The retrieve request was attempted after the account lost access to the {@link GuildMessageChannel GuildMessageChannel}
2292+
* due to {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} being revoked
2293+
* <br>Also can happen if the account lost the {@link net.dv8tion.jda.api.Permission#MESSAGE_HISTORY Permission.MESSAGE_HISTORY}</li>
2294+
*
2295+
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_EMOJI UNKNOWN_EMOJI}
2296+
* <br>The provided emoji was deleted, doesn't exist, or is not available to the currently logged-in account in this channel.</li>
2297+
*
2298+
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}
2299+
* <br>The provided {@code messageId} is unknown in this MessageChannel, either due to the id being invalid, or
2300+
* the message it referred to has already been deleted.</li>
2301+
* </ul>
2302+
*
2303+
* @param messageId
2304+
* The messageId to retrieve the users from.
2305+
* @param emoji
2306+
* The {@link Emoji} to retrieve users for.
2307+
* @param type
2308+
* The specific type of reaction
2309+
*
2310+
* @throws java.lang.UnsupportedOperationException
2311+
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
2312+
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
2313+
* If this is a {@link GuildMessageChannel GuildMessageChannel} and the
2314+
* logged in account does not have {@link net.dv8tion.jda.api.Permission#MESSAGE_HISTORY Permission.MESSAGE_HISTORY}.
2315+
* @throws java.lang.IllegalArgumentException
2316+
* <ul>
2317+
* <li>If provided {@code messageId} is not a valid snowflake.</li>
2318+
* <li>If provided {@code emoji} is {@code null}.</li>
2319+
* <li>If provided {@code type} is {@code null}.</li>
2320+
* </ul>
2321+
*
2322+
* @return The {@link ReactionPaginationAction ReactionPaginationAction} of the emoji's users.
2323+
*/
2324+
@Nonnull
2325+
@CheckReturnValue
2326+
default ReactionPaginationAction retrieveReactionUsersById(long messageId, @Nonnull Emoji emoji, @Nonnull MessageReaction.ReactionType type)
2327+
{
2328+
return retrieveReactionUsersById(Long.toUnsignedString(messageId), emoji, type);
2329+
}
2330+
22252331
/**
22262332
* Used to pin a message. Pinned messages are retrievable via {@link #retrievePinnedMessages()}.
22272333
*

src/main/java/net/dv8tion/jda/internal/entities/ReceivedMessage.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -354,15 +354,18 @@ public RestAction<Void> removeReaction(@Nonnull Emoji emoji, @Nonnull User user)
354354

355355
@Nonnull
356356
@Override
357-
public ReactionPaginationAction retrieveReactionUsers(@Nonnull Emoji emoji)
357+
public ReactionPaginationAction retrieveReactionUsers(@Nonnull Emoji emoji, @Nonnull MessageReaction.ReactionType type)
358358
{
359359
if (isEphemeral())
360360
throw new IllegalStateException("Cannot retrieve reactions on ephemeral messages.");
361361

362362
if (hasChannel())
363-
return getChannel().retrieveReactionUsersById(id, emoji);
363+
return getChannel().retrieveReactionUsersById(id, emoji, type);
364364

365-
return new ReactionPaginationActionImpl(this, emoji.getAsReactionCode());
365+
Checks.notNull(type, "ReactionType");
366+
Checks.notNull(emoji, "Emoji");
367+
368+
return new ReactionPaginationActionImpl(this, emoji.getAsReactionCode(), type);
366369
}
367370

368371
@Nullable

src/main/java/net/dv8tion/jda/internal/requests/restaction/pagination/ReactionPaginationActionImpl.java

+24-6
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,47 @@ public class ReactionPaginationActionImpl
4343
* Creates a new PaginationAction instance
4444
*
4545
* @param reaction
46-
* The target {@link net.dv8tion.jda.api.entities.MessageReaction MessageReaction}
46+
* The target {@link MessageReaction MessageReaction}
4747
*/
4848
public ReactionPaginationActionImpl(MessageReaction reaction)
4949
{
50-
super(reaction.getJDA(), Route.Messages.GET_REACTION_USERS.compile(reaction.getChannelId(), reaction.getMessageId(), getCode(reaction)), 1, 100, 100);
50+
this(reaction, MessageReaction.ReactionType.NORMAL);
51+
}
52+
53+
/**
54+
* Creates a new PaginationAction instance
55+
*
56+
* @param reaction
57+
* The target {@link MessageReaction MessageReaction}
58+
* @param type
59+
* Type of {@link MessageReaction.ReactionType MessageReaction.ReactionType} to retrieve users for
60+
*/
61+
public ReactionPaginationActionImpl(MessageReaction reaction, MessageReaction.ReactionType type)
62+
{
63+
super(reaction.getJDA(), getCompiledRoute(reaction.getChannelId(), reaction.getMessageId(), getCode(reaction), type), 1, 100, 100);
5164
super.order(PaginationOrder.FORWARD);
5265
this.reaction = reaction;
5366
}
5467

55-
public ReactionPaginationActionImpl(Message message, String code)
68+
public ReactionPaginationActionImpl(Message message, String code, MessageReaction.ReactionType type)
5669
{
57-
super(message.getJDA(), Route.Messages.GET_REACTION_USERS.compile(message.getChannelId(), message.getId(), code), 1, 100, 100);
70+
super(message.getJDA(), getCompiledRoute(message.getChannelId(), message.getId(), code, type), 1, 100, 100);
5871
super.order(PaginationOrder.FORWARD);
5972
this.reaction = null;
6073
}
6174

62-
public ReactionPaginationActionImpl(MessageChannel channel, String messageId, String code)
75+
public ReactionPaginationActionImpl(MessageChannel channel, String messageId, String code, MessageReaction.ReactionType type)
6376
{
64-
super(channel.getJDA(), Route.Messages.GET_REACTION_USERS.compile(channel.getId(), messageId, code), 1, 100, 100);
77+
super(channel.getJDA(), getCompiledRoute(channel.getId(), messageId, code, type), 1, 100, 100);
6578
super.order(PaginationOrder.FORWARD);
6679
this.reaction = null;
6780
}
6881

82+
private static Route.CompiledRoute getCompiledRoute(String channelId, String messageId, String code, MessageReaction.ReactionType type)
83+
{
84+
return Route.Messages.GET_REACTION_USERS.compile(channelId, messageId, code).withQueryParams("type", String.valueOf(type.getId()));
85+
}
86+
6987
protected static String getCode(MessageReaction reaction)
7088
{
7189
return reaction.getEmoji().getAsReactionCode();

0 commit comments

Comments
 (0)