io.github.freya022.botcommands.internal.components.repositories.ComponentTimeoutHandlers.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.repositories
import io.github.freya022.botcommands.api.components.Components
import io.github.freya022.botcommands.api.components.annotations.ComponentTimeoutHandler
import io.github.freya022.botcommands.api.components.data.ComponentTimeoutData
import io.github.freya022.botcommands.api.core.service.annotations.BService
import io.github.freya022.botcommands.api.core.service.annotations.Dependencies
import io.github.freya022.botcommands.internal.core.reflection.MemberFunction
import io.github.freya022.botcommands.internal.core.reflection.toMemberFunction
import io.github.freya022.botcommands.internal.core.requiredFilter
import io.github.freya022.botcommands.internal.core.service.FunctionAnnotationsMap
import io.github.freya022.botcommands.internal.utils.FunctionFilter
import kotlin.reflect.full.findAnnotation
@BService
@Dependencies(Components::class)
internal class ComponentTimeoutHandlers(functionAnnotationsMap: FunctionAnnotationsMap) : HandlerContainer {
private val map: Map> =
functionAnnotationsMap.getFunctionsWithAnnotation()
.requiredFilter(FunctionFilter.nonStatic())
.requiredFilter(FunctionFilter.firstArg(ComponentTimeoutData::class))
.associate {
it.function.findAnnotation()!!.name to it.toMemberFunction()
}
override operator fun get(handlerName: String) = map[handlerName]
}