
com.freya02.botcommands.internal.components.ComponentDescriptor.kt Maven / Gradle / Ivy
package com.freya02.botcommands.internal.components
import com.freya02.botcommands.api.commands.builder.CustomOptionBuilder
import com.freya02.botcommands.internal.BContextImpl
import com.freya02.botcommands.internal.IExecutableInteractionInfo
import com.freya02.botcommands.internal.core.reflection.MemberEventFunction
import com.freya02.botcommands.internal.parameters.OptionParameter
import com.freya02.botcommands.internal.transformParameters
import com.freya02.botcommands.internal.utils.ReflectionUtils.nonInstanceParameters
import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteractionCreateEvent
import kotlin.reflect.jvm.jvmErasure
class ComponentDescriptor(
context: BContextImpl,
override val eventFunction: MemberEventFunction
) : IExecutableInteractionInfo {
override val parameters: List
init {
parameters = function.nonInstanceParameters.drop(1).transformParameters(
builderBlock = { function, parameter, declaredName ->
when (context.serviceContainer.canCreateService(parameter.type.jvmErasure)) {
//No error => is a service
null -> CustomOptionBuilder(OptionParameter.fromSelfAggregate(function, declaredName))
else -> ComponentHandlerOptionBuilder(OptionParameter.fromSelfAggregate(function, declaredName))
}
},
aggregateBlock = { ComponentHandlerParameter(context, it) }
)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy