Class InteractiveMenuService


  • public final class InteractiveMenuService
    extends Object
    • Constructor Detail

      • InteractiveMenuService

        public InteractiveMenuService​(BotConfig botConfig,
                                      discord4j.core.GatewayDiscordClient gateway,
                                      CommandService commandService,
                                      EmojiService emojiService)
    • Method Detail

      • create

        public InteractiveMenu create​(Consumer<discord4j.core.spec.MessageCreateSpec> messageCreateSpec)
        Creates a new empty InteractiveMenu with a given message that will serve as menu prompt.
        Parameters:
        messageCreateSpec - the spec to build the menu message
        Returns:
        a new InteractiveMenu
      • create

        public InteractiveMenu create​(String message)
        Creates a new empty InteractiveMenu with a given message that will serve as menu prompt.
        Parameters:
        message - the menu message
        Returns:
        a new InteractiveMenu
      • create

        public InteractiveMenu create​(Function<Translator,​reactor.core.publisher.Mono<Consumer<discord4j.core.spec.MessageCreateSpec>>> source)
        Creates a new empty InteractiveMenu with a given message that will serve as menu prompt. The menu message may be supplied from an asynchronous source.
        Parameters:
        source - a Function accepting a translator and asynchronusly generating the message of the menu
        Returns:
        a new InteractiveMenu
      • createPaginated

        public InteractiveMenu createPaginated​(String text,
                                               int pageLength)
        Creates a new InteractiveMenu splitting the given text into several pages, returning a paginated InteractiveMenu if it contains 2 pages or more.

        If the whole text fits in one page (that is, if text.length() <= pageLength), it will create a simple InteractiveMenu with no pagination items.

        Pages will always be made so it doesn't cut at the middle of a line, and will properly close codeblock markdowns, as specified in MessageUtils.chunk(String, int)

        Parameters:
        text - the text to paginate
        pageLength - the max characters per page
        Returns:
        a new InteractiveMenu
      • createPaginated

        public InteractiveMenu createPaginated​(BiFunction<Translator,​Integer,​MessageSpecTemplate> paginator)
        Creates a new InteractiveMenu prefilled with menu items useful for pagination.
        Parameters:
        paginator - a Function that generates the message to display according to the current page number. If the page number is out of range, the function may throw a PageNumberOutOfRangeException which is handled by default to cover cases where the user inputs an invalid page number. Note that if the paginator function throws PageNumberOutOfRangeException with min/max values that aren't the same depending on the current page number, the behavior of the InteractiveMenu will be undefined.
        Returns:
        a new InteractiveMenu prefilled with menu items useful for pagination.
      • createAsyncPaginated

        public InteractiveMenu createAsyncPaginated​(BiFunction<Translator,​Integer,​reactor.core.publisher.Mono<MessageSpecTemplate>> asyncPaginator)
        Creates a new InteractiveMenu prefilled with menu items useful for pagination. Unlike createPaginated(BiFunction) this method support asynchronous paginator functions.
        Parameters:
        asyncPaginator - a Function that asynchronously generates the message to display according to the current page number. If the page number is out of range, the Mono returned by this function may emit a PageNumberOutOfRangeException which is handled by default to cover cases where the user inputs an invalid page number. Note that if PageNumberOutOfRangeException is emitted with min/max values that aren't the same depending on the current page number, the behavior of the InteractiveMenu will be undefined.
        Returns:
        a new InteractiveMenu prefilled with menu items useful for pagination.
      • getPaginationControls

        public PaginationControls getPaginationControls()
        Gets the pagination controls used by this service.
        Returns:
        the controls