Skip to content

Commit

Permalink
Move canTalk() from GuildMessageChannel to MessageChannel (#1956)
Browse files Browse the repository at this point in the history
Co-authored-by: V-Play-Games <vaibhavnargwani28@gmail>
  • Loading branch information
V-Play-Games and V-Play-Games committed Dec 24, 2021
1 parent 32f7369 commit 56bef05
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
Expand Up @@ -14,16 +14,7 @@
//TODO-v5: Docs
public interface GuildMessageChannel extends GuildChannel, MessageChannel
{
/**
* Whether we can send messages in this channel.
* <br>This is an overload of {@link #canTalk(Member)} with the SelfMember.
* <br>Checks for both {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} and
* {@link net.dv8tion.jda.api.Permission#MESSAGE_SEND Permission.MESSAGE_SEND}.
*
* For {@link ThreadChannel} this method checks for {@link Permission#MESSAGE_SEND_IN_THREADS} instead of {@link Permission#MESSAGE_SEND}.
*
* @return True, if we are able to read and send messages in this channel
*/
@Override
default boolean canTalk()
{
return canTalk(getGuild().getSelfMember());
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/net/dv8tion/jda/api/entities/MessageChannel.java
Expand Up @@ -101,7 +101,6 @@ default String getLatestMessageId()
return Long.toUnsignedString(getLatestMessageIdLong());
}


/**
* The id for the most recent message sent
* in this current MessageChannel.
Expand Down Expand Up @@ -135,6 +134,19 @@ default boolean hasLatestMessage()
return getLatestMessageIdLong() != 0;
}

/**
* Whether the currently logged in user can send messages in this channel or not.
* <br>For {@link GuildMessageChannel} this method checks for
* both {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL}
* and {@link net.dv8tion.jda.api.Permission#MESSAGE_SEND Permission.MESSAGE_SEND}.
* <br>For {@link ThreadChannel} this method checks for {@link net.dv8tion.jda.api.Permission#MESSAGE_SEND_IN_THREADS} instead of {@link net.dv8tion.jda.api.Permission#MESSAGE_SEND}.
* <br>For {@link PrivateChannel} this method checks if the user that this PrivateChannel communicates with is not a bot,
* but it does <b>not</b> check if the said user blocked the currently logged in user or have their DMs disabled.
*
* @return True, if we are able to read and send messages in this channel
*/
boolean canTalk();

/**
* Convenience method to delete messages in the most efficient way available.
* <br>This combines both {@link TextChannel#deleteMessagesByIds(Collection)} as well as {@link #deleteMessageById(long)}
Expand Down
Expand Up @@ -82,6 +82,12 @@ public long getLatestMessageIdLong()
return latestMessageId;
}

@Override
public boolean canTalk()
{
return !user.isBot();
}

@Override
public void checkCanAccessChannel() {}

Expand Down

0 comments on commit 56bef05

Please sign in to comment.