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

com.justai.jaicf.helpers.action.Generic.kt Maven / Gradle / Ivy

Go to download

JAICF-Kotlin Core component. Provides DSL, Tests API and multiple implementable interfaces.

There is a newer version: 1.3.8
Show newest version
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