Package com.github.ygimenez.model.helper
Class BaseHelper<Helper extends BaseHelper<Helper,T>,T>
java.lang.Object
com.github.ygimenez.model.helper.BaseHelper<Helper,T>
- Type Parameters:
Helper- A class that extendsBaseHelper.T- The type of collection used to store pages.
- Direct Known Subclasses:
ButtonizeHelper,CategorizeHelper,LazyPaginateHelper,PaginateHelper
Abstract class meant to be extended by builder-like classes, allowing reusability of parameters passed to
Pages methods.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseHelper(Class<Helper> subClass, T buttons, boolean useButtons)Constructor forBaseHelper. -
Method Summary
Modifier and TypeMethodDescription<Out extends net.dv8tion.jda.api.utils.messages.MessageRequest<Out>>
Outapply(Out action)Prepares the message for being used by the library.booleancanInteract(net.dv8tion.jda.api.entities.User user)Checks whether the suppliedUsercan interact with the event.abstract <Out extends net.dv8tion.jda.api.utils.messages.MessageRequest<Out>>
List<net.dv8tion.jda.api.interactions.components.LayoutComponent>getComponents(Out action)Retrieves theListofComponents generated by this helper.Retrieves the collection used by this helper to store the pages.longRetrieves the timeout for the event, in milliseconds.booleanReturns whether theEmote.CANCELbutton will be included or not.booleanReturns whether the event is configured to use buttons or not.setCancellable(boolean cancellable)Set whether the event is cancellable throughEmote.CANCEL.setCanInteract(Predicate<net.dv8tion.jda.api.entities.User> canInteract)Set the condition used to check if a given user can interact with the event buttons.setTimeout(int time, TimeUnit unit)Set the timeout for automatically cancelling the event.abstract booleanshouldUpdate(net.dv8tion.jda.api.entities.Message msg)Calculates whether theMessageneeds to have buttons applied onto or not.
-
Constructor Details
-
BaseHelper
Constructor forBaseHelper.- Parameters:
subClass- A class that extendsBaseHelper.buttons- The collection used to store pages.useButtons- Whether to use interaction buttons or not.
-
-
Method Details
-
getContent
Retrieves the collection used by this helper to store the pages.- Returns:
- The underlying collection.
-
isUsingButtons
public boolean isUsingButtons()Returns whether the event is configured to use buttons or not.- Returns:
- Whether the event is configured to use buttons or not.
-
isCancellable
public boolean isCancellable()Returns whether theEmote.CANCELbutton will be included or not.- Returns:
- Whether the event is cancellable or not.
-
setCancellable
Set whether the event is cancellable throughEmote.CANCEL.- Parameters:
cancellable- Whether the event can be cancelled or not (default: true).- Returns:
- The
BaseHelperinstance for chaining convenience.
-
getTimeout
public long getTimeout()Retrieves the timeout for the event, in milliseconds.- Returns:
- The timeout for the event.
-
setTimeout
Set the timeout for automatically cancelling the event. Values less than or equal to zero will disable the timeout.- Parameters:
time- The time for the timeout.unit- The unit for the timeout.- Returns:
- The
BaseHelperinstance for chaining convenience.
-
canInteract
public boolean canInteract(net.dv8tion.jda.api.entities.User user)Checks whether the suppliedUsercan interact with the event.- Parameters:
user- TheUserto check.- Returns:
- Whether the suppied user can interact with the event.
-
setCanInteract
Set the condition used to check if a given user can interact with the event buttons.- Parameters:
canInteract- APredicatefor checking if a given user can interact with the buttons (default: null).- Returns:
- The
BaseHelperinstance for chaining convenience.
-
getComponents
public abstract <Out extends net.dv8tion.jda.api.utils.messages.MessageRequest<Out>> List<net.dv8tion.jda.api.interactions.components.LayoutComponent> getComponents(Out action)Retrieves theListofComponents generated by this helper.- Type Parameters:
Out- Generic for aMessageRequest- Parameters:
action- A message event (either create or edit).- Returns:
- The list of components.
-
apply
public <Out extends net.dv8tion.jda.api.utils.messages.MessageRequest<Out>> Out apply(Out action)Prepares the message for being used by the library. This doesn't need to be called manually, this will be called during normal flow.
This is no-op when using reaction buttons.
Example:helper.apply(channel.sendMessage("Hello world!")).queue();- Type Parameters:
Out- Generic for aMessageRequest- Parameters:
action- A message event (either create or edit).- Returns:
- The same event, but modified to include the buttons.
-
shouldUpdate
public abstract boolean shouldUpdate(net.dv8tion.jda.api.entities.Message msg)Calculates whether theMessageneeds to have buttons applied onto or not.- Parameters:
msg- TheMessageto be checked.- Returns:
- Whether it needs to be updated or not.
-