![JAR search and dependency download from the Maven repository](/logo.png)
com.justai.jaicf.helpers.action.Generic.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
JAICF-Kotlin Core component. Provides DSL, Tests API and multiple implementable interfaces.
package com.justai.jaicf.helpers.action
import com.justai.jaicf.api.BotRequest
import com.justai.jaicf.context.ActionContext
import com.justai.jaicf.context.ActivatorContext
import com.justai.jaicf.context.DefaultActionContext
import com.justai.jaicf.generic.ActivatorTypeToken
import com.justai.jaicf.generic.ChannelTypeToken
import com.justai.jaicf.generic.ContextTypeToken
import com.justai.jaicf.reactions.Reactions
fun DefaultActionContext.ofType(activatorToken: ActivatorTypeToken<*>): Boolean =
activatorToken.isInstance(activator)
fun DefaultActionContext.ofType(channelToken: ChannelTypeToken<*, *>): Boolean =
channelToken.isInstance(request) && channelToken.isInstance(reactions)
fun DefaultActionContext.ofType(contextToken: ContextTypeToken<*, *, *>): Boolean =
contextToken.isInstance(activator) && contextToken.isInstance(request) && contextToken.isInstance(reactions)
@Suppress("UNCHECKED_CAST", "UNUSED_PARAMETER")
fun ActionContext.cast(
activatorToken: ActivatorTypeToken
): ActionContext = this as ActionContext
@Suppress("UNCHECKED_CAST", "UNUSED_PARAMETER")
fun ActionContext.cast(
channelToken: ChannelTypeToken
): ActionContext = this as ActionContext
@Suppress("UNCHECKED_CAST", "UNUSED_PARAMETER")
fun ActionContext.cast(
contextToken: ContextTypeToken
): ActionContext = this as ActionContext
@Suppress("UNCHECKED_CAST")
fun ActionContext.safeCast(
activatorToken: ActivatorTypeToken
): ActionContext? = if (ofType(activatorToken)) cast(activatorToken) else null
@Suppress("UNCHECKED_CAST")
fun ActionContext.safeCast(
channelToken: ChannelTypeToken
): ActionContext? = if (ofType(channelToken)) cast(channelToken) else null
@Suppress("UNCHECKED_CAST")
fun ActionContext.safeCast(
contextToken: ContextTypeToken
): ActionContext? = if (ofType(contextToken)) cast(contextToken) else null
© 2015 - 2025 Weber Informatics LLC | Privacy Policy