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

Add initial support for media channels #2516

Merged
merged 31 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d7c4e69
Add initial support for media channels
MinnDevelopment Aug 2, 2023
be989cf
More event handling
MinnDevelopment Aug 3, 2023
fdf0524
Update ChannelAction
MinnDevelopment Aug 3, 2023
15d1592
Update manager
MinnDevelopment Aug 3, 2023
1197992
Add MediaChannel to union types
MinnDevelopment Aug 3, 2023
4ca272c
Add media channel cache access
MinnDevelopment Aug 3, 2023
56bcb01
Add Category#createMediaChannel
MinnDevelopment Aug 3, 2023
cd09eda
Update ShardManager
MinnDevelopment Aug 3, 2023
0944a68
Add new channel consistency unit test
MinnDevelopment Aug 3, 2023
4eba05c
Fix some docs
MinnDevelopment Aug 4, 2023
1116e1e
Add ChannelUpdateDefaultSortOrderEvent
MinnDevelopment Aug 4, 2023
7eb7821
Cleanup and docs fixes
MinnDevelopment Aug 4, 2023
b37a440
Fix some more docs
MinnDevelopment Aug 4, 2023
e8eb3c8
Add more docs and missing methods for sort order configuration
MinnDevelopment Aug 4, 2023
3e053f9
Add missing annotations
MinnDevelopment Aug 4, 2023
aade426
Correctly copy sort order in createCopy
MinnDevelopment Aug 4, 2023
d2a90d9
Fire event properly
MinnDevelopment Aug 4, 2023
1e83f27
Improve type transition handling
MinnDevelopment Aug 4, 2023
3a77df1
Generalize type transitions
MinnDevelopment Aug 7, 2023
39ff5c9
Add setters for default thread slowmode
MinnDevelopment Sep 17, 2023
15a4601
Cleanup code
MinnDevelopment Sep 17, 2023
1fb488d
Dedupe code
MinnDevelopment Sep 17, 2023
416b464
Merge remote-tracking branch 'origin/master' into feature/media-channels
MinnDevelopment Sep 17, 2023
2272672
Merge remote-tracking branch 'origin/master' into feature/media-channels
MinnDevelopment Sep 17, 2023
8ea22ce
Dedupe code and cleanup
MinnDevelopment Sep 28, 2023
43a6958
Add missing docs
MinnDevelopment Sep 28, 2023
729f940
Merge remote-tracking branch 'origin/master' into feature/media-channels
MinnDevelopment Sep 28, 2023
0de62ac
Add ChannelUtil
MinnDevelopment Sep 28, 2023
a821b26
Move safeChannelCast into ChannelUtil
MinnDevelopment Sep 28, 2023
26e2ed5
Use createGuildChannel in ChannelActionImpl
MinnDevelopment Sep 28, 2023
1ede329
Add sanity check for archived threads
MinnDevelopment Sep 28, 2023
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
14 changes: 7 additions & 7 deletions src/main/java/net/dv8tion/jda/api/audit/AuditLogKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,13 @@ public enum AuditLogKey
*/
CHANNEL_ID("channel_id"),

// /**
// * The {@link ForumChannel#getDefaultSortOrder()} value.
// * <br>Only for {@link ChannelType#FORUM}.
// *
// * <p>Expected type: <b>Integer</b>
// */
// CHANNEL_DEFAULT_SORT_ORDER("default_sort_order"),
/**
* The {@link ForumChannel#getDefaultSortOrder()} value.
* <br>Only for {@link ChannelType#FORUM} and {@link ChannelType#MEDIA}.
*
* <p>Expected type: <b>Integer</b>
*/
CHANNEL_DEFAULT_SORT_ORDER("default_sort_order"),

/**
* The {@link ForumChannel#getDefaultLayout()} value.
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/Guild.java
Original file line number Diff line number Diff line change
Expand Up @@ -4539,6 +4539,70 @@ default ChannelAction<ForumChannel> createForumChannel(@Nonnull String name)
@CheckReturnValue
ChannelAction<ForumChannel> createForumChannel(@Nonnull String name, @Nullable Category parent);

/**
* Creates a new {@link MediaChannel} in this Guild.
* For this to be successful, the logged in account has to have the {@link net.dv8tion.jda.api.Permission#MANAGE_CHANNEL MANAGE_CHANNEL} Permission.
*
* <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by
* the returned {@link RestAction RestAction} include the following:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>The channel could not be created due to a permission discrepancy</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MAX_CHANNELS MAX_CHANNELS}
* <br>The maximum number of channels were exceeded</li>
* </ul>
*
* @param name
* The name of the MediaChannel to create (up to {@value Channel#MAX_NAME_LENGTH} characters)
*
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If the logged in account does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_CHANNEL} permission
* @throws IllegalArgumentException
* If the provided name is {@code null}, blank, or longer than {@value Channel#MAX_NAME_LENGTH} characters
*
* @return A specific {@link ChannelAction ChannelAction}
* <br>This action allows to set fields for the new MediaChannel before creating it
*/
@Nonnull
@CheckReturnValue
default ChannelAction<MediaChannel> createMediaChannel(@Nonnull String name)
{
return createMediaChannel(name, null);
}

/**
* Creates a new {@link MediaChannel} in this Guild.
* For this to be successful, the logged in account has to have the {@link net.dv8tion.jda.api.Permission#MANAGE_CHANNEL MANAGE_CHANNEL} Permission.
*
* <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by
* the returned {@link RestAction RestAction} include the following:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>The channel could not be created due to a permission discrepancy</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MAX_CHANNELS MAX_CHANNELS}
* <br>The maximum number of channels were exceeded</li>
* </ul>
*
* @param name
* The name of the MediaChannel to create (up to {@value Channel#MAX_NAME_LENGTH} characters)
* @param parent
* The optional parent category for this channel, or null
*
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If the logged in account does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_CHANNEL} permission
* @throws IllegalArgumentException
* If the provided name is {@code null}, blank, or longer than {@value Channel#MAX_NAME_LENGTH} characters;
* or the provided parent is not in the same guild.
*
* @return A specific {@link ChannelAction ChannelAction}
* <br>This action allows to set fields for the new MediaChannel before creating it
*/
@Nonnull
@CheckReturnValue
ChannelAction<MediaChannel> createMediaChannel(@Nonnull String name, @Nullable Category parent);

/**
* Creates a new {@link Category Category} in this Guild.
* For this to be successful, the logged in account has to have the {@link net.dv8tion.jda.api.Permission#MANAGE_CHANNEL MANAGE_CHANNEL} Permission.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,14 @@ public enum ChannelField
*/
DEFAULT_FORUM_LAYOUT("default_forum_layout", AuditLogKey.DEFAULT_FORUM_LAYOUT),

// /**
// * The default sort order of a forum channel.
// *
// * <p>Limited to {@link ForumChannel Forum Channels}.
// *
// * @see ForumChannel#getDefaultSortOrder()
// */
// DEFAULT_SORT_ORDER("default_sort_order", AuditLogKey.CHANNEL_DEFAULT_SORT_ORDER)
/**
* The default sort order of a forum channel.
*
* <p>Limited to {@link ForumChannel Forum Channels} and {@link MediaChannel Media Channels}.
*
* @see ForumChannel#getDefaultSortOrder()
*/
DEFAULT_SORT_ORDER("default_sort_order", AuditLogKey.CHANNEL_DEFAULT_SORT_ORDER)
;

private final String fieldName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ public enum ChannelFlag
/**
* This is a {@link ForumChannel} which requires all new post threads to have at least one applied tag.
*/
REQUIRE_TAG(1 << 4);
REQUIRE_TAG(1 << 4),

/**
* This is a {@link net.dv8tion.jda.api.entities.channel.concrete.MediaChannel MediaChannel} which hides the copy embed option.
*/
HIDE_MEDIA_DOWNLOAD_OPTIONS(1 << 15);

private final int value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public enum ChannelType
*/
FORUM(15, 0, true),

/**
* A {@link MediaChannel}, Guild-Only.
*/
MEDIA(16, 0, true),

/**
* Unknown Discord channel type. Should never happen and would only possibly happen if Discord implemented a new
* channel type and JDA had yet to implement support for it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ default GuildChannel getGuildChannelById(long id)
channel = getThreadChannelById(id);
if (channel == null)
channel = getForumChannelById(id);
if (channel == null)
channel = getMediaChannelById(id);

return channel;
}
Expand Down Expand Up @@ -273,6 +275,8 @@ default GuildChannel getGuildChannelById(@Nonnull ChannelType type, long id)
return getCategoryById(id);
case FORUM:
return getForumChannelById(id);
case MEDIA:
return getMediaChannelById(id);
}

if (type.isThread())
Expand Down Expand Up @@ -1101,4 +1105,118 @@ default List<ForumChannel> getForumChannels()
{
return getForumChannelCache().asList();
}


// MediaChannels


/**
* {@link SnowflakeCacheView SnowflakeCacheView} of {@link MediaChannel}.
*
* <p>This getter exists on any instance of {@link IGuildChannelContainer} and only checks the caches with the relevant scoping.
* For {@link Guild}, {@link JDA}, or {@link ShardManager},
* this returns the relevant channel with respect to the cache within each of those objects.
* For a guild, this would mean it only returns channels within the same guild.
* <br>If this is called on {@link JDA} or {@link ShardManager}, this may return null immediately after building, because the cache isn't initialized yet.
* To make sure the cache is initialized after building your {@link JDA} instance, you can use {@link JDA#awaitReady()}.
*
* @return {@link SnowflakeCacheView SnowflakeCacheView}
*/
@Nonnull
SnowflakeCacheView<MediaChannel> getMediaChannelCache();

/**
* Gets a list of all {@link MediaChannel MediaChannels}
* in this Guild that have the same name as the one provided.
* <br>If there are no channels with the provided name, then this returns an empty list.
*
* <p>This getter exists on any instance of {@link IGuildChannelContainer} and only checks the caches with the relevant scoping.
* For {@link Guild}, {@link JDA}, or {@link ShardManager},
* this returns the relevant channel with respect to the cache within each of those objects.
* For a guild, this would mean it only returns channels within the same guild.
* <br>If this is called on {@link JDA} or {@link ShardManager}, this may return null immediately after building, because the cache isn't initialized yet.
* To make sure the cache is initialized after building your {@link JDA} instance, you can use {@link JDA#awaitReady()}.
*
* @param name
* The name used to filter the returned {@link MediaChannel MediaChannels}.
* @param ignoreCase
* Determines if the comparison ignores case when comparing. True - case insensitive.
*
* @return Possibly-empty immutable list of all ForumChannel names that match the provided name.
*/
@Nonnull
default List<MediaChannel> getMediaChannelsByName(@Nonnull String name, boolean ignoreCase)
{
return getMediaChannelCache().getElementsByName(name, ignoreCase);
}

/**
* Gets a {@link MediaChannel} that has the same id as the one provided.
* <br>If there is no channel with an id that matches the provided one, then this returns {@code null}.
*
* <p>This getter exists on any instance of {@link IGuildChannelContainer} and only checks the caches with the relevant scoping.
* For {@link Guild}, {@link JDA}, or {@link ShardManager},
* this returns the relevant channel with respect to the cache within each of those objects.
* For a guild, this would mean it only returns channels within the same guild.
* <br>If this is called on {@link JDA} or {@link ShardManager}, this may return null immediately after building, because the cache isn't initialized yet.
* To make sure the cache is initialized after building your {@link JDA} instance, you can use {@link JDA#awaitReady()}.
*
* @param id
* The id of the {@link MediaChannel}.
*
* @throws java.lang.NumberFormatException
* If the provided {@code id} cannot be parsed by {@link Long#parseLong(String)}
*
* @return Possibly-null {@link MediaChannel} with matching id.
*/
@Nullable
default MediaChannel getMediaChannelById(@Nonnull String id)
{
return getMediaChannelCache().getElementById(id);
}

/**
* Gets a {@link MediaChannel} that has the same id as the one provided.
* <br>If there is no channel with an id that matches the provided one, then this returns {@code null}.
*
* <p>This getter exists on any instance of {@link IGuildChannelContainer} and only checks the caches with the relevant scoping.
* For {@link Guild}, {@link JDA}, or {@link ShardManager},
* this returns the relevant channel with respect to the cache within each of those objects.
* For a guild, this would mean it only returns channels within the same guild.
* <br>If this is called on {@link JDA} or {@link ShardManager}, this may return null immediately after building, because the cache isn't initialized yet.
* To make sure the cache is initialized after building your {@link JDA} instance, you can use {@link JDA#awaitReady()}.
*
* @param id
* The id of the {@link MediaChannel}.
*
* @return Possibly-null {@link MediaChannel} with matching id.
*/
@Nullable
default MediaChannel getMediaChannelById(long id)
{
return getMediaChannelCache().getElementById(id);
}

/**
* Gets all {@link MediaChannel} in the cache.
*
* <p>This copies the backing store into a list. This means every call
* creates a new list with O(n) complexity. It is recommended to store this into
* a local variable or use {@link #getForumChannelCache()} and use its more efficient
* versions of handling these values.
*
* <p>This getter exists on any instance of {@link IGuildChannelContainer} and only checks the caches with the relevant scoping.
* For {@link Guild}, {@link JDA}, or {@link ShardManager},
* this returns the relevant channel with respect to the cache within each of those objects.
* For a guild, this would mean it only returns channels within the same guild.
* <br>If this is called on {@link JDA} or {@link ShardManager}, this may return null immediately after building, because the cache isn't initialized yet.
* To make sure the cache is initialized after building your {@link JDA} instance, you can use {@link JDA#awaitReady()}.
*
* @return An immutable List of {@link MediaChannel}.
*/
@Nonnull
default List<MediaChannel> getMediaChannels()
{
return getMediaChannelCache().asList();
}
}
Loading
Loading