io.github.freya022.botcommands.api.parameters.resolvers.MessageContextParameterResolver.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.parameters.resolvers
import io.github.freya022.botcommands.api.commands.application.context.annotations.JDAMessageCommand
import io.github.freya022.botcommands.api.parameters.ParameterResolver
import io.github.freya022.botcommands.internal.commands.application.context.message.MessageCommandInfo
import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent
import kotlin.reflect.KParameter
import kotlin.reflect.KType
/**
* Parameter resolver for parameters of [@JDAMessageCommand][JDAMessageCommand].
*
* Needs to be implemented alongside a [ParameterResolver] subclass.
*
* @param T Type of the implementation
* @param R Type of the returned resolved objects
*/
interface MessageContextParameterResolver where T : ParameterResolver,
T : MessageContextParameterResolver {
/**
* Returns a resolved object from this message context interaction.
*
* If this returns `null`, and the parameter is required, i.e., not [nullable][KType.isMarkedNullable]
* or [optional][KParameter.isOptional], then the handler will throw.
*
* @param info The data of the command being executed
* @param event The corresponding event
*/
fun resolve(info: MessageCommandInfo, event: MessageContextInteractionEvent): R? =
throw NotImplementedError("${this.javaClass.simpleName} must implement the 'resolve' or 'resolveSuspend' method")
/**
* Returns a resolved object from this message context interaction.
*
* If this returns `null`, and the parameter is required, i.e., not [nullable][KType.isMarkedNullable]
* or [optional][KParameter.isOptional], then the handler will throw.
*
* @param info The data of the command being executed
* @param event The corresponding event
*/
@JvmSynthetic
suspend fun resolveSuspend(info: MessageCommandInfo, event: MessageContextInteractionEvent) =
resolve(info, event)
}