Class WebhookCluster

    • Constructor Detail

      • WebhookCluster

        public WebhookCluster​(@NotNull
                              @NotNull Collection<? extends WebhookClient> initialClients)
        Creates a new WebhookCluster with the provided clients
        Parameters:
        initialClients - Clients to add to the cluster
        Throws:
        NullPointerException - If provided with null
      • WebhookCluster

        public WebhookCluster​(int initialCapacity)
        Creates a webhook cluster with the specified capacity.
        Note that this capacity can be expanded dynamically by building/adding more clients.
        Parameters:
        initialCapacity - The initial capacity
        Throws:
        IllegalArgumentException - If the capacity is illegal
        See Also:
        ArrayList(int)
      • WebhookCluster

        public WebhookCluster()
        Default initializes a new WebhookCluster.
        This cluster will be empty.
    • Method Detail

      • setAllowedMentions

        @NotNull
        public @NotNull WebhookCluster setAllowedMentions​(@Nullable
                                                          @Nullable AllowedMentions allowedMentions)
        The mention whitelist to use by default for every webhook client.
        See AllowedMentions for more details.
        Parameters:
        allowedMentions - The default mention whitelist
        Returns:
        WebhookCluster instance for chaining convenience
      • setDefaultDaemon

        @NotNull
        public @NotNull WebhookCluster setDefaultDaemon​(boolean isDaemon)
        Configures whether WebhookClient instances should be daemon by default.
        Parameters:
        isDaemon - True, if clients should be daemon
        Returns:
        WebhookCluster instance for chaining convenience
        See Also:
        WebhookClientBuilder.setDaemon(boolean)
      • buildWebhook

        @NotNull
        public @NotNull WebhookCluster buildWebhook​(long id,
                                                    @NotNull
                                                    @NotNull String token)
        Builds a WebhookClient instance with the provided components and specified default configurations.
        Parameters:
        id - The id of the webhook
        token - The token of the webhook
        Returns:
        WebhookCluster instance for chaining convenience
        Throws:
        NullPointerException - If the token is null
      • newBuilder

        @NotNull
        public @NotNull WebhookClientBuilder newBuilder​(long id,
                                                        @NotNull
                                                        @NotNull String token)
        Creates a WebhookClientBuilder instance with the provided components and specified default configurations.
        The webhook client must be explicitly added to the cluster after building.
        Parameters:
        id - The id of the webhook
        token - The token of the webhook
        Returns:
        WebhookClientBuilder instance
        Throws:
        NullPointerException - If the token is null
      • addWebhooks

        @NotNull
        public @NotNull WebhookCluster addWebhooks​(@NotNull
                                                   @NotNull WebhookClient... clients)
        Adds the provided webhooks to the cluster.
        Parameters:
        clients - The clients to add
        Returns:
        WebhookCluster instance for chaining convenience
        Throws:
        NullPointerException - If provided with null
        IllegalArgumentException - If at least one of the clients is already shutdown
      • removeWebhooks

        @NotNull
        public @NotNull WebhookCluster removeWebhooks​(@NotNull
                                                      @NotNull WebhookClient... clients)
        Removes the provided webhooks from the cluster.
        Parameters:
        clients - The clients to remove
        Returns:
        WebhookCluster instance for chaining convenience
        Throws:
        NullPointerException - If provided with null
      • removeWebhooks

        @NotNull
        public @NotNull WebhookCluster removeWebhooks​(@NotNull
                                                      @NotNull Collection<WebhookClient> clients)
        Removes the provided webhooks from the cluster.
        Parameters:
        clients - The clients to remove
        Returns:
        WebhookCluster instance for chaining convenience
        Throws:
        NullPointerException - If provided with null
      • removeIf

        @NotNull
        public @NotNull List<WebhookClient> removeIf​(@NotNull
                                                     @NotNull Predicate<WebhookClient> predicate)
        Removes webhooks from the cluster based on the specified filter.
        Parameters:
        predicate - The filter to decide whether to remove a client or not
        Returns:
        List of the removed webhooks
        Throws:
        NullPointerException - If provided with null
      • closeIf

        @NotNull
        public @NotNull List<WebhookClient> closeIf​(@NotNull
                                                    @NotNull Predicate<WebhookClient> predicate)
        Closes and removes webhook clients based on the specified filter.
        Parameters:
        predicate - The filter to decide whether to close and remove the client
        Returns:
        List of the removed webhooks
        Throws:
        NullPointerException - If provided with null
      • getWebhooks

        @NotNull
        public @NotNull List<WebhookClient> getWebhooks()
        Unmodifiable list of currently registered clients
        Returns:
        List of clients
      • broadcast

        @NotNull
        public @NotNull List<CompletableFuture<ReadonlyMessage>> broadcast​(@NotNull
                                                                           @NotNull WebhookEmbed first,
                                                                           @NotNull
                                                                           @NotNull WebhookEmbed... embeds)
        Sends a message to all registered clients.
        Parameters:
        first - The first embed to send
        embeds - Optional additional embeds to send, up to 10
        Returns:
        List of futures for each client execution
        Throws:
        NullPointerException - If provided with null
      • broadcast

        @NotNull
        public @NotNull List<CompletableFuture<ReadonlyMessage>> broadcast​(@NotNull
                                                                           @NotNull String content)
        Sends a message to all registered clients.
        Parameters:
        content - The message to send
        Returns:
        List of futures for each client execution
        Throws:
        NullPointerException - If provided with null
      • broadcast

        @NotNull
        public @NotNull List<CompletableFuture<ReadonlyMessage>> broadcast​(@NotNull
                                                                           @NotNull String fileName,
                                                                           @NotNull
                                                                           @NotNull File file)
        Sends a message to all registered clients.
        Parameters:
        fileName - The alternative file name to use
        file - The file to send
        Returns:
        List of futures for each client execution
        Throws:
        NullPointerException - If provided with null
        UncheckedIOException - If an I/O error occurs
      • broadcast

        @NotNull
        public @NotNull List<CompletableFuture<ReadonlyMessage>> broadcast​(@NotNull
                                                                           @NotNull String fileName,
                                                                           @NotNull
                                                                           @org.jetbrains.annotations.NotNull byte[] data)
        Sends a message to all registered clients.
        Parameters:
        fileName - The alternative file name to use
        data - The data to send
        Returns:
        List of futures for each client execution
        Throws:
        NullPointerException - If provided with null
      • close

        public void close()
        Performs cascade closing on current webhook clients, all clients will be closed and removed after this returns.
        The cluster may still be used after calls to this method occurred.
        Specified by:
        close in interface AutoCloseable