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 extends BaseHelper.
T - The type of collection used to store pages.
Direct Known Subclasses:
ButtonizeHelper, CategorizeHelper, LazyPaginateHelper, PaginateHelper

public abstract class BaseHelper<Helper extends BaseHelper<Helper,​T>,​T> extends Object
Abstract class meant to be extended by builder-like classes, allowing reusability of parameters passed to Pages methods.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    BaseHelper​(Class<Helper> subClass, T buttons, boolean useButtons)
    Constructor for BaseHelper.
  • Method Summary

    Modifier and Type
    Method
    Description
    <Out extends net.dv8tion.jda.api.utils.messages.MessageRequest<Out>>
    Out
    apply​(Out action)
    Prepares the message for being used by the library.
    boolean
    canInteract​(net.dv8tion.jda.api.entities.User user)
    Checks whether the supplied User can 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 the List of Components generated by this helper.
    Retrieves the collection used by this helper to store the pages.
    long
    Retrieves the timeout for the event, in milliseconds.
    boolean
    Returns whether the Emote.CANCEL button will be included or not.
    boolean
    Returns whether the event is configured to use buttons or not.
    setCancellable​(boolean cancellable)
    Set whether the event is cancellable through Emote.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 boolean
    shouldUpdate​(net.dv8tion.jda.api.entities.Message msg)
    Calculates whether the Message needs to have buttons applied onto or not.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BaseHelper

      protected BaseHelper(Class<Helper> subClass, T buttons, boolean useButtons)
      Constructor for BaseHelper.
      Parameters:
      subClass - A class that extends BaseHelper.
      buttons - The collection used to store pages.
      useButtons - Whether to use interaction buttons or not.
  • Method Details

    • getContent

      public T 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 the Emote.CANCEL button will be included or not.
      Returns:
      Whether the event is cancellable or not.
    • setCancellable

      public Helper setCancellable(boolean cancellable)
      Set whether the event is cancellable through Emote.CANCEL.
      Parameters:
      cancellable - Whether the event can be cancelled or not (default: true).
      Returns:
      The BaseHelper instance for chaining convenience.
    • getTimeout

      public long getTimeout()
      Retrieves the timeout for the event, in milliseconds.
      Returns:
      The timeout for the event.
    • setTimeout

      public Helper setTimeout(int time, TimeUnit unit)
      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 BaseHelper instance for chaining convenience.
    • canInteract

      public boolean canInteract(net.dv8tion.jda.api.entities.User user)
      Checks whether the supplied User can interact with the event.
      Parameters:
      user - The User to check.
      Returns:
      Whether the suppied user can interact with the event.
    • setCanInteract

      public Helper setCanInteract(@Nullable Predicate<net.dv8tion.jda.api.entities.User> canInteract)
      Set the condition used to check if a given user can interact with the event buttons.
      Parameters:
      canInteract - A Predicate for checking if a given user can interact with the buttons (default: null).
      Returns:
      The BaseHelper instance 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 the List of Components generated by this helper.
      Type Parameters:
      Out - Generic for a MessageRequest
      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 a MessageRequest
      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 the Message needs to have buttons applied onto or not.
      Parameters:
      msg - The Message to be checked.
      Returns:
      Whether it needs to be updated or not.