Package dev.sympho.bot_utils.component
Class ComponentManager<E extends @NonNull ComponentInteractionEvent,C extends @NonNull ComponentManager.ComponentContext<E>,HF extends @NonNull ComponentManager.HandlerFunction<C>,H extends @NonNull ComponentManager.Handler<H,HF>,HE extends @NonNull ComponentManager.HandlerEntry<H>>
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
public abstract class ComponentManager<E extends @NonNull ComponentInteractionEvent,C extends @NonNull ComponentManager.ComponentContext<E>,HF extends @NonNull ComponentManager.HandlerFunction<C>,H extends @NonNull ComponentManager.Handler<H,HF>,HE extends @NonNull ComponentManager.HandlerEntry<H>>
extends Object
Centralized manager for component interaction handling.
- Since:
- 1.0
- Version:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe execution context of a component being interacted with.protected static interfaceSpecification for the handling of an interaction.protected static interfaceComponentManager.HandlerEntry<H extends @NonNull ComponentManager.Handler<H,?>> Specification for a handler to be registered.protected static interfaceA function used to handle an interaction event. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionComponentManager(GatewayDiscordClient client, AccessManager accessManager) Creates a new manager that receives interactions from the given client. -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the interaction event type.protected abstract CmakeContext(E event, AccessManager access) Creates the interaction context.static StringCreates a custom ID for a component with arguments in a format that is compatible with a manager.voidRegisters an interaction handler.voidRegisters a handler.voidregisterAll(Collection<HE> handlers) Registers a group of handlers.voidstart()Starts handling interactions.voidstop()Stops handling interactions.voidunregister(String id) Unregisters an interaction handler, if it exists.validateInteraction(C context, H handler) Validates that the interaction is allowed.
-
Field Details
-
logger
protected final org.slf4j.Logger loggerLogger.
-
-
Constructor Details
-
ComponentManager
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
Registers a handler.- Parameters:
id- The ID that invokes the handler.handler- The handler to use.
-
register
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
Unregisters an interaction handler, if it exists.- Parameters:
id- The ID that invokes the handler.
-
registerAll
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
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
Retrieves the interaction event type.- Returns:
- The interaction event type.
-
makeContext
Creates the interaction context.- Parameters:
event- The interaction event.access- The access manager.- Returns:
- The created context.
-
validateInteraction
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.
-