Package club.minnced.discord.webhook
Class WebhookClientBuilder
- java.lang.Object
-
- club.minnced.discord.webhook.WebhookClientBuilder
-
public class WebhookClientBuilder extends Object
Builder for aWebhookClientinstance.
-
-
Field Summary
Fields Modifier and Type Field Description static PatternWEBHOOK_PATTERNPattern 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 WebhookClientbuild()Builds theWebhookClientwith the current settings@NotNull D4JWebhookClientbuildD4J()Builds theD4JWebhookClientwith the current settings@NotNull JavacordWebhookClientbuildJavacord()Builds theJavacordWebhookClientwith the current settings@NotNull JDAWebhookClientbuildJDA()Builds theJDAWebhookClientwith the current settingsstatic @NotNull WebhookClientBuilderfromD4J(discord4j.core.object.entity.Webhook webhook)Creates a WebhookClientBuilder for the provided webhook.static @NotNull WebhookClientBuilderfromJavacord(org.javacord.api.entity.webhook.Webhook webhook)Creates a WebhookClientBuilder for the provided webhook.static @NotNull WebhookClientBuilderfromJDA(net.dv8tion.jda.api.entities.Webhook webhook)Creates a WebhookClientBuilder for the provided webhook.@NotNull WebhookClientBuildersetAllowedMentions(@Nullable AllowedMentions mentions)The default mention whitelist for every outgoing message.@NotNull WebhookClientBuildersetDaemon(boolean isDaemon)Whether the default executor should use daemon threads.@NotNull WebhookClientBuildersetExecutorService(@Nullable ScheduledExecutorService executorService)TheScheduledExecutorServicethat is used to execute send requests in the resultingWebhookClient.@NotNull WebhookClientBuildersetHttpClient(@Nullable OkHttpClient client)TheOkHttpClientthat is used to execute send requests in the resultingWebhookClient.@NotNull WebhookClientBuildersetThreadFactory(@Nullable ThreadFactory factory)TheThreadFactorythat is used to initialize the defaultScheduledExecutorServiceused ifsetExecutorService(java.util.concurrent.ScheduledExecutorService)is not configured.@NotNull WebhookClientBuildersetThreadId(long threadId)The ID for the thread you want the messages to be posted to.@NotNull WebhookClientBuildersetWait(boolean waitForMessage)Whether resulting messages should be parsed after sending, if this is set tofalsethe futures returned byWebhookClientwill receivenullinstead 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)
TheScheduledExecutorServicethat 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)
TheOkHttpClientthat 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)
TheThreadFactorythat is used to initialize the defaultScheduledExecutorServiceused 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.
SeeAllowedMentionsfor 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 tofalsethe futures returned byWebhookClientwill receivenullinstead 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 theWebhookClientwith the current settings- Returns:
WebhookClientinstance
-
buildJDA
@NotNull public @NotNull JDAWebhookClient buildJDA()
Builds theJDAWebhookClientwith the current settings- Returns:
JDAWebhookClientinstance
-
buildD4J
@NotNull public @NotNull D4JWebhookClient buildD4J()
Builds theD4JWebhookClientwith the current settings- Returns:
D4JWebhookClientinstance
-
buildJavacord
@NotNull public @NotNull JavacordWebhookClient buildJavacord()
Builds theJavacordWebhookClientwith the current settings- Returns:
JavacordWebhookClientinstance
-
-