io.github.freya022.botcommands.internal.components.timeout.TimeoutDescriptor.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.internal.components.timeout
import io.github.freya022.botcommands.api.commands.builder.CustomOptionBuilder
import io.github.freya022.botcommands.internal.IExecutableInteractionInfo
import io.github.freya022.botcommands.internal.core.BContextImpl
import io.github.freya022.botcommands.internal.core.options.OptionType
import io.github.freya022.botcommands.internal.core.reflection.MemberParamFunction
import io.github.freya022.botcommands.internal.parameters.OptionParameter
import io.github.freya022.botcommands.internal.transformParameters
import kotlin.reflect.KClass
import kotlin.reflect.jvm.jvmErasure
internal class TimeoutDescriptor internal constructor(
context: BContextImpl,
override val eventFunction: MemberParamFunction,
aggregatorFirstParamType: KClass
) : IExecutableInteractionInfo {
override val parameters: List
init {
parameters = eventFunction.transformParameters(
builderBlock = { function, parameter, declaredName ->
when (context.serviceContainer.canCreateService(parameter.type.jvmErasure)) {
//No error => is a service
null -> CustomOptionBuilder(OptionParameter.fromSelfAggregate(function, declaredName))
else -> TimeoutHandlerOptionBuilder(OptionParameter.fromSelfAggregate(function, declaredName))
}
},
aggregateBlock = { TimeoutHandlerParameter(context, it, aggregatorFirstParamType) }
)
}
internal val optionSize = parameters.sumOf { p -> p.allOptions.count { o -> o.optionType == OptionType.OPTION } }
}