Class InteractiveMenu

java.lang.Object
com.github.alex1304.ultimategdbot.api.utils.menu.InteractiveMenu

public class InteractiveMenu
extends java.lang.Object
Utility to create interactive menus in Discord. An interactive menu first sends a message as a prompt and waits for a interaction from the user. The said interaction can be either a message or a reaction.
  • Method Details

    • create

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

      public static InteractiveMenu create​(java.lang.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 static InteractiveMenu create​(reactor.core.publisher.Mono<java.util.function.Consumer<discord4j.core.spec.MessageCreateSpec>> specMono)
      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:
      specMono - the Mono emitting the spec to build the menu message
      Returns:
      a new InteractiveMenu
    • createPaginated

      public static InteractiveMenu createPaginated​(java.util.concurrent.atomic.AtomicInteger currentPage, PaginationControls controls, java.util.function.IntFunction<UniversalMessageSpec> paginator)
      Creates a new InteractiveMenu prefilled with menu items useful for pagination.
      Parameters:
      currentPage - an AtomicInteger that stores the current page number
      controls - the emojis to use for reaction-based navigation controls
      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 static InteractiveMenu createAsyncPaginated​(java.util.concurrent.atomic.AtomicInteger currentPage, PaginationControls controls, java.util.function.IntFunction<reactor.core.publisher.Mono<UniversalMessageSpec>> asyncPaginator)
      Creates a new InteractiveMenu prefilled with menu items useful for pagination. Unlike createPaginated(AtomicInteger, PaginationControls, IntFunction), this method support asynchronous paginator functions.
      Parameters:
      currentPage - an AtomicInteger that stores the current page number
      controls - the emojis to use for reaction-based navigation controls
      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.
    • addMessageItem

      public InteractiveMenu addMessageItem​(java.lang.String message, java.util.function.Function<MessageMenuInteraction,​reactor.core.publisher.Mono<java.lang.Void>> action)
    • addReactionItem

      public InteractiveMenu addReactionItem​(java.lang.String emojiName, java.util.function.Function<ReactionMenuInteraction,​reactor.core.publisher.Mono<java.lang.Void>> action)
    • deleteMenuOnClose

      public InteractiveMenu deleteMenuOnClose​(boolean deleteMenuOnClose)
    • deleteMenuOnTimeout

      public InteractiveMenu deleteMenuOnTimeout​(boolean deleteMenuOnTimeout)
    • closeAfterMessage

      public InteractiveMenu closeAfterMessage​(boolean closeAfterMessage)
    • closeAfterReaction

      public InteractiveMenu closeAfterReaction​(boolean closeAfterReaction)
    • open

      public reactor.core.publisher.Mono<java.lang.Void> open​(Context ctx)
      Opens the interactive menu, that is, sends the menu message over Discord and starts listening for user's interaction. The returned Mono completes once the menu closes or timeouts. If the menu was created using the factory method create(Mono) and the supplied Mono completes empty or with an error, the respective signals will be forwarded through the returning Mono.
      Parameters:
      ctx - the context of the command invoking this menu
      Returns:
      a Mono completing when the menu closes or timeouts. Any error happening while the menu is open will be forwarded through the Mono