Module ultimategdbot.api
Class InteractiveMenu
- java.lang.Object
-
- com.github.alex1304.ultimategdbot.api.command.menu.InteractiveMenu
-
public final 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InteractiveMenu
addMessageItem(String message, Function<MessageMenuInteraction,reactor.core.publisher.Mono<Void>> action)
Adds an item to this menu that is triggered when replying with a specific message.InteractiveMenu
addReactionItem(String emojiName, Function<ReactionMenuInteraction,reactor.core.publisher.Mono<Void>> action)
Adds an item to this menu that is triggered when adding or removing a reaction to the menu message.InteractiveMenu
closeAfterMessage(boolean closeAfterMessage)
Sets whether to close this menu after a message item is triggered.InteractiveMenu
closeAfterReaction(boolean closeAfterReaction)
Sets whether to close this menu after a reaction item is triggered.InteractiveMenu
deleteMenuOnClose(boolean deleteMenuOnClose)
Sets whether to delete the menu message when the menu is closed by user.InteractiveMenu
deleteMenuOnTimeout(boolean deleteMenuOnTimeout)
Sets whether to delete the menu message when the menu is closed automatically by timeoutreactor.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.InteractiveMenu
withInteractionContext(Consumer<Map<String,Object>> contextConsumer)
Initializes the interaction context that will be passed to all interaction instances happening while this menu is open.InteractiveMenu
withTimeout(Duration timeout)
Sets a timeou after which the menu automatically closes.
-
-
-
Method Detail
-
withInteractionContext
public InteractiveMenu withInteractionContext(Consumer<Map<String,Object>> contextConsumer)
Initializes the interaction context that will be passed to all interaction instances happening while this menu is open.- Parameters:
contextConsumer
- the consumer that populates the context map- Returns:
- this menu
-
addMessageItem
public InteractiveMenu addMessageItem(String message, Function<MessageMenuInteraction,reactor.core.publisher.Mono<Void>> action)
Adds an item to this menu that is triggered when replying with a specific message.- Parameters:
message
- the text the message must start with in order to trigger this itemaction
- the action associated to this item- Returns:
- this menu
-
addReactionItem
public InteractiveMenu addReactionItem(String emojiName, Function<ReactionMenuInteraction,reactor.core.publisher.Mono<Void>> action)
Adds an item to this menu that is triggered when adding or removing a reaction to the menu message.- Parameters:
emojiName
- the name of the reaction emoji identifying this item. It can be a Unicode emoji character, or the name of one of the emojis in the emoji servers configured on the botaction
- the action associated to this item- Returns:
- this menu
-
deleteMenuOnClose
public InteractiveMenu deleteMenuOnClose(boolean deleteMenuOnClose)
Sets whether to delete the menu message when the menu is closed by user.- Parameters:
deleteMenuOnClose
- a boolean- Returns:
- this menu
-
deleteMenuOnTimeout
public InteractiveMenu deleteMenuOnTimeout(boolean deleteMenuOnTimeout)
Sets whether to delete the menu message when the menu is closed automatically by timeout- Parameters:
deleteMenuOnTimeout
- a boolean- Returns:
- this menu
-
closeAfterMessage
public InteractiveMenu closeAfterMessage(boolean closeAfterMessage)
Sets whether to close this menu after a message item is triggered.- Parameters:
closeAfterMessage
- a boolean- Returns:
- this menu
-
closeAfterReaction
public InteractiveMenu closeAfterReaction(boolean closeAfterReaction)
Sets whether to close this menu after a reaction item is triggered.- Parameters:
closeAfterReaction
- a boolean- Returns:
- this menu
-
withTimeout
public InteractiveMenu withTimeout(Duration timeout)
Sets a timeou after which the menu automatically closes. The timeout starts when the menu opens, and is not reset by user interaction.- Parameters:
timeout
- the timeout- Returns:
- this menu
-
open
public 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. The returned Mono completes once the menu closes or timeouts.- 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
-
-