Module ultimategdbot.api
Class InteractiveMenuService
- java.lang.Object
-
- com.github.alex1304.ultimategdbot.api.command.menu.InteractiveMenuService
-
public final class InteractiveMenuService extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static String
CONFIG_RESOURCE_NAME
-
Constructor Summary
Constructors Constructor Description InteractiveMenuService(BotConfig botConfig, discord4j.core.GatewayDiscordClient gateway, CommandService commandService, EmojiService emojiService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InteractiveMenu
create(String message)
Creates a new empty InteractiveMenu with a given message that will serve as menu prompt.InteractiveMenu
create(Consumer<discord4j.core.spec.MessageCreateSpec> messageCreateSpec)
Creates a new empty InteractiveMenu with a given message that will serve as menu prompt.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.InteractiveMenu
createAsyncPaginated(BiFunction<Translator,Integer,reactor.core.publisher.Mono<MessageSpecTemplate>> asyncPaginator)
Creates a newInteractiveMenu
prefilled with menu items useful for pagination.InteractiveMenu
createPaginated(String text, int pageLength)
Creates a newInteractiveMenu
splitting the given text into several pages, returning a paginatedInteractiveMenu
if it contains 2 pages or more.InteractiveMenu
createPaginated(BiFunction<Translator,Integer,MessageSpecTemplate> paginator)
Creates a newInteractiveMenu
prefilled with menu items useful for pagination.PaginationControls
getPaginationControls()
Gets the pagination controls used by this service.
-
-
-
Field Detail
-
CONFIG_RESOURCE_NAME
public static final String CONFIG_RESOURCE_NAME
- See Also:
- Constant Field Values
-
-
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 newInteractiveMenu
splitting the given text into several pages, returning a paginatedInteractiveMenu
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 simpleInteractiveMenu
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 paginatepageLength
- the max characters per page- Returns:
- a new
InteractiveMenu
-
createPaginated
public InteractiveMenu createPaginated(BiFunction<Translator,Integer,MessageSpecTemplate> paginator)
Creates a newInteractiveMenu
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 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 InteractiveMenu createAsyncPaginated(BiFunction<Translator,Integer,reactor.core.publisher.Mono<MessageSpecTemplate>> asyncPaginator)
Creates a newInteractiveMenu
prefilled with menu items useful for pagination. UnlikecreatePaginated(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 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.
-
getPaginationControls
public PaginationControls getPaginationControls()
Gets the pagination controls used by this service.- Returns:
- the controls
-
-