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

Introduce Channel Unions #2138

Merged
merged 20 commits into from
Jul 3, 2022
Merged
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2316f05
First pass on new union types
DV8FromTheWorld May 14, 2022
bda7ac3
Added documentation
DV8FromTheWorld May 22, 2022
7c1f502
Removed pointless union
DV8FromTheWorld May 22, 2022
119bb0c
Update src/main/java/net/dv8tion/jda/api/entities/IWebhookContainer.java
DV8FromTheWorld May 22, 2022
2a71e0b
Merge branch 'master' of https://github.com/DV8FromTheWorld/JDA into …
DV8FromTheWorld May 22, 2022
774f038
Merge branch 'feature/channel-unions' of https://github.com/DV8FromTh…
DV8FromTheWorld May 22, 2022
aee55a0
Updated docs based on PR feedback
DV8FromTheWorld Jun 18, 2022
9804211
added asGuildMessageChannel to MessageChannelUnion
DV8FromTheWorld Jun 18, 2022
3a5db33
Introduced asThreadContainer to unions
DV8FromTheWorld Jun 18, 2022
35c45fc
Fixed <br><br> issue
DV8FromTheWorld Jun 30, 2022
2c2e6e1
Created GuildChannelUnion to simplify OptionMapping interface
DV8FromTheWorld Jun 30, 2022
d5bc09d
Addressed comments about docs maintainability
DV8FromTheWorld Jul 2, 2022
a1c3ecd
Merge branch 'master' of https://github.com/DV8FromTheWorld/JDA into …
DV8FromTheWorld Jul 2, 2022
49f2493
Removed channel from WebhookMessageActionImpl as it wasn't needed
DV8FromTheWorld Jul 3, 2022
6cdbf0c
Introduced ChannelUnion and removed majority of getXChannel getters i…
DV8FromTheWorld Jul 3, 2022
a98b730
Introduced IPermissionContainerUnion
DV8FromTheWorld Jul 3, 2022
5b24fcc
Fixed 6+ year old typo
DV8FromTheWorld Jul 3, 2022
5b09a3c
Update MessageReaction#getGuild contract to throw on non-guild channel.
DV8FromTheWorld Jul 3, 2022
5026636
Fix Javadoc
DV8FromTheWorld Jul 3, 2022
0377e87
Fix examples
DV8FromTheWorld Jul 3, 2022
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
6 changes: 3 additions & 3 deletions src/main/java/net/dv8tion/jda/api/entities/ChannelField.java
Original file line number Diff line number Diff line change
@@ -78,16 +78,16 @@ public enum ChannelField
*
* Limited to {@link NewsChannel NewsChannels} and {@link TextChannel TextChannels}.
*
* @see BaseGuildMessageChannel#getTopic()
* @see StandardGuildMessageChannel#getTopic()
*/
TOPIC("topic", AuditLogKey.CHANNEL_TOPIC),

/**
* The NSFW state of the channel.
*
* Limited to {@link BaseGuildMessageChannel Base Guild Channels} (and implementations).
* Limited to {@link StandardGuildMessageChannel StandardGuildMessageChannels} (and implementations).
*
* @see BaseGuildMessageChannel#isNSFW()
* @see StandardGuildMessageChannel#isNSFW()
*/
NSFW("nsfw", AuditLogKey.CHANNEL_NSFW),

9 changes: 5 additions & 4 deletions src/main/java/net/dv8tion/jda/api/entities/Guild.java
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.Region;
import net.dv8tion.jda.api.entities.channel.IGuildChannelContainer;
import net.dv8tion.jda.api.entities.channel.unions.DefaultGuildChannelUnion;
import net.dv8tion.jda.api.entities.templates.Template;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.interactions.commands.Command;
@@ -1943,17 +1944,17 @@ default RestAction<ListedEmote> retrieveEmote(@Nonnull Emote emote)
Role getPublicRole();

/**
* The default {@link net.dv8tion.jda.api.entities.BaseGuildMessageChannel BaseGuildMessageChannel} for a {@link net.dv8tion.jda.api.entities.Guild Guild}.
* The default {@link net.dv8tion.jda.api.entities.StandardGuildChannel} for a {@link net.dv8tion.jda.api.entities.Guild Guild}.
* <br>This is the channel that the Discord client will default to opening when a Guild is opened for the first time when accepting an invite
* that is not directed at a specific {@link net.dv8tion.jda.api.entities.BaseGuildMessageChannel BaseGuildMessageChannel}.
* that is not directed at a specific {@link IInviteContainer channel}.
*
* <p>Note: This channel is the first channel in the guild (ordered by position) that the {@link #getPublicRole()}
* has the {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} in.
*
* @return The {@link net.dv8tion.jda.api.entities.BaseGuildMessageChannel BaseGuildMessageChannel} representing the default channel for this guild
* @return The {@link net.dv8tion.jda.api.entities.StandardGuildChannel channel} representing the default channel for this guild
*/
@Nullable
BaseGuildMessageChannel getDefaultChannel();
DefaultGuildChannelUnion getDefaultChannel();

/**
* Returns the {@link GuildManager GuildManager} for this Guild, used to modify
Original file line number Diff line number Diff line change
@@ -15,10 +15,9 @@
/**
* Represents all message channels present in guilds.
*
* This includes channels that are not included in {@link BaseGuildMessageChannel BaseGuildMessageChannel}, such as {@link ThreadChannel}.
*
* @see BaseGuildMessageChannel
* This includes channels that are not included in {@link StandardGuildMessageChannel}, such as {@link ThreadChannel}.
*
* @see StandardGuildMessageChannel
*/
public interface GuildMessageChannel extends GuildChannel, MessageChannel
{
Original file line number Diff line number Diff line change
@@ -1,51 +1,38 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.api.entities;

import net.dv8tion.jda.api.managers.channel.middleman.BaseGuildMessageChannelManager;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.requests.restaction.AuditableRestAction;
import net.dv8tion.jda.api.requests.restaction.ChannelAction;
import net.dv8tion.jda.api.requests.restaction.WebhookAction;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;


/**
* Represents a standard {@link Guild Guild} {@link MessageChannel MessageChannel}.
* <br>These are the "<i>normal</i>" message channels that are present in the channel sidebar.
* These are <b>not</b> {@link ThreadChannel ThreadChannels}.
* Represents a {@link GuildChannel} that is capable of utilizing <a href="https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks" target="_blank">webhooks</a>.
*
* @see net.dv8tion.jda.api.entities.GuildMessageChannel
* @see TextChannel
* @see NewsChannel
* Webhooks can be used to integrate third-party systems into Discord by way of sending information via messages.
*/
public interface BaseGuildMessageChannel extends GuildMessageChannel, IThreadContainer, GuildChannel, ICategorizableChannel, ICopyableChannel, IPermissionContainer, IMemberContainer, IInviteContainer, IPositionableChannel
public interface IWebhookContainer extends GuildChannel
{
//TODO-v5: Docs
@Override
@Nonnull
BaseGuildMessageChannelManager<?, ?> getManager();

/**
* The topic set for this TextChannel.
* <br>If no topic has been set, this returns null.
*
* @return Possibly-null String containing the topic of this TextChannel.
*/
@Nullable
String getTopic();

/**
* Whether or not this channel is considered as "NSFW" (Not-Safe-For-Work)
*
* @return True, If this TextChannel is considered NSFW by the official Discord Client
*/
boolean isNSFW();

/**
* Retrieves the {@link net.dv8tion.jda.api.entities.Webhook Webhooks} attached to this TextChannel.
/**
* Retrieves the {@link net.dv8tion.jda.api.entities.Webhook Webhooks} attached to this channel.
*
* <p>Possible ErrorResponses include:
* <ul>
@@ -102,7 +89,7 @@ public interface BaseGuildMessageChannel extends GuildMessageChannel, IThreadCon
* <p>Possible ErrorResponses include:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_WEBHOOK}
* <br>The provided id does not refer to a WebHook present in this TextChannel, either due
* <br>The provided id does not refer to a WebHook present in this chanel, either due
DV8FromTheWorld marked this conversation as resolved.
Show resolved Hide resolved
* to it not existing or having already been deleted.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL}
@@ -130,14 +117,4 @@ public interface BaseGuildMessageChannel extends GuildMessageChannel, IThreadCon
@Nonnull
@CheckReturnValue
AuditableRestAction<Void> deleteWebhookById(@Nonnull String id);

@Override
@Nonnull
@CheckReturnValue
ChannelAction<? extends BaseGuildMessageChannel> createCopy(@Nonnull Guild guild);

@Override
@Nonnull
@CheckReturnValue
ChannelAction<? extends BaseGuildMessageChannel> createCopy();
}
7 changes: 4 additions & 3 deletions src/main/java/net/dv8tion/jda/api/entities/Member.java
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import net.dv8tion.jda.annotations.Incubating;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.channel.unions.DefaultGuildChannelUnion;
import net.dv8tion.jda.api.requests.restaction.AuditableRestAction;
import net.dv8tion.jda.api.utils.ImageProxy;

@@ -422,18 +423,18 @@ default ImageProxy getEffectiveAvatar()
boolean isPending();

/**
* The default {@link net.dv8tion.jda.api.entities.BaseGuildMessageChannel BaseGuildMessageChannel} for a {@link net.dv8tion.jda.api.entities.Member Member}.
* The default {@link net.dv8tion.jda.api.entities.StandardGuildChannel channel} for a {@link net.dv8tion.jda.api.entities.Member Member}.
DV8FromTheWorld marked this conversation as resolved.
Show resolved Hide resolved
* <br>This is the channel that the Discord client will default to opening when a Guild is opened for the first time
* after joining the guild.
* <br>The default channel is the channel with the highest position in which the member has
* {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} permissions. If this requirement doesn't apply for
* any channel in the guild, this method returns {@code null}.
*
* @return The {@link net.dv8tion.jda.api.entities.BaseGuildMessageChannel BaseGuildMessageChannel} representing the default channel for this member
* @return The {@link StandardGuildChannel channel} representing the default channel for this member
DV8FromTheWorld marked this conversation as resolved.
Show resolved Hide resolved
* or null if no such channel exists.
*/
@Nullable
BaseGuildMessageChannel getDefaultChannel();
DefaultGuildChannelUnion getDefaultChannel();

/**
* Bans this Member and deletes messages sent by the user based on the amount of delDays.
6 changes: 4 additions & 2 deletions src/main/java/net/dv8tion/jda/api/entities/Message.java
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.channel.unions.GuildMessageChannelUnion;
import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
import net.dv8tion.jda.api.exceptions.HttpException;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.interactions.InteractionType;
@@ -493,7 +495,7 @@ default boolean isFromGuild()
* @return The MessageChannel of this Message
*/
@Nonnull
MessageChannel getChannel();
MessageChannelUnion getChannel();

/**
* Returns the {@link net.dv8tion.jda.api.entities.GuildMessageChannel GuildMessageChannel} that this message was sent in
@@ -507,7 +509,7 @@ default boolean isFromGuild()
* @return The MessageChannel of this Message
*/
@Nonnull
GuildMessageChannel getGuildChannel();
GuildMessageChannelUnion getGuildChannel();

/**
* Returns the {@link net.dv8tion.jda.api.entities.PrivateChannel PrivateChannel} that this message was sent in.
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.exceptions.MissingAccessException;
import net.dv8tion.jda.api.requests.Request;
@@ -124,9 +125,9 @@ public boolean isEmpty()
* @return The MessageChannel of this history.
*/
@Nonnull
public MessageChannel getChannel()
public MessageChannelUnion getChannel()
{
return channel;
return (MessageChannelUnion) channel;
}

/**
13 changes: 7 additions & 6 deletions src/main/java/net/dv8tion/jda/api/entities/MessageReaction.java
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.channel.unions.GuildMessageChannelUnion;
import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.exceptions.PermissionException;
import net.dv8tion.jda.api.requests.RestAction;
@@ -203,21 +205,20 @@ public PrivateChannel getPrivateChannel()
* @return The channel this Reaction was used in
*/
@Nonnull
public MessageChannel getChannel()
public MessageChannelUnion getChannel()
{
return channel;
return (MessageChannelUnion) channel;
DV8FromTheWorld marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* The {@link net.dv8tion.jda.api.entities.GuildMessageChannel GuildMessageChannel}
* this Reaction was used in.
* The {@link net.dv8tion.jda.api.entities.GuildMessageChannel channel} this Reaction was used in.
*
* @return The channel this Reaction was used in or null if it wasn't used in a Guild
*/
@Nullable
public GuildMessageChannel getGuildChannel()
public GuildMessageChannelUnion getGuildChannel()
{
return getChannel() instanceof GuildMessageChannel ? (GuildMessageChannel) getChannel() : null;
return getChannel() instanceof GuildMessageChannel ? (GuildMessageChannelUnion) getChannel() : null;
}

/**
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.exceptions.MissingAccessException;
import net.dv8tion.jda.api.requests.RestAction;
@@ -187,9 +188,9 @@ public Message getMessage()
* @see #getChannelId()
*/
@Nullable
public MessageChannel getChannel()
public MessageChannelUnion getChannel()
{
return channel;
return (MessageChannelUnion) channel;
}


4 changes: 2 additions & 2 deletions src/main/java/net/dv8tion/jda/api/entities/NewsChannel.java
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
import javax.annotation.Nonnull;

/**
* Represents {@link BaseGuildMessageChannel} that are News Channels.
* Represents {@link StandardGuildMessageChannel} that are News Channels.
*
* The Discord client may refer to these as Announcement Channels.
*
@@ -26,7 +26,7 @@
* @see Message#getFlags()
* @see net.dv8tion.jda.api.entities.Message.MessageFlag#CROSSPOSTED
*/
public interface NewsChannel extends BaseGuildMessageChannel
public interface NewsChannel extends StandardGuildMessageChannel
{
/**
* Subscribes to the crossposted messages in this channel.
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@
*
* <p>This is a specialized AudioChannel that can be used to host events with speakers and listeners.
*/
public interface StageChannel extends GuildChannel, AudioChannel, ICategorizableChannel, ICopyableChannel, IPositionableChannel, IPermissionContainer, IMemberContainer, IInviteContainer
public interface StageChannel extends GuildChannel, AudioChannel, StandardGuildChannel
{
/**
* {@link StageInstance} attached to this stage channel.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.api.entities;

import net.dv8tion.jda.api.managers.channel.middleman.StandardGuildChannelManager;
import net.dv8tion.jda.api.requests.restaction.ChannelAction;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;

/**
* Represents a standard {@link GuildChannel} which are the "<i>normal</i>" channels that are present in the channel sidebar.
* They include functionality "expected" of normal Discord channels like {@link IPermissionContainer permissions},
* {@link IInviteContainer invite support}, {@link IPositionableChannel positioning}, the ability
* {@link ICategorizableChannel to be categorized}, and more.
*
* @see net.dv8tion.jda.api.entities.GuildMessageChannel
* @see TextChannel
* @see NewsChannel
* @see StageChannel
* @see VoiceChannel
*/
public interface StandardGuildChannel extends GuildChannel, IPermissionContainer, IPositionableChannel, ICopyableChannel, IMemberContainer, IInviteContainer, ICategorizableChannel
{
@Nonnull
@Override
StandardGuildChannelManager<?, ?> getManager();

@Override
@Nonnull
@CheckReturnValue
ChannelAction<? extends StandardGuildChannel> createCopy(@Nonnull Guild guild);

@Override
@Nonnull
@CheckReturnValue
ChannelAction<? extends StandardGuildChannel> createCopy();
}
Loading