All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.freya022.botcommands.api.commands.text.TextCommandRejectionHandler.kt Maven / Gradle / Ivy

Go to download

A Kotlin-first (and Java) framework that makes creating Discord bots a piece of cake, using the JDA library.

There is a newer version: 3.0.0-alpha.18
Show newest version
package io.github.freya022.botcommands.api.commands.text

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.message.MessageReceivedEvent

/**
 * Processes text command rejections returned by [text command filters][TextCommandFilter].
 *
 * ### Requirements
 * - Register your instance as a service with [@BService][BService].
 * - Implement either [handle] (Java) or [handleSuspend] (Kotlin).
 *
 * ### Example - Replying the error string returned by the [TextCommandFilter] example
 * ```kt
 * @BService
 * class MyTextCommandRejectionHandler : TextCommandRejectionHandler, ApplicationCommandRejectionHandler {
 *     override suspend fun handleSuspend(event: MessageReceivedEvent, variation: TextCommandVariation, args: String, userData: String) {
 *         event.message.reply(userData).await()
 *     }
 * }
 * ```
 *
 * 
* * ```java * @BService * public class MyTextCommandRejectionHandler implements TextCommandRejectionHandler { * @Override * public void handle(@NotNull MessageReceivedEvent event, @NotNull TextCommandVariation variation, @NotNull String args, @NotNull String userData) { * event.getMessage().reply(userData).queue(); * } * } * ``` * * @param T Type of the error object returned by [TextCommandFilter] * * @see TextCommandFilter */ @InterfacedService(acceptMultiple = false) interface TextCommandRejectionHandler { @JvmSynthetic suspend fun handleSuspend(event: MessageReceivedEvent, variation: TextCommandVariation, args: String, userData: T): Unit = handle(event, variation, args, userData) fun handle(event: MessageReceivedEvent, variation: TextCommandVariation, args: String, userData: T): Unit = throw NotImplementedError("${this.javaClass.simpleNestedName} must implement the 'handle' or 'handleSuspend' method") }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy