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 support for forum channels #2184

Merged
merged 79 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
b9065ee
Add initial support for forum channels
MinnDevelopment Jul 19, 2022
5644266
Fix some copy-paste issues
MinnDevelopment Jul 19, 2022
0cabd2d
Update union type list
MinnDevelopment Jul 19, 2022
a97bc91
Add ForumChannel#createForumPost
MinnDevelopment Jul 19, 2022
d3d3719
Implement ForumChannelManagerImpl
MinnDevelopment Jul 20, 2022
eb78683
Merge remote-tracking branch 'origin/master' into feature/forums
MinnDevelopment Jul 20, 2022
8765433
Improve checks in ChannelActionImpl
MinnDevelopment Jul 20, 2022
fd4d312
Remove tags
MinnDevelopment Jul 20, 2022
45ae0ca
Add throws docs for other overload
MinnDevelopment Jul 20, 2022
581f56f
Add docs for permission checks
MinnDevelopment Jul 20, 2022
48ba485
Add new message count logic
MinnDevelopment Jul 26, 2022
26d4428
Fix typo
MinnDevelopment Jul 26, 2022
9768352
Add forums to Guild#getChannels
MinnDevelopment Jul 31, 2022
9418b61
Add Category#getForumChannels
MinnDevelopment Jul 31, 2022
9aaf5f7
Clear forum channel cache on invalidate
MinnDevelopment Jul 31, 2022
a30040e
Reduce code duplication in createXChannel
MinnDevelopment Jul 31, 2022
3919196
Improve some documentation
MinnDevelopment Jul 31, 2022
628e2f7
Add Category#createNewsChannel
MinnDevelopment Jul 31, 2022
b4739f6
Add missing docs for IThreadContainer
MinnDevelopment Jul 31, 2022
cb4ed95
Improve handling of thread parents
MinnDevelopment Aug 8, 2022
0f37bff
Update docs for ThreadChannel
MinnDevelopment Aug 8, 2022
bc34c48
Update more docs of thread channel
MinnDevelopment Aug 8, 2022
3d2f7e9
Make getForumChannelCache return the cache instead of null
MinnDevelopment Aug 8, 2022
e25b4e2
Merge remote-tracking branch 'origin/master' into feature/forums
MinnDevelopment Aug 16, 2022
a689e3e
Add ForumPostAction
MinnDevelopment Aug 16, 2022
32cfbd6
Update some docs
MinnDevelopment Aug 16, 2022
11517ad
Update src/main/java/net/dv8tion/jda/api/entities/Guild.java
MinnDevelopment Aug 16, 2022
8770569
Fix javadoc errors
MinnDevelopment Aug 16, 2022
346c3a4
Add missing break
MinnDevelopment Aug 30, 2022
6b28ff9
Add another missing break
MinnDevelopment Aug 30, 2022
d7ebf59
Add missing docs
MinnDevelopment Aug 30, 2022
3940806
Update docs for archives and add some more missing docs
MinnDevelopment Aug 30, 2022
6e4d5f1
Add handling for forum topic length
MinnDevelopment Aug 30, 2022
a336739
Add basic support for applying tags
MinnDevelopment Aug 30, 2022
bed9213
Add check for max tags
MinnDevelopment Aug 30, 2022
f8c44fb
Merge remote-tracking branch 'origin/master' into feature/forums
MinnDevelopment Aug 30, 2022
c86264e
Add support for applied tags on threads
MinnDevelopment Aug 30, 2022
f3fbf18
Add handling for tag updates
MinnDevelopment Aug 30, 2022
9160ed7
Add cache flag for forum tags
MinnDevelopment Aug 31, 2022
a1d3c46
Handle default thread slowmode
MinnDevelopment Sep 1, 2022
dfccd62
Handle channel flags for forums
MinnDevelopment Sep 1, 2022
ae85f75
Handle thread flags
MinnDevelopment Sep 1, 2022
d5a4961
Merge remote-tracking branch 'origin/master' into feature/forums
MinnDevelopment Sep 14, 2022
191acca
Implement tag ordering by position
MinnDevelopment Sep 14, 2022
bca3972
Implement tag emoji and setting available tags on managers
MinnDevelopment Sep 14, 2022
2082c83
Add support to manage available tags
MinnDevelopment Sep 14, 2022
0e1906a
Add webhook support to forums
MinnDevelopment Sep 14, 2022
64162cc
Add convenience getters and support modifying tags
MinnDevelopment Sep 14, 2022
f7ace19
Support changing channel flags
MinnDevelopment Sep 14, 2022
22fbb46
Add support for default reactions
MinnDevelopment Sep 15, 2022
47ac2c1
Add missing docs
MinnDevelopment Sep 15, 2022
935116c
Fix some docs
MinnDevelopment Sep 15, 2022
2f6b4e4
Remove todo and update exception message
MinnDevelopment Sep 15, 2022
854a759
Add missing docs to BaseForumTag
MinnDevelopment Sep 15, 2022
f324cb1
Fix annotation
MinnDevelopment Sep 15, 2022
30edf96
Use FluentRestAction interface
MinnDevelopment Sep 15, 2022
4ea02aa
Make ChannelUpdateAppliedTagsEvent cache independent
MinnDevelopment Sep 15, 2022
35a60c7
Update ChannelManager#setTopic
MinnDevelopment Sep 15, 2022
a3a4ddd
Update exception message for setAppliedTags
MinnDevelopment Sep 15, 2022
31ecfa0
Move checkTypes into Checks class
MinnDevelopment Sep 15, 2022
be4b40c
Rename create thread routes
MinnDevelopment Sep 15, 2022
c2f104b
Update src/main/java/net/dv8tion/jda/api/events/channel/update/Channe…
MinnDevelopment Sep 15, 2022
1f9c577
Update src/main/java/net/dv8tion/jda/internal/handle/MessageDeleteHan…
MinnDevelopment Sep 15, 2022
9c777e4
Add forum tag events
MinnDevelopment Sep 16, 2022
7d09a14
Fix constructors
MinnDevelopment Sep 16, 2022
f8c3cbc
Introduce ISlowmodeChannel attribute interface
MinnDevelopment Sep 17, 2022
af69976
Add varargs version of setAppliedTags
MinnDevelopment Sep 17, 2022
81adfa9
Add FluentAuditableRestAction
MinnDevelopment Sep 17, 2022
bab2947
Rename isRequireTag to isTagRequired
MinnDevelopment Sep 17, 2022
e02dea1
Add more accessors for forum tags
MinnDevelopment Sep 17, 2022
50f23a0
Add event docs
MinnDevelopment Sep 17, 2022
8a90838
Use constants more
MinnDevelopment Sep 17, 2022
0d0fb2b
Update the slowmode supported types and remove outdated todo comment
MinnDevelopment Sep 17, 2022
a22fb78
Add missing setters to ChannelAction
MinnDevelopment Sep 17, 2022
fce8eaa
Add docs for ISlowmodeChannelManager
MinnDevelopment Sep 19, 2022
9951047
Mention CacheFlag in getAvailableTagCache
MinnDevelopment Sep 19, 2022
f7c97f9
Add type checks to ChannelAction
MinnDevelopment Sep 19, 2022
0aa796b
Add default sort oder
MinnDevelopment Sep 19, 2022
051ee54
Missed event
MinnDevelopment Sep 19, 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
141 changes: 119 additions & 22 deletions src/main/java/net/dv8tion/jda/api/entities/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package net.dv8tion.jda.api.entities;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel;
import net.dv8tion.jda.api.managers.channel.concrete.CategoryManager;
import net.dv8tion.jda.api.requests.restaction.ChannelAction;
import net.dv8tion.jda.api.requests.restaction.order.CategoryOrderAction;
Expand Down Expand Up @@ -49,10 +50,8 @@
public interface Category extends GuildChannel, ICopyableChannel, IPositionableChannel, IPermissionContainer, IMemberContainer
{
/**
* All {@link GuildChannel Channels} listed
* for this Category
* <br>This may contain {@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannels},
* and {@link net.dv8tion.jda.api.entities.TextChannel TextChannels}!
* All {@link GuildChannel Channels} listed for this Category.
* <br>Includes all types of channels, except for threads.
*
* @return Immutable list of all child channels
*/
Expand All @@ -64,6 +63,7 @@ default List<GuildChannel> getChannels()
channels.addAll(getVoiceChannels());
channels.addAll(getStageChannels());
channels.addAll(getNewsChannels());
channels.addAll(getForumChannels());
Collections.sort(channels);

return Collections.unmodifiableList(channels);
Expand All @@ -78,9 +78,11 @@ default List<GuildChannel> getChannels()
@Nonnull
default List<TextChannel> getTextChannels()
{
return Collections.unmodifiableList(getGuild().getTextChannelCache().stream()
.filter(channel -> equals(channel.getParentCategory()))
.sorted().collect(Collectors.toList()));
return Collections.unmodifiableList(getGuild().getTextChannelCache().applyStream(stream ->
stream.filter(channel -> equals(channel.getParentCategory()))
.sorted()
.collect(Collectors.toList())
));
}

/**
Expand All @@ -92,9 +94,26 @@ default List<TextChannel> getTextChannels()
@Nonnull
default List<NewsChannel> getNewsChannels()
{
return Collections.unmodifiableList(getGuild().getNewsChannelCache().stream()
.filter(channel -> equals(channel.getParentCategory()))
.sorted().collect(Collectors.toList()));
return Collections.unmodifiableList(getGuild().getNewsChannelCache().applyStream(stream ->
stream.filter(channel -> equals(channel.getParentCategory()))
.sorted()
.collect(Collectors.toList())
));
}

/**
* All {@link net.dv8tion.jda.api.entities.channel.concrete.ForumChannel ForumChannels} listed for this Category
*
* @return Immutable list of all child ForumChannels
*/
@Nonnull
default List<ForumChannel> getForumChannels()
{
return Collections.unmodifiableList(getGuild().getForumChannelCache().applyStream(stream ->
stream.filter(channel -> equals(channel.getParentCategory()))
.sorted()
.collect(Collectors.toList())
));
}

/**
Expand All @@ -106,9 +125,11 @@ default List<NewsChannel> getNewsChannels()
@Nonnull
default List<VoiceChannel> getVoiceChannels()
{
return Collections.unmodifiableList(getGuild().getVoiceChannelCache().stream()
.filter(channel -> equals(channel.getParentCategory()))
.sorted().collect(Collectors.toList()));
return Collections.unmodifiableList(getGuild().getVoiceChannelCache().applyStream(stream ->
stream.filter(channel -> equals(channel.getParentCategory()))
.sorted()
.collect(Collectors.toList())
));
}

/**
Expand All @@ -120,9 +141,11 @@ default List<VoiceChannel> getVoiceChannels()
@Nonnull
default List<StageChannel> getStageChannels()
{
return Collections.unmodifiableList(getGuild().getStageChannelCache().stream()
.filter(channel -> equals(channel.getParentCategory()))
.sorted().collect(Collectors.toList()));
return Collections.unmodifiableList(getGuild().getStageChannelCache().applyStream(stream ->
stream.filter(channel -> equals(channel.getParentCategory()))
.sorted()
.collect(Collectors.toList())
));
}

/**
Expand All @@ -148,12 +171,12 @@ default List<StageChannel> getStageChannels()
* </ul>
*
* @param name
* The name of the TextChannel to create
* The name of the TextChannel 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} or empty or greater than 100 characters in length
* If the provided name is {@code null}, empty, 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 TextChannel before creating it
Expand All @@ -162,6 +185,43 @@ default List<StageChannel> getStageChannels()
@CheckReturnValue
ChannelAction<TextChannel> createTextChannel(@Nonnull String name);

/**
* Creates a new {@link net.dv8tion.jda.api.entities.NewsChannel NewsChannel} with this Category as parent.
* For this to be successful, the logged in account has to have the
* {@link net.dv8tion.jda.api.Permission#MANAGE_CHANNEL MANAGE_CHANNEL} Permission in this Category.
*
* <p>This will copy all {@link net.dv8tion.jda.api.entities.PermissionOverride PermissionOverrides} of this Category!
* Unless the bot is unable to sync it with this category due to permission escalation.
* See {@link IPermissionHolder#canSync(IPermissionContainer, IPermissionContainer)} for details.
*
* <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by
* the returned {@link net.dv8tion.jda.api.requests.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#MISSING_ACCESS MISSING_ACCESS}
* <br>The {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL VIEW_CHANNEL} permission was removed</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 NewsChannel 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}, empty, 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 NewsChannel before creating it
*/
@Nonnull
@CheckReturnValue
ChannelAction<NewsChannel> createNewsChannel(@Nonnull String name);

/**
* Creates a new {@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannel} with this Category as parent.
* For this to be successful, the logged in account has to have the
Expand All @@ -185,12 +245,12 @@ default List<StageChannel> getStageChannels()
* </ul>
*
* @param name
* The name of the VoiceChannel to create
* The name of the VoiceChannel 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} or empty or greater than 100 characters in length
* If the provided name is {@code null}, empty, 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 VoiceChannel before creating it
Expand Down Expand Up @@ -222,12 +282,12 @@ default List<StageChannel> getStageChannels()
* </ul>
*
* @param name
* The name of the StageChannel to create
* The name of the StageChannel 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} or empty or greater than 100 characters in length
* If the provided name is {@code null}, empty, 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 StageChannel before creating it
Expand All @@ -236,6 +296,43 @@ default List<StageChannel> getStageChannels()
@CheckReturnValue
ChannelAction<StageChannel> createStageChannel(@Nonnull String name);

/**
* Creates a new {@link ForumChannel} with this Category as parent.
* For this to be successful, the logged in account has to have the
* {@link net.dv8tion.jda.api.Permission#MANAGE_CHANNEL MANAGE_CHANNEL} Permission in this Category.
*
* <p>This will copy all {@link net.dv8tion.jda.api.entities.PermissionOverride PermissionOverrides} of this Category!
* Unless the bot is unable to sync it with this category due to permission escalation.
* See {@link IPermissionHolder#canSync(IPermissionContainer, IPermissionContainer)} for details.
*
* <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by
* the returned {@link net.dv8tion.jda.api.requests.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#MISSING_ACCESS MISSING_ACCESS}
* <br>The {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL VIEW_CHANNEL} permission was removed</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 ForumChannel 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}, empty, 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 ForumChannel before creating it
*/
@Nonnull
@CheckReturnValue
ChannelAction<ForumChannel> createForumChannel(@Nonnull String name);

/**
* Modifies the positional order of this Category's nested {@link #getTextChannels() TextChannels} and {@link #getNewsChannels() NewsChannels}.
* <br>This uses an extension of {@link ChannelOrderAction ChannelOrderAction}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
*/
public interface Channel extends IMentionable
{
int MAX_NAME_LENGTH = 100;
MinnDevelopment marked this conversation as resolved.
Show resolved Hide resolved

/**
* The human readable name of this channel.
*
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/ChannelType.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public enum ChannelType
GUILD_PUBLIC_THREAD(11, -1, true),
GUILD_PRIVATE_THREAD(12, -1, true),

FORUM(15, 0, true),
MinnDevelopment marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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
Loading