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

io.github.freya022.botcommands.internal.components.timeout.TimeoutDescriptor.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.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 } }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy