diff --git a/src/main/java/net/dv8tion/jda/internal/entities/channel/concrete/PrivateChannelImpl.java b/src/main/java/net/dv8tion/jda/internal/entities/channel/concrete/PrivateChannelImpl.java index cc8d32508a3..23d4a2138fe 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/channel/concrete/PrivateChannelImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/channel/concrete/PrivateChannelImpl.java @@ -155,8 +155,6 @@ public PrivateChannelImpl setLatestMessageIdLong(long latestMessageId) return this; } - // -- Object -- - @Override public int hashCode() { @@ -195,4 +193,7 @@ private void checkBot() if (getUser() != null && getUser().isBot()) throw new UnsupportedOperationException("Cannot send a private message between bots."); } + + @Override + public void checkCanAccess() {} } diff --git a/src/main/java/net/dv8tion/jda/internal/entities/channel/mixin/ChannelMixin.java b/src/main/java/net/dv8tion/jda/internal/entities/channel/mixin/ChannelMixin.java index 7f24ef5e51c..ea68d8dfdd1 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/channel/mixin/ChannelMixin.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/channel/mixin/ChannelMixin.java @@ -42,4 +42,7 @@ default RestAction delete() // ---- State Accessors ---- T setName(String name); + + // ---- Hooks ---- + void checkCanAccess(); } diff --git a/src/main/java/net/dv8tion/jda/internal/entities/channel/mixin/middleman/GuildMessageChannelMixin.java b/src/main/java/net/dv8tion/jda/internal/entities/channel/mixin/middleman/GuildMessageChannelMixin.java index 0314fb724ee..c93ac2f4811 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/channel/mixin/middleman/GuildMessageChannelMixin.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/channel/mixin/middleman/GuildMessageChannelMixin.java @@ -46,6 +46,7 @@ public interface GuildMessageChannelMixin> @CheckReturnValue default RestAction deleteMessagesByIds(@Nonnull Collection messageIds) { + checkCanAccess(); checkPermission(Permission.MESSAGE_MANAGE, "Must have MESSAGE_MANAGE in order to bulk delete messages in this channel regardless of author."); if (messageIds.size() < 2 || messageIds.size() > 100) @@ -66,6 +67,7 @@ default RestAction removeReactionById(@Nonnull String messageId, @Nonnull Checks.notNull(emoji, "Emoji"); Checks.notNull(user, "User"); + checkCanAccess(); if (!getJDA().getSelfUser().equals(user)) checkPermission(Permission.MESSAGE_MANAGE); @@ -85,6 +87,7 @@ default RestAction clearReactionsById(@Nonnull String messageId) { Checks.isSnowflake(messageId, "Message ID"); + checkCanAccess(); checkPermission(Permission.MESSAGE_MANAGE); final Route.CompiledRoute route = Route.Messages.REMOVE_ALL_REACTIONS.compile(getId(), messageId); @@ -98,6 +101,7 @@ default RestAction clearReactionsById(@Nonnull String messageId, @Nonnull Checks.notNull(messageId, "Message ID"); Checks.notNull(emoji, "Emoji"); + checkCanAccess(); checkPermission(Permission.MESSAGE_MANAGE); Route.CompiledRoute route = Route.Messages.CLEAR_EMOJI_REACTIONS.compile(getId(), messageId, emoji.getAsReactionCode()); diff --git a/src/main/java/net/dv8tion/jda/internal/entities/channel/mixin/middleman/MessageChannelMixin.java b/src/main/java/net/dv8tion/jda/internal/entities/channel/mixin/middleman/MessageChannelMixin.java index 28e86c12eb8..3c80eff1c96 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/channel/mixin/middleman/MessageChannelMixin.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/channel/mixin/middleman/MessageChannelMixin.java @@ -41,6 +41,7 @@ import net.dv8tion.jda.api.utils.messages.MessageCreateData; import net.dv8tion.jda.api.utils.messages.MessageEditData; import net.dv8tion.jda.api.utils.messages.MessagePollData; +import net.dv8tion.jda.internal.entities.channel.mixin.ChannelMixin; import net.dv8tion.jda.internal.requests.RestActionImpl; import org.jetbrains.annotations.NotNull; @@ -51,12 +52,14 @@ public interface MessageChannelMixin> extends MessageChannel, - MessageChannelUnion + MessageChannelUnion, + ChannelMixin { // ---- Default implementations of interface ---- @Nonnull default List> purgeMessages(@Nonnull List messages) { + checkCanAccess(); if (messages == null || messages.isEmpty()) return Collections.emptyList(); @@ -80,6 +83,7 @@ default List> purgeMessages(@Nonnull List> purgeMessagesById(@Nonnull long... messageIds) { + checkCanAccess(); if (messageIds == null || messageIds.length == 0) return Collections.emptyList(); @@ -207,6 +211,7 @@ default RestAction retrieveMessageById(@Nonnull String messageId) @CheckReturnValue default AuditableRestAction deleteMessageById(@Nonnull String messageId) { + checkCanAccess(); //We don't know if this is a Message sent by us or another user, so we can't run checks for Permission.MESSAGE_MANAGE return MessageChannelUnion.super.deleteMessageById(messageId); } @@ -263,6 +268,7 @@ default MessageHistory.MessageRetrieveAction getHistoryFromBeginning(int limit) @CheckReturnValue default RestAction sendTyping() { + checkCanAccess(); return MessageChannelUnion.super.sendTyping(); } @@ -310,6 +316,7 @@ default RestAction unpinMessageById(@Nonnull String messageId) @CheckReturnValue default RestAction> retrievePinnedMessages() { + checkCanAccess(); return MessageChannelUnion.super.retrievePinnedMessages(); }