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

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(String id, H handler)
      Registers a handler.
      Parameters:
      id - The ID that invokes the handler.
      handler - The handler to use.
    • register

      public void register(HE handler)
      Registers an interaction handler.
      Parameters:
      handler - The handler to use.
      Implementation Requirements:
      The default implementation directly delegates to register(String, Handler). If the entry type has additional configuration options, this method should be overriden to use them.
    • 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<HE> 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.
    • 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.
    • validateInteraction

      @SideEffectFree protected abstract Mono<String> validateInteraction(C context, H handler)
      Validates that the interaction is allowed.
      Parameters:
      context - The interaction context.
      handler - The invoked handler.
      Returns:
      A mono that completes empty if the interaction is allowed, otherwise issuing an error message to be sent to the user.
    • start

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

      @PreDestroy public void stop()
      Stops handling interactions.