-
-
Notifications
You must be signed in to change notification settings - Fork 734
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 more configurations for JDABuilder #705
Conversation
Also added an option to set the okhttp client used by JDA to allow using a single okhttp client for all JDA sessions Additionally I also fixed the documentation in a few locations
Also ensure the token in DefaultShardManager is only validated once
} | ||
|
||
userResponse = checkToken(login); | ||
requester.shutdownNow(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should call JDA#shutdownNow here
@@ -535,7 +560,7 @@ public DefaultShardManagerBuilder setIdleProvider(final IntFunction<Boolean> idl | |||
* @throws IllegalArgumentException | |||
* if the provided OnlineStatus is null or {@link net.dv8tion.jda.core.OnlineStatus#UNKNOWN UNKNOWN} | |||
* | |||
* @return The {@link net.dv8tion.jda.bot.sharding.DefaultShardManagerBuilder DefaultShardManagerBuilder} instance. Useful for chaining. | |||
* @return @return The DefaultShardManagerBuilder instance. Useful for chaining. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
This comment has been minimized.
This comment has been minimized.
buildAsync -> build() buildBlocking -> build().awaitReady()
Now the methods accepting threadpools additionally accept an optional boolean to enable/disable automatic shutdown Additionally I added generic bounds to the providers (where needed)
Example usage: JDABuilder builder = new JDABuilder(AccountType.BOT).setToken(BOT_TOKEN);
builder.setCorePoolSize(1);
builder.setCallbackPool(new ForkJoinPool(), true);
builder.addEventListener(new CommandHandler());
JDA api = builder.build();
api.awaitStatus(JDA.Status.AWAITING_LOGIN_CONFIRMATION);
log.info("Shard has started setting up"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some renaming / improvements i would make. Nothing major
README.md
Outdated
## Creating the JDA Object | ||
Creating the JDA Object is done via the JDABuilder class by providing an AccountType (Bot/Client). | ||
After setting the token via setter, | ||
the JDA Object is then created by calling the `.buildBlocking()` or the `.buildAsync()` (non-blocking login) method. | ||
the JDA Object is then created by calling the `.build()` (non-blocking login) method. | ||
When `build()` returns JDA might not have finished starting up, however you can use `awaitReady()` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might change punctuation to "When build()
returns**,** JDA might not have finished starting up**.** However**,** ..."
|
||
**Example**: | ||
|
||
```java | ||
JDA jda = new JDABuilder(AccountType.BOT).setToken("token").buildBlocking(); | ||
JDA jda = new JDABuilder(AccountType.BOT).setToken("token").build(); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
README.md
Outdated
@@ -67,7 +79,7 @@ public class MessageListener extends ListenerAdapter | |||
public static void main(String[] args) | |||
throws LoginException, RateLimitedException, InterruptedException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If i understand correctly, build() on its own will not throw an InterruptedException anymore, right?
{ | ||
T provide(int shardId); | ||
|
||
default boolean isAutomaticShutdown(int shardId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add javadocs here, and possibly rename to shouldShutdownAutomatically
cuz isAutomaticShutdown sounds like JDA asks the ThreadPoolProvider if the pool already shuts down automatically rather than asking if JDA should shut it down
*/ | ||
@Deprecated | ||
public JDA buildBlocking(JDA.Status status) throws LoginException, InterruptedException | ||
{ | ||
Checks.notNull(status, "Status"); | ||
Checks.check(status.isInit(), "Cannot await the status %s as it is not part of the login cycle!", status); | ||
JDA jda = buildAsync(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would use build() here instead of buildAsync(). The checks are also not needed anymore, as they are present in jda#awaitStatus()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are needed because we don't want to build if they fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right... makes sense
*/ | ||
@Deprecated | ||
public JDA buildBlocking() throws LoginException, InterruptedException | ||
{ | ||
return buildBlocking(Status.CONNECTED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe switch to build().awaitReady()? Its not important here tho
Pull Request Etiquette
There are several guidelines you should follow in order for your
Pull Request to be merged.
Description
This will add a few more options to configure JDA.