java.lang.Object
dev.sympho.bot_utils.component.ComponentManager<E,C,HF,H>
Type Parameters:
E - The interaction event type.
C - The context type.
HF - The handler function type.
H - The handler type.
Direct Known Subclasses:
ButtonManager, ModalManager

public abstract class ComponentManager<E extends @NonNull ComponentInteractionEvent,C extends @NonNull ComponentEventContext,HF extends @NonNull ComponentManager.HandlerFunction<C>,H extends @NonNull ComponentManager.Handler<HF>> extends Object
Centralized manager for component interaction handling.
Since:
1.0
Version:
1.0
  • Field Details

    • logger

      protected final org.slf4j.Logger logger
      Logger.
  • Constructor Details

    • ComponentManager

      @SideEffectFree public ComponentManager(GatewayDiscordClient client, AccessManager accessManager)
      Creates a new manager that receives interactions from the given client.
      Parameters:
      client - The client to receive interactions from.
      accessManager - The access manager to use.
  • Method Details

    • register

      public void register(H handler)
      Registers a handler.
      Parameters:
      handler - The handler to register.
    • unregister

      public void unregister(String id)
      Unregisters an interaction handler, if it exists.
      Parameters:
      id - The ID that invokes the handler.
    • registerAll

      public void registerAll(Collection<H> handlers)
      Registers a group of handlers.
      Parameters:
      handlers - The handlers to register.
      API Note:
      This method is a convenience to register all handlers in a batch.
    • makeId

      @SideEffectFree public static String makeId(String id, String args)
      Creates a custom ID for a component with arguments in a format that is compatible with a manager.
      Parameters:
      id - The handler ID.
      args - The interaction arguments.
      Returns:
      The assembled custom ID.
    • sourceField

      protected static EmbedCreateFields.Field sourceField(ComponentInteractionEvent event)
      Formats a field that links to the message that the component is on.
      Parameters:
      event - The event.
      Returns:
      The field.
    • getEventType

      @Pure protected abstract Class<E> getEventType()
      Retrieves the interaction event type.
      Returns:
      The interaction event type.
    • makeContext

      @SideEffectFree protected abstract C makeContext(E event, AccessManager access)
      Creates the interaction context.
      Parameters:
      event - The interaction event.
      access - The access manager.
      Returns:
      The created context.
    • runHandler

      protected Mono<?> runHandler(H handler, C context, String args)
      Executes the selected handler.
      Parameters:
      handler - The handler to execute.
      context - The execution context.
      args - The execution arguments.
      Returns:
      A mono that completes when handling is complete. It may result in an AccessException to indicate that the user does not have sufficient permissions.
      Implementation Requirements:
      By default, it simply calls ComponentManager.HandlerFunction.apply(ComponentEventContext, String).
    • reportFailure

      @SideEffectFree protected Mono<Reply> reportFailure(C context, String message)
      Reports an error back to the user.
      Parameters:
      context - The event context.
      message - The error message.
      Returns:
      A Mono that completes after the error is reported.
    • start

      @PostConstruct public void start()
      Starts handling interactions.
    • stop

      @PreDestroy public void stop()
      Stops handling interactions.