Skip to content

Commit

Permalink
Merge branch 'master' into feature/cache-flag-from-events
Browse files Browse the repository at this point in the history
  • Loading branch information
freya022 committed Jan 21, 2024
2 parents 4058741 + 472cf52 commit 9cdfe6f
Show file tree
Hide file tree
Showing 77 changed files with 2,879 additions and 947 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
with:
arguments: build
- name: Upload Artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: build/libs/*.jar
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
with:
arguments: javadoc
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
uses: actions/upload-pages-artifact@v3
with:
path: './build/docs/javadoc'
- name: Deploy to GitHub Pages
Expand Down
12 changes: 6 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ plugins {
}

val javaVersion = JavaVersion.current()
val versionObj = Version(major = "5", minor = "0", revision = "0", classifier = "beta.17")
val versionObj = Version(major = "5", minor = "0", revision = "0", classifier = "beta.20")
val isCI = System.getProperty("BUILD_NUMBER") != null // jenkins
|| System.getenv("BUILD_NUMBER") != null
|| System.getProperty("GIT_COMMIT") != null // jitpack
Expand Down Expand Up @@ -105,7 +105,7 @@ dependencies {

//Web Connection Support
api("com.neovisionaries:nv-websocket-client:2.14")
api("com.squareup.okhttp3:okhttp:4.10.0")
api("com.squareup.okhttp3:okhttp:4.12.0")

//Opus library support
api("club.minnced:opus-java:1.1.1")
Expand All @@ -122,9 +122,8 @@ dependencies {

//General Utility
implementation("net.sf.trove4j:trove4j:3.0.3")
// Match the minor version of lavaplayers jackson dependency
implementation("com.fasterxml.jackson.core:jackson-core:2.14.1")
implementation("com.fasterxml.jackson.core:jackson-databind:2.14.1")
implementation("com.fasterxml.jackson.core:jackson-core:2.16.0")
implementation("com.fasterxml.jackson.core:jackson-databind:2.16.0")

//Sets the dependencies for the examples
configurations["examplesImplementation"].withDependencies {
Expand All @@ -133,8 +132,9 @@ dependencies {
addAll(configurations["compileOnly"].allDependencies)
}

testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
testImplementation("org.junit.jupiter:junit-jupiter:5.10.1")
testImplementation("org.reflections:reflections:0.10.2")
testImplementation("org.mockito:mockito-core:5.8.0")
}

val compileJava: JavaCompile by tasks
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/net/dv8tion/jda/api/EmbedBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,15 @@ public static EmbedBuilder fromData(@Nonnull DataObject data)
* that has been checked as being valid for sending.
*
* @throws java.lang.IllegalStateException
* If the embed is empty. Can be checked with {@link #isEmpty()}.
* <ul>
* <li>If the embed is empty. Can be checked with {@link #isEmpty()}.</li>
* <li>If the character limit for {@code description}, defined by {@link net.dv8tion.jda.api.entities.MessageEmbed#DESCRIPTION_MAX_LENGTH} as {@value net.dv8tion.jda.api.entities.MessageEmbed#DESCRIPTION_MAX_LENGTH},
* is exceeded.</li>
* <li>If the embed's total length, defined by {@link net.dv8tion.jda.api.entities.MessageEmbed#EMBED_MAX_LENGTH_BOT} as {@value net.dv8tion.jda.api.entities.MessageEmbed#EMBED_MAX_LENGTH_BOT},
* is exceeded.</li>
* <li>If the embed's number of embed fields, defined by {@link net.dv8tion.jda.api.entities.MessageEmbed#MAX_FIELD_AMOUNT} as {@value net.dv8tion.jda.api.entities.MessageEmbed#MAX_FIELD_AMOUNT},
* is exceeded.</li>
* </ul>
*
* @return the built, sendable {@link net.dv8tion.jda.api.entities.MessageEmbed}
*/
Expand All @@ -167,7 +175,9 @@ public MessageEmbed build()
if (description.length() > MessageEmbed.DESCRIPTION_MAX_LENGTH)
throw new IllegalStateException(Helpers.format("Description is longer than %d! Please limit your input!", MessageEmbed.DESCRIPTION_MAX_LENGTH));
if (length() > MessageEmbed.EMBED_MAX_LENGTH_BOT)
throw new IllegalStateException("Cannot build an embed with more than " + MessageEmbed.EMBED_MAX_LENGTH_BOT + " characters!");
throw new IllegalStateException(Helpers.format("Cannot build an embed with more than %d characters!", MessageEmbed.EMBED_MAX_LENGTH_BOT));
if (fields.size() > MessageEmbed.MAX_FIELD_AMOUNT)
throw new IllegalStateException(Helpers.format("Cannot build an embed with more than %d embed fields set!", MessageEmbed.MAX_FIELD_AMOUNT));
final String description = this.description.length() < 1 ? null : this.description.toString();

return EntityBuilder.createMessageEmbed(url, title, description, EmbedType.RICH, timestamp,
Expand Down
13 changes: 1 addition & 12 deletions src/main/java/net/dv8tion/jda/api/JDA.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
*
* @see JDABuilder
*/
public interface JDA extends IGuildChannelContainer
public interface JDA extends IGuildChannelContainer<Channel>
{
/**
* Represents the connection status of JDA and its Main WebSocket.
Expand Down Expand Up @@ -1478,17 +1478,6 @@ default List<ScheduledEvent> getScheduledEventsByName(@Nonnull String name, bool
return getScheduledEventCache().getElementsByName(name, ignoreCase);
}

@Nullable
@Override
default <T extends Channel> T getChannelById(@Nonnull Class<T> type, long id)
{
Checks.notNull(type, "Class");
Channel channel = getPrivateChannelById(id);
if (channel != null)
return type.isInstance(channel) ? type.cast(channel) : null;
return IGuildChannelContainer.super.getChannelById(type, id);
}

/**
* {@link net.dv8tion.jda.api.utils.cache.SnowflakeCacheView SnowflakeCacheView} of
* all cached {@link PrivateChannel PrivateChannels} visible to this JDA session.
Expand Down
119 changes: 114 additions & 5 deletions src/main/java/net/dv8tion/jda/api/JDABuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ public class JDABuilder
protected final List<Object> listeners = new LinkedList<>();
protected final EnumSet<CacheFlag> automaticallyDisabled = EnumSet.noneOf(CacheFlag.class);

protected ScheduledExecutorService rateLimitPool = null;
protected boolean shutdownRateLimitPool = true;
protected ScheduledExecutorService rateLimitScheduler = null;
protected boolean shutdownRateLimitScheduler = true;
protected ExecutorService rateLimitElastic = null;
protected boolean shutdownRateLimitElastic = true;
protected ScheduledExecutorService mainWsPool = null;
protected boolean shutdownMainWsPool = true;
protected ExecutorService callbackPool = null;
Expand Down Expand Up @@ -913,8 +915,13 @@ public JDABuilder setWebsocketFactory(@Nullable WebSocketFactory factory)
* The thread-pool to use for rate-limit handling
*
* @return The JDABuilder instance. Useful for chaining.
*
* @deprecated This pool is now split into two pools.
* You should use {@link #setRateLimitScheduler(ScheduledExecutorService)} and {@link #setRateLimitElastic(ExecutorService)} instead.
*/
@Nonnull
@Deprecated
@ReplaceWith("setRateLimitScheduler(pool)")
public JDABuilder setRateLimitPool(@Nullable ScheduledExecutorService pool)
{
return setRateLimitPool(pool, pool == null);
Expand All @@ -937,12 +944,113 @@ public JDABuilder setRateLimitPool(@Nullable ScheduledExecutorService pool)
* Whether {@link JDA#shutdown()} should shutdown this pool
*
* @return The JDABuilder instance. Useful for chaining.
*
* @deprecated This pool is now split into two pools.
* You should use {@link #setRateLimitScheduler(ScheduledExecutorService, boolean)} and {@link #setRateLimitElastic(ExecutorService, boolean)} instead.
*/
@Nonnull
@Deprecated
@ReplaceWith("setRateLimitScheduler(pool, automaticShutdown)")
public JDABuilder setRateLimitPool(@Nullable ScheduledExecutorService pool, boolean automaticShutdown)
{
this.rateLimitPool = pool;
this.shutdownRateLimitPool = automaticShutdown;
this.rateLimitScheduler = pool;
this.shutdownRateLimitScheduler = automaticShutdown;
return this;
}

/**
* Sets the {@link ScheduledExecutorService ScheduledExecutorService} that should be used in
* the JDA rate-limit handler. Changing this can drastically change the JDA behavior for RestAction execution
* and should be handled carefully. <b>Only change this pool if you know what you're doing.</b>
* <br><b>This automatically disables the automatic shutdown of the rate-limit pool, you can enable
* it using {@link #setRateLimitPool(ScheduledExecutorService, boolean) setRateLimitPool(executor, true)}</b>
*
* <p>This is used mostly by the Rate-Limiter to handle backoff delays by using scheduled executions.
* Besides that it is also used by planned execution for {@link net.dv8tion.jda.api.requests.RestAction#queueAfter(long, TimeUnit)}
* and similar methods. Requests are handed off to the {@link #setRateLimitElastic(ExecutorService) elastic pool} for blocking execution.
*
* <p>Default: {@link ScheduledThreadPoolExecutor} with 2 threads.
*
* @param pool
* The thread-pool to use for rate-limit handling
*
* @return The JDABuilder instance. Useful for chaining.
*/
@Nonnull
public JDABuilder setRateLimitScheduler(@Nullable ScheduledExecutorService pool)
{
return setRateLimitScheduler(pool, pool == null);
}

/**
* Sets the {@link ScheduledExecutorService ScheduledExecutorService} that should be used in
* the JDA rate-limit handler. Changing this can drastically change the JDA behavior for RestAction execution
* and should be handled carefully. <b>Only change this pool if you know what you're doing.</b>
*
* <p>This is used mostly by the Rate-Limiter to handle backoff delays by using scheduled executions.
* Besides that it is also used by planned execution for {@link net.dv8tion.jda.api.requests.RestAction#queueAfter(long, TimeUnit)}
* and similar methods. Requests are handed off to the {@link #setRateLimitElastic(ExecutorService) elastic pool} for blocking execution.
*
* <p>Default: {@link ScheduledThreadPoolExecutor} with 2 threads.
*
* @param pool
* The thread-pool to use for rate-limit handling
* @param automaticShutdown
* Whether {@link JDA#shutdown()} should shutdown this pool
*
* @return The JDABuilder instance. Useful for chaining.
*/
@Nonnull
public JDABuilder setRateLimitScheduler(@Nullable ScheduledExecutorService pool, boolean automaticShutdown)
{
this.rateLimitScheduler = pool;
this.shutdownRateLimitScheduler = automaticShutdown;
return this;
}

/**
* Sets the {@link ExecutorService ExecutorService} that should be used in
* the JDA request handler. Changing this can drastically change the JDA behavior for RestAction execution
* and should be handled carefully. <b>Only change this pool if you know what you're doing.</b>
* <br><b>This automatically disables the automatic shutdown of the rate-limit elastic pool, you can enable
* it using {@link #setRateLimitElastic(ExecutorService, boolean) setRateLimitElastic(executor, true)}</b>
*
* <p>This is used mostly by the Rate-Limiter to execute the blocking HTTP requests at runtime.
*
* <p>Default: {@link Executors#newCachedThreadPool()}.
*
* @param pool
* The thread-pool to use for executing http requests
*
* @return The JDABuilder instance. Useful for chaining.
*/
@Nonnull
public JDABuilder setRateLimitElastic(@Nullable ExecutorService pool)
{
return setRateLimitElastic(pool, pool == null);
}

/**
* Sets the {@link ExecutorService ExecutorService} that should be used in
* the JDA request handler. Changing this can drastically change the JDA behavior for RestAction execution
* and should be handled carefully. <b>Only change this pool if you know what you're doing.</b>
*
* <p>This is used mostly by the Rate-Limiter to execute the blocking HTTP requests at runtime.
*
* <p>Default: {@link Executors#newCachedThreadPool()}.
*
* @param pool
* The thread-pool to use for executing http requests
* @param automaticShutdown
* Whether {@link JDA#shutdown()} should shutdown this pool
*
* @return The JDABuilder instance. Useful for chaining.
*/
@Nonnull
public JDABuilder setRateLimitElastic(@Nullable ExecutorService pool, boolean automaticShutdown)
{
this.rateLimitElastic = pool;
this.shutdownRateLimitElastic = automaticShutdown;
return this;
}

Expand Down Expand Up @@ -1797,7 +1905,8 @@ public JDA build()
ThreadingConfig threadingConfig = new ThreadingConfig();
threadingConfig.setCallbackPool(callbackPool, shutdownCallbackPool);
threadingConfig.setGatewayPool(mainWsPool, shutdownMainWsPool);
threadingConfig.setRateLimitPool(rateLimitPool, shutdownRateLimitPool);
threadingConfig.setRateLimitScheduler(rateLimitScheduler, shutdownRateLimitScheduler);
threadingConfig.setRateLimitElastic(rateLimitElastic, shutdownRateLimitElastic);
threadingConfig.setEventPool(eventPool, shutdownEventPool);
threadingConfig.setAudioPool(audioPool, shutdownAudioPool);
SessionConfig sessionConfig = new SessionConfig(controller, httpClient, wsFactory, voiceDispatchInterceptor, flags, maxReconnectDelay, largeThreshold);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/dv8tion/jda/api/Permission.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public enum Permission
VOICE_START_ACTIVITIES( 39, true, true, "Use Activities"),
VOICE_USE_SOUNDBOARD( 42, true, true, "Use Soundboard"),
VOICE_USE_EXTERNAL_SOUNDS(45, true, true, "Use External Sounds"),
VOICE_SET_STATUS( 48, true, true, "Set Voice Channel Status"),

// Stage Channel Permissions
REQUEST_TO_SPEAK( 32, true, true, "Request to Speak"),
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/net/dv8tion/jda/api/audit/ActionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.ScheduledEvent;
import net.dv8tion.jda.api.entities.channel.attribute.IVoiceStatusChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;

Expand Down Expand Up @@ -635,6 +636,27 @@ public enum ActionType
*/
AUTO_MODERATION_MEMBER_TIMEOUT( 145, TargetType.MEMBER),

/**
* A user updated the {@link IVoiceStatusChannel#getStatus() status} of a voice channel.
*
* <p><b>Possible Keys</b><br>
* <ul>
* <li>{@link AuditLogKey#CHANNEL_VOICE_STATUS CHANNEL_VOICE_STATUS}</li>
* <li>{@link AuditLogKey#CHANNEL_ID CHANNEL_ID}</li>
* </ul>
*/
VOICE_CHANNEL_STATUS_UPDATE(192, TargetType.CHANNEL),

/**
* A user removed the {@link IVoiceStatusChannel#getStatus() status} of a voice channel.
*
* <p><b>Possible Keys</b><br>
* <ul>
* <li>{@link AuditLogKey#CHANNEL_ID CHANNEL_ID}</li>
* </ul>
*/
VOICE_CHANNEL_STATUS_DELETE(193, TargetType.CHANNEL),

UNKNOWN(-1, TargetType.UNKNOWN);

private final int key;
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/net/dv8tion/jda/api/audit/AuditLogKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ public enum AuditLogKey
*/
CHANNEL_TOPIC("topic"),

/**
* Change of the {@link VoiceChannel#getStatus() VoiceChannel.getStatus()} value.
* <br>Only for {@link ChannelType#VOICE ChannelType.VOICE}
*
* <p>Expected type: <b>String</b>
*/
CHANNEL_VOICE_STATUS("status"),

/**
* Change of the {@link ISlowmodeChannel#getSlowmode()} value.
*
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/ApplicationInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,39 @@ default String getInviteUrl(long guildId, @Nullable Permission... permissions)
@Nonnull
List<String> getTags();

/**
* A {@link java.util.List} containing the OAuth2 redirect URIs of this bot's application.
*
* <p>This List is empty if no redirect URIs are set in the <a href="https://discord.com/developers/applications" target="_blank">Developer Portal</a>.
*
* @return Immutable list containing the OAuth2 redirect URIs of this bot's application
*/
@Nonnull
List<String> getRedirectUris();

/**
* The interaction endpoint URL of this bot's application.
*
* <p>This returns {@code null} if no interaction endpoint URL is set in the <a href="https://discord.com/developers/applications" target="_blank">Developer Portal</a>.
*
* <p>A non-null value means your bot will no longer receive {@link net.dv8tion.jda.api.interactions.Interaction interactions}
* through JDA, such as slash commands, components and modals.
*
* @return Interaction endpoint URL of this bot's application, or {@code null} if it has not been set
*/
@Nullable
String getInteractionsEndpointUrl();

/**
* The role connections (linked roles) verification URL of this bot's application.
*
* <p>This returns {@code null} if no role connection verification URL is set in the <a href="https://discord.com/developers/applications" target="_blank">Developer Portal</a>.
*
* @return Role connections verification URL of this bot's application, or {@code null} if it has not been set
*/
@Nullable
String getRoleConnectionsVerificationUrl();

/**
* The custom Authorization URL of this bot's application.
*
Expand Down
Loading

0 comments on commit 9cdfe6f

Please sign in to comment.