io.github.freya022.botcommands.api.components.ComponentInteractionRejectionHandler.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of BotCommands Show documentation
Show all versions of BotCommands Show documentation
A Kotlin-first (and Java) framework that makes creating Discord bots a piece of cake, using the JDA library.
package io.github.freya022.botcommands.api.components
import io.github.freya022.botcommands.api.core.config.BServiceConfigBuilder
import io.github.freya022.botcommands.api.core.service.annotations.BService
import io.github.freya022.botcommands.api.core.service.annotations.InterfacedService
import io.github.freya022.botcommands.api.core.utils.simpleNestedName
import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteractionCreateEvent
/**
* Processes component interaction rejections returned by [component interaction filters][ComponentInteractionFilter].
*
* ### Usage
* - Register your instance as a service with [@BService][BService]
* or [any annotation that enables your class for dependency injection][BServiceConfigBuilder.serviceAnnotations].
* - Implement either [handle] (Java) or [handleSuspend] (Kotlin).
*
* ### Example - Replying the error string returned by the [ComponentInteractionFilter] example
* ```kt
* @BService
* class MyComponentRejectionHandler : ComponentInteractionRejectionHandler {
* override suspend fun handleSuspend(event: GenericComponentInteractionCreateEvent, handlerName: String?, userData: String) {
* event.reply_(userData, ephemeral = true).await()
* }
* }
* ```
*
*
*
* ```java
* @BService
* public class MyComponentRejectionHandler implements ComponentInteractionRejectionHandler {
* @Override
* public void handle(@NotNull GenericComponentInteractionCreateEvent event, @Nullable String handlerName, @NotNull String userData) {
* event.reply(userData).setEphemeral(true).queue();
* }
* }
* ```
*
* @param T Type of the error object returned by [ComponentInteractionFilter]
*
* @see ComponentInteractionFilter
*/
@InterfacedService(acceptMultiple = false)
interface ComponentInteractionRejectionHandler {
@JvmSynthetic
suspend fun handleSuspend(event: GenericComponentInteractionCreateEvent, handlerName: String?, userData: T): Unit =
handle(event, handlerName, userData)
fun handle(event: GenericComponentInteractionCreateEvent, handlerName: String?, userData: T): Unit =
throw NotImplementedError("${this.javaClass.simpleNestedName} must implement the 'handle' or 'handleSuspend' method")
}