Skip to content

Commit

Permalink
Add support for forum channels (#2184)
Browse files Browse the repository at this point in the history
* Add ForumChannel#createForumPost
* Add new message count logic
* Reduce code duplication in createXChannel
* Add Category#createNewsChannel
* Add missing docs for IThreadContainer
* Improve handling of thread parents
* Update docs for ThreadChannel
* Add ForumPostAction
* Update docs for archives and add some more missing docs
* Handle default thread slowmode
* Support changing channel flags
* Use FluentRestAction interface
* Add FluentAuditableRestAction
  • Loading branch information
MinnDevelopment authored Sep 20, 2022
1 parent 567693e commit f7ac0e7
Show file tree
Hide file tree
Showing 86 changed files with 4,700 additions and 562 deletions.
61 changes: 58 additions & 3 deletions src/main/java/net/dv8tion/jda/api/audit/AuditLogKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@

package net.dv8tion.jda.api.audit;

import net.dv8tion.jda.annotations.DeprecatedSince;
import net.dv8tion.jda.annotations.ForRemoval;
import net.dv8tion.jda.annotations.ReplaceWith;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.channel.Channel;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.attribute.ICategorizableChannel;
import net.dv8tion.jda.api.entities.channel.attribute.ISlowmodeChannel;
import net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer;
import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel;
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;
Expand Down Expand Up @@ -207,6 +214,13 @@ public enum AuditLogKey
*/
CHANNEL_NAME("name"),

/**
* Change of the {@link Channel#getFlags() flags} value.
*
* <p>Expected type: <b>Integer</b>
*/
CHANNEL_FLAGS("flags"),

/**
* Change of the {@link ICategorizableChannel#getParentCategory()} ICategorizable.getParentCategory()} value.
* <br>Use with {@link net.dv8tion.jda.api.entities.Guild#getCategoryById(String) Guild.getCategoryById(String)}
Expand All @@ -224,13 +238,26 @@ public enum AuditLogKey
CHANNEL_TOPIC("topic"),

/**
* Change of the {@link TextChannel#getSlowmode() TextChannel.getSlowmode()} value.
* <br>Only for {@link ChannelType#TEXT ChannelType.TEXT}
* Change of the {@link ISlowmodeChannel#getSlowmode()} value.
*
* <p>Expected type: <b>Integer</b>
*/
CHANNEL_SLOWMODE("rate_limit_per_user"),

/**
* Change of the {@link IThreadContainer#getDefaultThreadSlowmode()} value.
*
* <p>Expected type: <b>Integer</b>
*/
CHANNEL_DEFAULT_THREAD_SLOWMODE("default_thread_rate_limit_per_user"),

/**
* Change of the {@link ForumChannel#getDefaultReaction()} value.
*
* <p>Expected type: <b>Map</b> containing {@code emoji_id} and {@code emoji_name}
*/
CHANNEL_DEFAULT_REACTION_EMOJI("default_reaction_emoji"),

/**
* Change of the {@link VoiceChannel#getBitrate() VoiceChannel.getBitrate()} value.
* <br>Only for {@link ChannelType#VOICE ChannelType.VOICE}
Expand Down Expand Up @@ -277,6 +304,21 @@ public enum AuditLogKey
*/
CHANNEL_OVERRIDES("permission_overwrites"),

/**
* The available tags of this {@link net.dv8tion.jda.api.entities.channel.concrete.ForumChannel ForumChannel}.
*
* <p>Expected type: <b>List{@literal <Map<String, Object>>}</b>
*/
CHANNEL_AVAILABLE_TAGS("available_tags"),

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

// THREADS

/**
Expand All @@ -287,10 +329,16 @@ public enum AuditLogKey
THREAD_NAME("name"),

/**
* Change of the {@link ThreadChannel#getSlowmode() ThreadChannel.getSlowmode()} value.
* Change of the {@link ISlowmodeChannel#getSlowmode()} value.
*
* <p>Expected type: <b>Integer</b>
*
* @deprecated Use {@link #CHANNEL_SLOWMODE} instead
*/
@Deprecated
@ForRemoval
@DeprecatedSince("5.0.0")
@ReplaceWith("CHANNEL_SLOWMODE")
THREAD_SLOWMODE("rate_limit_per_user"),

/**
Expand Down Expand Up @@ -322,6 +370,13 @@ public enum AuditLogKey
*/
THREAD_INVITABLE("invitable"),

/**
* The applied tags of this {@link ThreadChannel}, given that it is a forum post.
*
* <p>Expected type: <b>List{@literal <String>}</b>
*/
THREAD_APPLIED_TAGS("applied_tags"),

// STAGE_INSTANCE

/**
Expand Down
133 changes: 99 additions & 34 deletions src/main/java/net/dv8tion/jda/api/entities/Guild.java

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/channel/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import java.util.EnumSet;
import java.util.FormattableFlags;
import java.util.Formatter;

Expand All @@ -31,6 +32,23 @@
*/
public interface Channel extends IMentionable
{
/**
* The maximum length a channel name can be. ({@value #MAX_NAME_LENGTH})
*/
int MAX_NAME_LENGTH = 100;

/**
* The flags configured for this channel.
* <br>This feature is currently primarily used for {@link net.dv8tion.jda.api.entities.channel.concrete.ForumChannel ForumChannels}.
*
* @return {@link EnumSet} of the configured {@link ChannelFlag ChannelFlags}, changes to this enum set are not reflected in the API.
*/
@Nonnull
default EnumSet<ChannelFlag> getFlags()
{
return EnumSet.noneOf(ChannelFlag.class);
}

/**
* The human readable name of this channel.
*
Expand Down Expand Up @@ -71,6 +89,7 @@ public interface Channel extends IMentionable
@CheckReturnValue
RestAction<Void> delete();

@Nonnull
@Override
default String getAsMention()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import net.dv8tion.jda.api.audit.AuditLogKey;
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.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.StandardGuildMessageChannel;
Expand Down Expand Up @@ -56,10 +59,17 @@ public enum ChannelField
*/
NAME("name", AuditLogKey.CHANNEL_NAME),

/**
* The flags of the channel.
*
* @see Channel#getFlags()
*/
FLAGS("flags", AuditLogKey.CHANNEL_FLAGS),

/**
* The {@link Category parent} of the channel.
*
* Limited to {@link net.dv8tion.jda.api.entities.channel.attribute.ICategorizableChannel Categorizable Channels} (and implementations).
* <p>Limited to {@link net.dv8tion.jda.api.entities.channel.attribute.ICategorizableChannel Categorizable Channels} (and implementations).
*
* @see net.dv8tion.jda.api.entities.channel.attribute.ICategorizableChannel#getParentCategory()
*/
Expand All @@ -74,13 +84,26 @@ public enum ChannelField
*/
POSITION("position", null), //Discord doesn't track Channel position changes in AuditLog.

/**
* The default slowmode applied to threads in a {@link net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer ThreadContainer}.
*
* @see IThreadContainer#getDefaultThreadSlowmode()
*/
DEFAULT_THREAD_SLOWMODE("default_thread_slowmode", AuditLogKey.CHANNEL_DEFAULT_THREAD_SLOWMODE),

/**
* The default reaction emoji used in a {@link ForumChannel}.
*
* @see ForumChannel#getDefaultReaction()
*/
DEFAULT_REACTION_EMOJI("default_reaction_emoji", AuditLogKey.CHANNEL_DEFAULT_REACTION_EMOJI),

//Text Specific

/**
* The topic of the channel.
*
* Limited to {@link NewsChannel NewsChannels} and {@link TextChannel TextChannels}.
* <p>Limited to {@link NewsChannel NewsChannels} and {@link TextChannel TextChannels}.
*
* @see StandardGuildMessageChannel#getTopic()
*/
Expand All @@ -89,34 +112,42 @@ public enum ChannelField
/**
* The NSFW state of the channel.
*
* Limited to {@link StandardGuildMessageChannel StandardGuildMessageChannels} (and implementations).
* <p>Limited to {@link IAgeRestrictedChannel IAgeRestrictedChannels} (and implementations).
*
* @see StandardGuildMessageChannel#isNSFW()
* @see IAgeRestrictedChannel#isNSFW()
*/
NSFW("nsfw", AuditLogKey.CHANNEL_NSFW),

/**
* The state of slow mode in the channel. This defines the minimum time between message sends.
* The state of slow mode in the channel.
* <br>This defines the minimum time between message sends.
*
* Limited to {@link TextChannel Text Channels}.
* <p>Limited to {@link ISlowmodeChannel ISlowmodeChannels} (and implementations).
*
* @see TextChannel#getSlowmode()
* @see ISlowmodeChannel#getSlowmode()
*/
SLOWMODE("slowmode", AuditLogKey.CHANNEL_SLOWMODE),

/**
* The applied tags of a {@link ForumChannel}.
*
* @see ForumChannel#getAvailableTags()
*/
AVAILABLE_TAGS("available_tags", AuditLogKey.CHANNEL_AVAILABLE_TAGS),


//Voice Specific

/**
* The bitrate (in bits per second) of the audio in this channel.
*
* For standard channels this is between 8000 and 96000.
* <p>For standard channels this is between 8000 and 96000.
*
* VIP servers extend this limit to 128000.
* <p>VIP servers extend this limit to 128000.
* <br>
* The bitrates of boost tiers may be found in {@link Guild.BoostTier the boost tiers}.
*
* Limited to {@link AudioChannel Audio Channels}.
* <p>Limited to {@link AudioChannel Audio Channels}.
*
* @see AudioChannel#getBitrate()
*/
Expand All @@ -125,7 +156,7 @@ public enum ChannelField
/**
* The region of the channel.
*
* Limited to {@link AudioChannel Audio Channels}.
* <p>Limited to {@link AudioChannel Audio Channels}.
*
* @see AudioChannel#getRegion()
* @see net.dv8tion.jda.api.Region
Expand All @@ -135,7 +166,7 @@ public enum ChannelField
/**
* The maximum user count of this channel.
*
* Limited to {@link VoiceChannel Voice Channels}.
* <p>Limited to {@link VoiceChannel Voice Channels}.
*
* @see VoiceChannel#getUserLimit()
*/
Expand All @@ -147,9 +178,9 @@ public enum ChannelField
/**
* The auto archive duration of this channel.
*
* If the thread is inactive for this long, it becomes auto-archived.
* <p>If the thread is inactive for this long, it becomes auto-archived.
*
* Limited to {@link ThreadChannel Thread Channels}.
* <p>Limited to {@link ThreadChannel Thread Channels}.
*
* @see ThreadChannel#getAutoArchiveDuration()
* @see ThreadChannel.AutoArchiveDuration
Expand All @@ -159,9 +190,9 @@ public enum ChannelField
/**
* The archive state of this channel.
*
* If the channel is archived, this is true.
* <p>If the channel is archived, this is true.
*
* Limited to {@link ThreadChannel Thread Channels}.
* <p>Limited to {@link ThreadChannel Thread Channels}.
*
* @see ThreadChannel#isArchived()
*/
Expand All @@ -170,7 +201,7 @@ public enum ChannelField
/**
* The time this channel's archival information was last updated.
*
* This timestamp will be updated when any of the following happen:
* <p>This timestamp will be updated when any of the following happen:
* <ul>
* <li>The channel is archived</li>
* <li>The channel is unarchived</li>
Expand All @@ -179,17 +210,16 @@ public enum ChannelField
*
* Limited to {@link ThreadChannel Thread Channels}.
*
*
* @see ThreadChannel#getTimeArchiveInfoLastModified()
*/
ARCHIVED_TIMESTAMP("archiveTimestamp", null),

/**
* The locked state of this channel.
*
* If the channel is locked, this is true.
* <p>If the channel is locked, this is true.
*
* Limited to {@link ThreadChannel Thread Channels}.
* <p>Limited to {@link ThreadChannel Thread Channels}.
*
* @see ThreadChannel#isLocked()
*/
Expand All @@ -198,14 +228,31 @@ public enum ChannelField
/**
* The invite state of this channel.
*
* If the channel is invitable, this is true.
* <p>If the channel is invitable, this is true.
*
* Limited to {@link ThreadChannel Thread Channels}.
* <p>Limited to {@link ThreadChannel Thread Channels}.
*
* @see ThreadChannel#isInvitable()
*/
INVITABLE("invitable", AuditLogKey.THREAD_INVITABLE)
;
INVITABLE("invitable", AuditLogKey.THREAD_INVITABLE),

/**
* The tags applied to a forum post thread.
*
* <p>Limited to {@link ThreadChannel ThreadChannels} inside {@link ForumChannel ForumChannels}
*
* @see ThreadChannel#getAppliedTags()
*/
APPLIED_TAGS("applied_tags", AuditLogKey.THREAD_APPLIED_TAGS),

/**
* 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);

private final String fieldName;
private final AuditLogKey auditLogKey;
Expand All @@ -228,6 +275,8 @@ public AuditLogKey getAuditLogKey()
return auditLogKey;
}

@Nonnull
@Override
public String toString()
{
return "ChannelField." + name() + '(' + fieldName + ')';
Expand Down
Loading

0 comments on commit f7ac0e7

Please sign in to comment.