Skip to content

Commit

Permalink
Revert "Adding a check in reaction methods before calling getTextChan…
Browse files Browse the repository at this point in the history
…nel() (discord-jda#1216)"

This reverts commit d74ee2e.
  • Loading branch information
Andre601 committed Apr 21, 2020
1 parent 2dddc21 commit c9b68b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 52 deletions.
29 changes: 2 additions & 27 deletions src/main/java/net/dv8tion/jda/api/entities/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -1165,8 +1165,6 @@ default boolean isFromGuild()
* Removes all reactions from this Message.
* <br>This is useful for moderator commands that wish to remove all reactions at once from a specific message.
*
* <p>Please note that you <b>can't</b> clear reactions if this message was sent in a {@link net.dv8tion.jda.api.entities.PrivateChannel PrivateChannel}!
*
* <p><b>Neither success nor failure of this request will affect this Message's {@link #getReactions()} return as Message is immutable.</b>
*
* <p>The following {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} are possible:
Expand All @@ -1193,7 +1191,7 @@ default boolean isFromGuild()
* 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}.
* {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}.
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link java.lang.Void}
*/
Expand All @@ -1204,8 +1202,6 @@ default boolean isFromGuild()
/**
* Removes all reactions for the specified emoji.
*
* <p>Please note that you <b>can't</b> clear reactions if this message was sent in a {@link net.dv8tion.jda.api.entities.PrivateChannel PrivateChannel}!
*
* <h2>Example</h2>
* <pre><code>
* // custom
Expand Down Expand Up @@ -1238,9 +1234,6 @@ default boolean isFromGuild()
* If the currently logged in account does not have {@link Permission#MESSAGE_MANAGE} in the channel
* @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}.
*
* @return {@link RestAction}
*
Expand All @@ -1253,8 +1246,6 @@ default boolean isFromGuild()
/**
* Removes all reactions for the specified emote.
*
* <p>Please note that you <b>can't</b> clear reactions if this message was sent in a {@link net.dv8tion.jda.api.entities.PrivateChannel PrivateChannel}!
*
* <p>The following {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} are possible:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
Expand All @@ -1277,9 +1268,6 @@ default boolean isFromGuild()
* If the currently logged in account does not have {@link Permission#MESSAGE_MANAGE} in the channel
* @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}.
*
* @return {@link RestAction}
*
Expand Down Expand Up @@ -1338,8 +1326,6 @@ default boolean isFromGuild()
/**
* Removes a {@link net.dv8tion.jda.api.entities.User User's} reaction from this Message using an {@link net.dv8tion.jda.api.entities.Emote Emote}.
*
* <p>Please note that you <b>can't</b> remove reactions of other users if this message was sent in a {@link net.dv8tion.jda.api.entities.PrivateChannel PrivateChannel}!
*
* <p>This message instance will not be updated by this operation.
*
* <p>Reactions are the small emoji/emotes below a message that have a counter beside them
Expand Down Expand Up @@ -1380,12 +1366,7 @@ default boolean isFromGuild()
* <li>If the provided {@link net.dv8tion.jda.api.entities.Emote Emote} is fake {@link net.dv8tion.jda.api.entities.Emote#isFake() Emote.isFake()}.</li>
* <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>
* <li>If the provided user is null</li>
* </ul>
* @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}.
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link java.lang.Void}
*
Expand Down Expand Up @@ -1452,8 +1433,6 @@ default boolean isFromGuild()
* <br>A reference of unicode emojis can be found here:
* <a href="http://unicode.org/emoji/charts/full-emoji-list.html" target="_blank">Emoji Table</a>.
*
* <p>Please note that you <b>can't</b> remove reactions of other users if this message was sent in a {@link net.dv8tion.jda.api.entities.PrivateChannel PrivateChannel}!
*
* <p>This message instance will not be updated by this operation.
*
* <p>Reactions are the small emoji/emotes below a message that have a counter beside them
Expand Down Expand Up @@ -1491,11 +1470,7 @@ default boolean isFromGuild()
* <li>{@link net.dv8tion.jda.api.Permission#MESSAGE_MANAGE Permission.MESSAGE_MANAGE}</li>
* </ul>
* @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 the provided unicode emoji is null or empty.
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link java.lang.Void}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public RestAction<Void> addReaction(@Nonnull String unicode)
@Override
public RestAction<Void> clearReactions()
{
if (!isFromGuild())
if (!isFromType(ChannelType.TEXT))
throw new IllegalStateException("Cannot clear reactions from a message in a Group or PrivateChannel.");
return getTextChannel().clearReactionsById(getId());
}
Expand All @@ -172,17 +172,13 @@ public RestAction<Void> clearReactions()
@Override
public RestAction<Void> clearReactions(@Nonnull String unicode)
{
if (!isFromGuild())
throw new IllegalStateException("Cannot clear reactions from a message in a Group or PrivateChannel.");
return getTextChannel().clearReactionsById(getId(), unicode);
}

@Nonnull
@Override
public RestAction<Void> clearReactions(@Nonnull Emote emote)
{
if (!isFromGuild())
throw new IllegalStateException("Cannot clear reactions from a message in a Group or PrivateChannel.");
return getTextChannel().clearReactionsById(getId(), emote);
}

Expand All @@ -197,14 +193,6 @@ public RestAction<Void> removeReaction(@Nonnull Emote emote)
@Override
public RestAction<Void> removeReaction(@Nonnull Emote emote, @Nonnull User user)
{
Checks.notNull(user, "User"); // to prevent NPEs
// check if the passed user is the SelfUser, then the ChannelType doesn't matter and
// we can safely remove that
if (user.equals(getJDA().getSelfUser()))
return channel.removeReactionById(getIdLong(), emote);

if (!isFromGuild())
throw new IllegalStateException("Cannot remove reactions of others from a message in a Group or PrivateChannel.");
return getTextChannel().removeReactionById(getIdLong(), emote, user);
}

Expand All @@ -219,12 +207,6 @@ public RestAction<Void> removeReaction(@Nonnull String unicode)
@Override
public RestAction<Void> removeReaction(@Nonnull String unicode, @Nonnull User user)
{
Checks.notNull(user, "User");
if (user.equals(getJDA().getSelfUser()))
return channel.removeReactionById(getIdLong(), unicode);

if (!isFromGuild())
throw new IllegalStateException("Cannot remove reactions of others from a message in a Group or PrivateChannel.");
return getTextChannel().removeReactionById(getId(), unicode, user);
}

Expand Down Expand Up @@ -408,7 +390,7 @@ public List<Member> getMentionedMembers(@Nonnull Guild guild)
@Override
public List<Member> getMentionedMembers()
{
if (isFromGuild())
if (isFromType(ChannelType.TEXT))
return getMentionedMembers(getGuild());
else
throw new IllegalStateException("You must specify a Guild for Messages which are not sent from a TextChannel!");
Expand Down Expand Up @@ -542,7 +524,7 @@ else if (mentionable instanceof Member)
final Member member = (Member) mentionable;
return CollectionUtils.containsAny(getMentionedRoles(), member.getRoles());
}
else if (isFromGuild() && mentionable instanceof User)
else if (isFromType(ChannelType.TEXT) && mentionable instanceof User)
{
final Member member = getGuild().getMember((User) mentionable);
return member != null && CollectionUtils.containsAny(getMentionedRoles(), member.getRoles());
Expand Down Expand Up @@ -614,7 +596,7 @@ public String getContentDisplay()
for (User user : getMentionedUsers())
{
String name;
if (isFromGuild() && getGuild().isMember(user))
if (isFromType(ChannelType.TEXT) && getGuild().isMember(user))
name = getGuild().getMember(user).getEffectiveName();
else
name = user.getName();
Expand Down Expand Up @@ -700,8 +682,6 @@ public PrivateChannel getPrivateChannel()
@Override
public TextChannel getTextChannel()
{
// might be the reason why other methods calling this throw that exception
// in case of other GuildChannels being able to receive messages in the future
if (!isFromType(ChannelType.TEXT))
throw new IllegalStateException("This message was not sent in a text channel");
return (TextChannel) channel;
Expand All @@ -710,7 +690,7 @@ public TextChannel getTextChannel()
@Override
public Category getCategory()
{
return isFromGuild() ? getTextChannel().getParent() : null;
return isFromType(ChannelType.TEXT) ? getTextChannel().getParent() : null;
}

@Nonnull
Expand Down

0 comments on commit c9b68b9

Please sign in to comment.