Class InteractiveMenu
java.lang.Object
com.github.alex1304.ultimategdbot.api.utils.menu.InteractiveMenu
public class InteractiveMenu extends 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 Summary
Modifier and Type Method Description InteractiveMenu
addMessageItem(String message, Function<MessageMenuInteraction,reactor.core.publisher.Mono<Void>> action)
InteractiveMenu
addReactionItem(String emojiName, Function<ReactionMenuInteraction,reactor.core.publisher.Mono<Void>> action)
InteractiveMenu
closeAfterMessage(boolean closeAfterMessage)
InteractiveMenu
closeAfterReaction(boolean closeAfterReaction)
static InteractiveMenu
create(String message)
Creates a new empty InteractiveMenu with a given message that will serve as menu prompt.static InteractiveMenu
create(Consumer<discord4j.core.spec.MessageCreateSpec> spec)
Creates a new empty InteractiveMenu with a given message that will serve as menu prompt.static InteractiveMenu
create(reactor.core.publisher.Mono<Consumer<discord4j.core.spec.MessageCreateSpec>> specMono)
Creates a new empty InteractiveMenu with a given message that will serve as menu prompt.static InteractiveMenu
createAsyncPaginated(AtomicInteger currentPage, PaginationControls controls, IntFunction<reactor.core.publisher.Mono<UniversalMessageSpec>> asyncPaginator)
Creates a new InteractiveMenu prefilled with menu items useful for pagination.static InteractiveMenu
createPaginated(AtomicInteger currentPage, PaginationControls controls, IntFunction<UniversalMessageSpec> paginator)
Creates a new InteractiveMenu prefilled with menu items useful for pagination.InteractiveMenu
deleteMenuOnClose(boolean deleteMenuOnClose)
InteractiveMenu
deleteMenuOnTimeout(boolean deleteMenuOnTimeout)
reactor.core.publisher.Mono<Void>
open(Context ctx)
Opens the interactive menu, that is, sends the menu message over Discord and starts listening for user's interaction.
-
Method Details
-
create
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
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<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(AtomicInteger currentPage, PaginationControls controls, IntFunction<UniversalMessageSpec> paginator)Creates a new InteractiveMenu prefilled with menu items useful for pagination.- Parameters:
currentPage
- an AtomicInteger that stores the current page numbercontrols
- the emojis to use for reaction-based navigation controlspaginator
- 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 aPageNumberOutOfRangeException
which is handled by default to cover cases where the user inputs an invalid page number. Note that if the paginator function throwsPageNumberOutOfRangeException
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(AtomicInteger currentPage, PaginationControls controls, IntFunction<reactor.core.publisher.Mono<UniversalMessageSpec>> asyncPaginator)Creates a new InteractiveMenu prefilled with menu items useful for pagination. UnlikecreatePaginated(AtomicInteger, PaginationControls, IntFunction)
, this method support asynchronous paginator functions.- Parameters:
currentPage
- an AtomicInteger that stores the current page numbercontrols
- the emojis to use for reaction-based navigation controlsasyncPaginator
- 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 aPageNumberOutOfRangeException
which is handled by default to cover cases where the user inputs an invalid page number. Note that ifPageNumberOutOfRangeException
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(String message, Function<MessageMenuInteraction,reactor.core.publisher.Mono<Void>> action) -
addReactionItem
public InteractiveMenu addReactionItem(String emojiName, Function<ReactionMenuInteraction,reactor.core.publisher.Mono<Void>> action) -
deleteMenuOnClose
-
deleteMenuOnTimeout
-
closeAfterMessage
-
closeAfterReaction
-
open
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 methodcreate(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
-