Skip to content

Commit

Permalink
Support messages in stage channels (#2399)
Browse files Browse the repository at this point in the history
* Add support for stage channel messages
* Add asAudioChannel to some more unions
* Add asStageChannel to unions
* Add user_limit to stage channels
  • Loading branch information
MinnDevelopment authored Mar 19, 2023
1 parent 83d370d commit 7bdef70
Show file tree
Hide file tree
Showing 19 changed files with 369 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public boolean isMessage()
{
case TEXT:
case VOICE:
case STAGE:
case NEWS:
case PRIVATE:
case GROUP:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
import net.dv8tion.jda.api.entities.GuildVoiceState;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.StageInstance;
import net.dv8tion.jda.api.entities.channel.attribute.IAgeRestrictedChannel;
import net.dv8tion.jda.api.entities.channel.attribute.ISlowmodeChannel;
import net.dv8tion.jda.api.entities.channel.attribute.IWebhookContainer;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildChannel;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.managers.channel.concrete.StageChannelManager;
Expand All @@ -42,8 +45,13 @@
*
* <p>This is a specialized AudioChannel that can be used to host events with speakers and listeners.
*/
public interface StageChannel extends GuildChannel, AudioChannel, StandardGuildChannel
public interface StageChannel extends StandardGuildChannel, GuildMessageChannel, AudioChannel, IWebhookContainer, IAgeRestrictedChannel, ISlowmodeChannel
{
/**
* The maximum limit you can set with {@link StageChannelManager#setUserLimit(int)}. ({@value})
*/
int MAX_USERLIMIT = 10000;

/**
* {@link StageInstance} attached to this stage channel.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.channel.attribute.IAgeRestrictedChannel;
import net.dv8tion.jda.api.entities.channel.attribute.ISlowmodeChannel;
import net.dv8tion.jda.api.entities.channel.attribute.IWebhookContainer;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
Expand Down Expand Up @@ -46,16 +47,12 @@
* @see JDA#getVoiceChannelsByName(String, boolean)
* @see JDA#getVoiceChannelById(long)
*/
public interface VoiceChannel extends AudioChannel, StandardGuildChannel, GuildMessageChannel, IWebhookContainer, IAgeRestrictedChannel
public interface VoiceChannel extends StandardGuildChannel, GuildMessageChannel, AudioChannel, IWebhookContainer, IAgeRestrictedChannel, ISlowmodeChannel
{
/**
* The maximum amount of {@link net.dv8tion.jda.api.entities.Member Members} that can be in this
* {@link VoiceChannel VoiceChannel} at once.
* <br>0 - No limit
*
* @return The maximum amount of members allowed in this channel at once.
* The maximum limit you can set with {@link VoiceChannelManager#setUserLimit(int)}. ({@value})
*/
int getUserLimit();
int MAX_USERLIMIT = 99;

@Nonnull
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ public interface AudioChannel extends StandardGuildChannel
*/
int getBitrate();

/**
* The maximum amount of {@link net.dv8tion.jda.api.entities.Member Members} that be in an audio connection within this channel concurrently.
* <br>Returns 0 if there is no limit.
*
* <p>Moderators with the {@link net.dv8tion.jda.api.Permission#VOICE_MOVE_OTHERS VOICE_MOVE_OTHERS} permission can bypass this limit.
*
* @return The maximum connections allowed in this channel concurrently
*/
int getUserLimit();

/**
* The {@link Region} of this channel.
* <br>This will return {@link Region#AUTOMATIC} if the region of this channel is set to Automatic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.dv8tion.jda.api.entities.channel.concrete.StageChannel;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -79,4 +80,23 @@ public interface AudioChannelUnion extends AudioChannel
*/
@Nonnull
StageChannel asStageChannel();

/**
* Casts this union to a {@link GuildMessageChannel}.
* <br>This method exists for developer discoverability.
*
* <p>Note: This is effectively equivalent to using the cast operator:
* <pre>{@code
* //These are the same!
* GuildMessageChannel channel = union.asGuildMessageChannel();
* GuildMessageChannel channel2 = (GuildMessageChannel) union;
* }</pre>
*
* @throws IllegalStateException
* If the channel represented by this union is not actually a {@link GuildMessageChannel}.
*
* @return The channel as a {@link GuildMessageChannel}
*/
@Nonnull
GuildMessageChannel asGuildMessageChannel();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@

import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer;
import net.dv8tion.jda.api.entities.channel.concrete.NewsChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.api.entities.channel.concrete.*;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildChannel;
import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildMessageChannel;
Expand All @@ -38,6 +36,7 @@
* <li>{@link TextChannel}</li>
* <li>{@link NewsChannel}</li>
* <li>{@link VoiceChannel}</li>
* <li>{@link StageChannel}</li>
* <li>{@link ThreadChannel}</li>
* </ul>
*/
Expand Down Expand Up @@ -131,6 +130,28 @@ public interface GuildMessageChannelUnion extends GuildMessageChannel
@Nonnull
VoiceChannel asVoiceChannel();

/**
* Casts this union to a {@link StageChannel}.
* This method exists for developer discoverability.
*
* Note: This is effectively equivalent to using the cast operator:
* <pre><code>
* //These are the same!
* StageChannel channel = union.asStageChannel();
* StageChannel channel2 = (StageChannel) union;
* </code></pre>
*
* You can use {@link #getType()} to see if the channel is of type {@link ChannelType#STAGE} to validate
* whether you can call this method in addition to normal instanceof checks: <code>channel instanceof StageChannel</code>
*
* @throws IllegalStateException
* If the channel represented by this union is not actually a {@link StageChannel}.
*
* @return The channel as a {@link StageChannel}
*/
@Nonnull
StageChannel asStageChannel();

/**
* Casts this union to a {@link net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer}.
* This method exists for developer discoverability.
Expand All @@ -149,6 +170,7 @@ public interface GuildMessageChannelUnion extends GuildMessageChannel
*
* @return The channel as a {@link net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer}
*/
@Nonnull
IThreadContainer asThreadContainer();

/**
Expand Down Expand Up @@ -187,4 +209,25 @@ public interface GuildMessageChannelUnion extends GuildMessageChannel
*/
@Nonnull
StandardGuildMessageChannel asStandardGuildMessageChannel();

/**
* Casts this union to a {@link AudioChannel}.
* This method exists for developer discoverability.
*
* Note: This is effectively equivalent to using the cast operator:
* <pre><code>
* //These are the same!
* AudioChannel channel = union.asAudioChannel();
* AudioChannel channel2 = (AudioChannel) union;
* </code></pre>
*
* You can use <code>channel instanceof AudioChannel</code> to validate whether you can call this method.
*
* @throws IllegalStateException
* If the channel represented by this union is not actually a {@link AudioChannel}.
*
* @return The channel as a {@link AudioChannel}
*/
@Nonnull
AudioChannel asAudioChannel();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer;
import net.dv8tion.jda.api.entities.channel.attribute.IWebhookContainer;
import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel;
import net.dv8tion.jda.api.entities.channel.concrete.NewsChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.api.entities.channel.concrete.*;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildChannel;
import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildMessageChannel;
Expand All @@ -38,6 +36,8 @@
* <ul>
* <li>{@link TextChannel}</li>
* <li>{@link NewsChannel}</li>
* <li>{@link VoiceChannel}</li>
* <li>{@link StageChannel}</li>
* <li>{@link ForumChannel}</li>
* </ul>
*/
Expand Down Expand Up @@ -152,6 +152,28 @@ public interface IWebhookContainerUnion extends IWebhookContainer
@Nonnull
VoiceChannel asVoiceChannel();

/**
* Casts this union to a {@link StageChannel}.
* This method exists for developer discoverability.
*
* Note: This is effectively equivalent to using the cast operator:
* <pre><code>
* //These are the same!
* StageChannel channel = union.asStageChannel();
* StageChannel channel2 = (StageChannel) union;
* </code></pre>
*
* You can use {@link #getType()} to see if the channel is of type {@link ChannelType#STAGE} to validate
* whether you can call this method in addition to normal instanceof checks: <code>channel instanceof StageChannel</code>
*
* @throws IllegalStateException
* If the channel represented by this union is not actually a {@link StageChannel}.
*
* @return The channel as a {@link StageChannel}
*/
@Nonnull
StageChannel asStageChannel();

/**
* Casts this union to a {@link GuildMessageChannel}.
* <br>This works for the following channel types represented by this union:
Expand Down Expand Up @@ -215,4 +237,25 @@ public interface IWebhookContainerUnion extends IWebhookContainer
*/
@Nonnull
StandardGuildMessageChannel asStandardGuildMessageChannel();

/**
* Casts this union to a {@link AudioChannel}.
* This method exists for developer discoverability.
*
* Note: This is effectively equivalent to using the cast operator:
* <pre><code>
* //These are the same!
* AudioChannel channel = union.asAudioChannel();
* AudioChannel channel2 = (AudioChannel) union;
* </code></pre>
*
* You can use <code>channel instanceof AudioChannel</code> to validate whether you can call this method.
*
* @throws IllegalStateException
* If the channel represented by this union is not actually a {@link AudioChannel}.
*
* @return The channel as a {@link AudioChannel}
*/
@Nonnull
AudioChannel asAudioChannel();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer;
import net.dv8tion.jda.api.entities.channel.concrete.*;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;

Expand All @@ -34,6 +35,7 @@
* <li>{@link TextChannel}</li>
* <li>{@link NewsChannel}</li>
* <li>{@link VoiceChannel}</li>
* <li>{@link StageChannel}</li>
* <li>{@link ThreadChannel}</li>
* <li>{@link PrivateChannel}</li>
* </ul>
Expand Down Expand Up @@ -150,6 +152,28 @@ public interface MessageChannelUnion extends MessageChannel
@Nonnull
VoiceChannel asVoiceChannel();

/**
* Casts this union to a {@link StageChannel}.
* This method exists for developer discoverability.
*
* Note: This is effectively equivalent to using the cast operator:
* <pre><code>
* //These are the same!
* StageChannel channel = union.asStageChannel();
* StageChannel channel2 = (StageChannel) union;
* </code></pre>
*
* You can use {@link #getType()} to see if the channel is of type {@link ChannelType#STAGE} to validate
* whether you can call this method in addition to normal instanceof checks: <code>channel instanceof StageChannel</code>
*
* @throws IllegalStateException
* If the channel represented by this union is not actually a {@link StageChannel}.
*
* @return The channel as a {@link StageChannel}
*/
@Nonnull
StageChannel asStageChannel();

/**
* Casts this union to a {@link net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer}.
* This method exists for developer discoverability.
Expand Down Expand Up @@ -197,4 +221,25 @@ public interface MessageChannelUnion extends MessageChannel
*/
@Nonnull
GuildMessageChannel asGuildMessageChannel();

/**
* Casts this union to a {@link AudioChannel}.
* This method exists for developer discoverability.
*
* Note: This is effectively equivalent to using the cast operator:
* <pre><code>
* //These are the same!
* AudioChannel channel = union.asAudioChannel();
* AudioChannel channel2 = (AudioChannel) union;
* </code></pre>
*
* You can use <code>channel instanceof AudioChannel</code> to validate whether you can call this method.
*
* @throws IllegalStateException
* If the channel represented by this union is not actually a {@link AudioChannel}.
*
* @return The channel as a {@link AudioChannel}
*/
@Nonnull
AudioChannel asAudioChannel();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package net.dv8tion.jda.api.managers.channel.concrete;

import net.dv8tion.jda.api.entities.channel.concrete.StageChannel;
import net.dv8tion.jda.api.managers.channel.attribute.IAgeRestrictedChannelManager;
import net.dv8tion.jda.api.managers.channel.attribute.ISlowmodeChannelManager;
import net.dv8tion.jda.api.managers.channel.middleman.AudioChannelManager;
import net.dv8tion.jda.api.managers.channel.middleman.StandardGuildChannelManager;

Expand All @@ -32,6 +34,8 @@
*/
public interface StageChannelManager extends
AudioChannelManager<StageChannel, StageChannelManager>,
StandardGuildChannelManager<StageChannel, StageChannelManager>
StandardGuildChannelManager<StageChannel, StageChannelManager>,
IAgeRestrictedChannelManager<StageChannel, StageChannelManager>,
ISlowmodeChannelManager<StageChannel, StageChannelManager>
{
}
Loading

0 comments on commit 7bdef70

Please sign in to comment.