Package dev.sympho.bot_utils.component
Class ComponentManager<E extends @NonNull ComponentInteractionEvent,C extends @NonNull ComponentEventContext,HF extends @NonNull ComponentManager.HandlerFunction<C>,H extends @NonNull ComponentManager.Handler<HF>>
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceSpecification for the handling of an interaction.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 a handler.voidregisterAll(Collection<H> handlers) Registers a group of handlers.reportFailure(C context, String message) Reports an error back to the user.protected Mono<?>runHandler(H handler, C context, String args) Executes the selected handler.protected static EmbedCreateFields.FieldFormats a field that links to the message that the component is on.voidstart()Starts handling interactions.voidstop()Stops handling interactions.voidunregister(String id) Unregisters an interaction handler, if it exists.
-
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:
handler- The handler to register.
-
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.
-
sourceField
Formats a field that links to the message that the component is on.- Parameters:
event- The event.- Returns:
- The field.
-
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.
-
runHandler
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
AccessExceptionto indicate that the user does not have sufficient permissions. - Implementation Requirements:
- By default, it simply calls
ComponentManager.HandlerFunction.apply(ComponentEventContext, String).
-
reportFailure
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.
-