Package club.minnced.discord.webhook
Class WebhookClientBuilder
- java.lang.Object
-
- club.minnced.discord.webhook.WebhookClientBuilder
-
public class WebhookClientBuilder extends Object
Builder for aWebhookClient
instance.
-
-
Field Summary
Fields Modifier and Type Field Description static Pattern
WEBHOOK_PATTERN
Pattern used to validate webhook urls(?:https?://)?(?:\w+\.)?discord(?:app)?\.com/api(?:/v\d+)?/webhooks/(\d+)/([\w-]+)(?:/(?:\w+)?)?
-
Constructor Summary
Constructors Constructor Description WebhookClientBuilder(long id, @NotNull String token)
Creates a new WebhookClientBuilder for the specified webhook componentsWebhookClientBuilder(@NotNull String url)
Creates a new WebhookClientBuilder for the specified webhook url
The url is verified usingWEBHOOK_PATTERN
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull WebhookClient
build()
Builds theWebhookClient
with the current settings@NotNull D4JWebhookClient
buildD4J()
Builds theD4JWebhookClient
with the current settings@NotNull JavacordWebhookClient
buildJavacord()
Builds theJavacordWebhookClient
with the current settings@NotNull JDAWebhookClient
buildJDA()
Builds theJDAWebhookClient
with the current settingsstatic @NotNull WebhookClientBuilder
fromD4J(discord4j.core.object.entity.Webhook webhook)
Creates a WebhookClientBuilder for the provided webhook.static @NotNull WebhookClientBuilder
fromJavacord(org.javacord.api.entity.webhook.Webhook webhook)
Creates a WebhookClientBuilder for the provided webhook.static @NotNull WebhookClientBuilder
fromJDA(net.dv8tion.jda.api.entities.Webhook webhook)
Creates a WebhookClientBuilder for the provided webhook.@NotNull WebhookClientBuilder
setAllowedMentions(@Nullable AllowedMentions mentions)
The default mention whitelist for every outgoing message.@NotNull WebhookClientBuilder
setDaemon(boolean isDaemon)
Whether the default executor should use daemon threads.@NotNull WebhookClientBuilder
setExecutorService(@Nullable ScheduledExecutorService executorService)
TheScheduledExecutorService
that is used to execute send requests in the resultingWebhookClient
.@NotNull WebhookClientBuilder
setHttpClient(@Nullable OkHttpClient client)
TheOkHttpClient
that is used to execute send requests in the resultingWebhookClient
.@NotNull WebhookClientBuilder
setThreadFactory(@Nullable ThreadFactory factory)
TheThreadFactory
that is used to initialize the defaultScheduledExecutorService
used ifsetExecutorService(java.util.concurrent.ScheduledExecutorService)
is not configured.@NotNull WebhookClientBuilder
setThreadId(long threadId)
The ID for the thread you want the messages to be posted to.@NotNull WebhookClientBuilder
setWait(boolean waitForMessage)
Whether resulting messages should be parsed after sending, if this is set tofalse
the futures returned byWebhookClient
will receivenull
instead of instances ofReadonlyMessage
.
-
-
-
Field Detail
-
WEBHOOK_PATTERN
public static final Pattern WEBHOOK_PATTERN
Pattern used to validate webhook urls(?:https?://)?(?:\w+\.)?discord(?:app)?\.com/api(?:/v\d+)?/webhooks/(\d+)/([\w-]+)(?:/(?:\w+)?)?
-
-
Constructor Detail
-
WebhookClientBuilder
public WebhookClientBuilder(long id, @NotNull @NotNull String token)
Creates a new WebhookClientBuilder for the specified webhook components- Parameters:
id
- The webhook idtoken
- The webhook token- Throws:
NullPointerException
- If the token is null
-
WebhookClientBuilder
public WebhookClientBuilder(@NotNull @NotNull String url)
Creates a new WebhookClientBuilder for the specified webhook url
The url is verified usingWEBHOOK_PATTERN
.- Parameters:
url
- The url to use- Throws:
NullPointerException
- If the url is nullIllegalArgumentException
- If the url is not valid
-
-
Method Detail
-
fromJDA
@NotNull public static @NotNull WebhookClientBuilder fromJDA(@NotNull net.dv8tion.jda.api.entities.Webhook webhook)
Creates a WebhookClientBuilder for the provided webhook.- Parameters:
webhook
- The webhook- Returns:
- The WebhookClientBuilder
- Throws:
NullPointerException
- If the webhook is null or does not provide a token
-
fromD4J
@NotNull public static @NotNull WebhookClientBuilder fromD4J(@NotNull discord4j.core.object.entity.Webhook webhook)
Creates a WebhookClientBuilder for the provided webhook.- Parameters:
webhook
- The webhook- Returns:
- The WebhookClientBuilder
- Throws:
NullPointerException
- If the webhook is null or does not provide a token
-
fromJavacord
@NotNull public static @NotNull WebhookClientBuilder fromJavacord(@NotNull org.javacord.api.entity.webhook.Webhook webhook)
Creates a WebhookClientBuilder for the provided webhook.- Parameters:
webhook
- The webhook- Returns:
- The WebhookClientBuilder
- Throws:
NullPointerException
- If the webhook is null or does not provide a token
-
setExecutorService
@NotNull public @NotNull WebhookClientBuilder setExecutorService(@Nullable @Nullable ScheduledExecutorService executorService)
TheScheduledExecutorService
that is used to execute send requests in the resultingWebhookClient
.
This will be closed by a call toWebhookClient.close()
.- Parameters:
executorService
- The executor service to use- Returns:
- The current builder, for chaining convenience
-
setHttpClient
@NotNull public @NotNull WebhookClientBuilder setHttpClient(@Nullable @Nullable OkHttpClient client)
TheOkHttpClient
that is used to execute send requests in the resultingWebhookClient
.
It is usually not necessary to use multiple different clients in one application- Parameters:
client
- The http client to use- Returns:
- The current builder, for chaining convenience
-
setThreadFactory
@NotNull public @NotNull WebhookClientBuilder setThreadFactory(@Nullable @Nullable ThreadFactory factory)
TheThreadFactory
that is used to initialize the defaultScheduledExecutorService
used ifsetExecutorService(java.util.concurrent.ScheduledExecutorService)
is not configured.- Parameters:
factory
- The factory to use- Returns:
- The current builder, for chaining convenience
-
setAllowedMentions
@NotNull public @NotNull WebhookClientBuilder setAllowedMentions(@Nullable @Nullable AllowedMentions mentions)
The default mention whitelist for every outgoing message.
SeeAllowedMentions
for more details.- Parameters:
mentions
- The mention whitelist- Returns:
- This builder for chaining convenience
-
setDaemon
@NotNull public @NotNull WebhookClientBuilder setDaemon(boolean isDaemon)
Whether the default executor should use daemon threads.
This has no effect if eithersetExecutorService(java.util.concurrent.ScheduledExecutorService)
orsetThreadFactory(java.util.concurrent.ThreadFactory)
are configured to non-null values.- Parameters:
isDaemon
- Whether to use daemon threads or not- Returns:
- The current builder, for chaining convenience
-
setWait
@NotNull public @NotNull WebhookClientBuilder setWait(boolean waitForMessage)
Whether resulting messages should be parsed after sending, if this is set tofalse
the futures returned byWebhookClient
will receivenull
instead of instances ofReadonlyMessage
.- Parameters:
waitForMessage
- True, if the client should parse resulting messages (default behavior)- Returns:
- The current builder, for chaining convenience
-
setThreadId
@NotNull public @NotNull WebhookClientBuilder setThreadId(long threadId)
The ID for the thread you want the messages to be posted to.
You can useWebhookClient.onThread(long)
to send specific messages to threads.- Parameters:
threadId
- The target thread id, or 0 to not use threads- Returns:
- The current builder, for chaining convenience
-
build
@NotNull public @NotNull WebhookClient build()
Builds theWebhookClient
with the current settings- Returns:
WebhookClient
instance
-
buildJDA
@NotNull public @NotNull JDAWebhookClient buildJDA()
Builds theJDAWebhookClient
with the current settings- Returns:
JDAWebhookClient
instance
-
buildD4J
@NotNull public @NotNull D4JWebhookClient buildD4J()
Builds theD4JWebhookClient
with the current settings- Returns:
D4JWebhookClient
instance
-
buildJavacord
@NotNull public @NotNull JavacordWebhookClient buildJavacord()
Builds theJavacordWebhookClient
with the current settings- Returns:
JavacordWebhookClient
instance
-
-