diff --git a/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSMBuilder.kt b/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSMBuilder.kt index 3a17d1bc3c..143815c151 100644 --- a/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSMBuilder.kt +++ b/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSMBuilder.kt @@ -7,7 +7,6 @@ import dev.inmo.micro_utils.fsm.common.managers.InMemoryDefaultStatesManagerRepo import dev.inmo.micro_utils.fsm.common.utils.StateHandlingErrorHandler import dev.inmo.micro_utils.fsm.common.utils.defaultStateHandlingErrorHandler import dev.inmo.tgbotapi.bot.TelegramBot -import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.optionallyWithDefaultReceiver import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.updateHandlerWithMediaGroupsAdaptation import dev.inmo.tgbotapi.types.Seconds @@ -15,6 +14,7 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter import kotlinx.coroutines.* import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.emptyFlow /** * Creates [BehaviourContextWithFSM] via creating of [DefaultBehaviourContext] with [this] as [TelegramBot], @@ -39,11 +39,12 @@ suspend fun TelegramBot.buildBehaviourWithFSM( useDefaultSubcontextInitialAction: Boolean = true, block: CustomBehaviourContextReceiver, Unit> ): DefaultBehaviourContextWithFSM = BehaviourContextWithFSM( - behaviourContext = DefaultBehaviourContext( + behaviourContext = BehaviourContext( bot = this, scope = defaultExceptionsHandler ?.let { scope + ContextSafelyExceptionHandler(it) } ?: scope, - upstreamUpdatesFlow = upstreamUpdatesFlow, - subcontextInitialAction = subcontextInitialAction.optionallyWithDefaultReceiver(useDefaultSubcontextInitialAction) + upstreamUpdatesFlow = upstreamUpdatesFlow ?: emptyFlow(), + useDefaultSubcontextInitialAction = useDefaultSubcontextInitialAction, + subcontextInitialAction = subcontextInitialAction ), handlers = presetHandlers, statesManager = statesManager, @@ -127,11 +128,12 @@ suspend fun TelegramBot.buildBehaviourWithFSM( useDefaultSubcontextInitialAction: Boolean = true, block: CustomBehaviourContextReceiver, Unit> ): DefaultBehaviourContextWithFSM = BehaviourContextWithFSM( - DefaultBehaviourContext( + BehaviourContext( this, defaultExceptionsHandler ?.let { scope + ContextSafelyExceptionHandler(it) } ?: scope, upstreamUpdatesFlow = flowUpdatesFilter.allUpdatesFlow, - subcontextInitialAction = subcontextInitialAction.optionallyWithDefaultReceiver(useDefaultSubcontextInitialAction) + subcontextInitialAction = subcontextInitialAction, + useDefaultSubcontextInitialAction = useDefaultSubcontextInitialAction ), presetHandlers, statesManager, diff --git a/tgbotapi.behaviour_builder/api/tgbotapi.behaviour_builder.api b/tgbotapi.behaviour_builder/api/tgbotapi.behaviour_builder.api index 7815ab4b16..3d98dcfdf4 100644 --- a/tgbotapi.behaviour_builder/api/tgbotapi.behaviour_builder.api +++ b/tgbotapi.behaviour_builder/api/tgbotapi.behaviour_builder.api @@ -66,8 +66,12 @@ public final class dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourConte public final class dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextKt { public static final fun BehaviourContext (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlinx/coroutines/CoroutineScope;Ldev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlin/jvm/functions/Function3;ZLkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun BehaviourContext (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlinx/coroutines/CoroutineScope;Ldev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;ZLkotlin/jvm/functions/Function3;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/DefaultBehaviourContext; + public static final fun BehaviourContext (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlinx/coroutines/CoroutineScope;Lkotlinx/coroutines/flow/Flow;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlin/jvm/functions/Function3;ZLkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun BehaviourContext (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlinx/coroutines/CoroutineScope;Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function3;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Z)Ldev/inmo/tgbotapi/extensions/behaviour_builder/DefaultBehaviourContext; public static synthetic fun BehaviourContext$default (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlinx/coroutines/CoroutineScope;Ldev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlin/jvm/functions/Function3;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/Object; public static synthetic fun BehaviourContext$default (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlinx/coroutines/CoroutineScope;Ldev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;ZLkotlin/jvm/functions/Function3;ILjava/lang/Object;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/DefaultBehaviourContext; + public static synthetic fun BehaviourContext$default (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlinx/coroutines/CoroutineScope;Lkotlinx/coroutines/flow/Flow;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlin/jvm/functions/Function3;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/Object; + public static synthetic fun BehaviourContext$default (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlinx/coroutines/CoroutineScope;Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function3;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;ZILjava/lang/Object;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/DefaultBehaviourContext; public static final fun BehaviourContextAndTwoTypesReceiver (Lkotlin/jvm/functions/Function4;)Lkotlin/jvm/functions/Function4; public static final fun BehaviourContextAndTypeReceiver (Lkotlin/jvm/functions/Function3;)Lkotlin/jvm/functions/Function3; public static final fun BehaviourContextReceiver (Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2; @@ -111,8 +115,8 @@ public final class dev/inmo/tgbotapi/extensions/behaviour_builder/CombinedSubcon } public final class dev/inmo/tgbotapi/extensions/behaviour_builder/DefaultBehaviourContext : dev/inmo/tgbotapi/updateshandlers/AbstractFlowsUpdatesFilter, dev/inmo/tgbotapi/bot/RequestsExecutor, dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext, kotlinx/coroutines/CoroutineScope { - public fun (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlinx/coroutines/CoroutineScope;ILkotlinx/coroutines/channels/BufferOverflow;Lkotlinx/coroutines/flow/Flow;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlin/jvm/functions/Function3;)V - public synthetic fun (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlinx/coroutines/CoroutineScope;ILkotlinx/coroutines/channels/BufferOverflow;Lkotlinx/coroutines/flow/Flow;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlin/jvm/functions/Function3;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlinx/coroutines/CoroutineScope;ILkotlinx/coroutines/channels/BufferOverflow;Lkotlinx/coroutines/flow/Flow;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextData;Lkotlin/jvm/functions/Function3;)V + public synthetic fun (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlinx/coroutines/CoroutineScope;ILkotlinx/coroutines/channels/BufferOverflow;Lkotlinx/coroutines/flow/Flow;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextData;Lkotlin/jvm/functions/Function3;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun close ()V public synthetic fun copy (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlinx/coroutines/CoroutineScope;ILkotlinx/coroutines/channels/BufferOverflow;Lkotlinx/coroutines/flow/Flow;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlin/jvm/functions/Function3;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext; public fun copy (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlinx/coroutines/CoroutineScope;ILkotlinx/coroutines/channels/BufferOverflow;Lkotlinx/coroutines/flow/Flow;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlin/jvm/functions/Function3;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/DefaultBehaviourContext; @@ -1593,6 +1597,7 @@ public final class dev/inmo/tgbotapi/extensions/behaviour_builder/utils/DefaultC public static final field Companion Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/DefaultCustomBehaviourContextAndTypeReceiver$Companion; public fun (Lkotlin/jvm/functions/Function3;)V public fun invoke (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/types/update/abstracts/Update;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun invoke (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextData;)V public synthetic fun invoke (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; } @@ -1605,8 +1610,8 @@ public abstract interface class dev/inmo/tgbotapi/extensions/behaviour_builder/u public final class dev/inmo/tgbotapi/extensions/behaviour_builder/utils/DefaultCustomBehaviourContextAndTypeReceiverKt { public static final fun botInfo (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun optionallyWithDefaultReceiver (Lkotlin/jvm/functions/Function3;Z)Lkotlin/jvm/functions/Function3; - public static final fun withDefaultReceiver (Lkotlin/jvm/functions/Function3;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/DefaultCustomBehaviourContextAndTypeReceiver; + public static final fun optionallyWithDefaultReceiver (Lkotlin/jvm/functions/Function3;ZLdev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextData;)Lkotlin/jvm/functions/Function3; + public static final fun withDefaultReceiver (Lkotlin/jvm/functions/Function3;Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextData;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/DefaultCustomBehaviourContextAndTypeReceiver; } public final class dev/inmo/tgbotapi/extensions/behaviour_builder/utils/LiveLocationKt { diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourBuilders.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourBuilders.kt index b2f7bc2179..38ae9a9d66 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourBuilders.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourBuilders.kt @@ -4,6 +4,7 @@ import dev.inmo.micro_utils.coroutines.ContextSafelyExceptionHandler import dev.inmo.micro_utils.coroutines.ExceptionHandler import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.DefaultCustomBehaviourContextAndTypeReceiver +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.optionallyWithDefaultReceiver import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.updateHandlerWithMediaGroupsAdaptation @@ -44,11 +45,8 @@ suspend fun TelegramBot.buildBehaviour( } }, flowsUpdatesFilter = flowUpdatesFilter, - subcontextInitialAction = if (useDefaultSubcontextInitialAction) { - DefaultCustomBehaviourContextAndTypeReceiver(subcontextInitialAction) - } else { - subcontextInitialAction - } + useDefaultSubcontextInitialAction = useDefaultSubcontextInitialAction, + subcontextInitialAction = subcontextInitialAction ).apply { block() } diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt index 84bb692db1..f3f0b499bc 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt @@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder -import dev.inmo.kslog.common.KSLog import dev.inmo.micro_utils.coroutines.* import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.handlers_registrar.TriggersHolder @@ -84,6 +83,7 @@ class DefaultBehaviourContext( onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND, private val upstreamUpdatesFlow: Flow? = null, override val triggersHolder: TriggersHolder = TriggersHolder(), + override val data: BehaviourContextData = BehaviourContextData(), override val subcontextInitialAction: CustomBehaviourContextAndTypeReceiver = {} ) : AbstractFlowsUpdatesFilter(), TelegramBot by bot, CoroutineScope by scope, BehaviourContext { @@ -108,8 +108,6 @@ class DefaultBehaviourContext( }.accumulatorFlow(WeakScope(scope)) override val asUpdateReceiver: UpdateReceiver = additionalUpdatesSharedFlow::emit - override val data: BehaviourContextData = BehaviourContextData() - override fun copy( bot: TelegramBot, scope: CoroutineScope, @@ -138,13 +136,17 @@ fun BehaviourContext( triggersHolder: TriggersHolder = TriggersHolder(), useDefaultSubcontextInitialAction: Boolean = true, subcontextInitialAction: CustomBehaviourContextAndTypeReceiver = {} -) = DefaultBehaviourContext( - bot = bot, - scope = scope, - upstreamUpdatesFlow = flowsUpdatesFilter.allUpdatesFlow, - triggersHolder = triggersHolder, - subcontextInitialAction = subcontextInitialAction.optionallyWithDefaultReceiver(useDefaultSubcontextInitialAction) -) +): DefaultBehaviourContext { + val data = BehaviourContextData() + return DefaultBehaviourContext( + bot = bot, + scope = scope, + upstreamUpdatesFlow = flowsUpdatesFilter.allUpdatesFlow, + triggersHolder = triggersHolder, + data = data, + subcontextInitialAction = subcontextInitialAction.optionallyWithDefaultReceiver(useDefaultSubcontextInitialAction, data) + ) +} inline fun BehaviourContext( bot: TelegramBot, @@ -154,13 +156,56 @@ inline fun BehaviourContext( noinline subcontextInitialAction: CustomBehaviourContextAndTypeReceiver = {}, useDefaultSubcontextInitialAction: Boolean = true, crossinline block: BehaviourContext.() -> T -) = DefaultBehaviourContext( - bot = bot, - scope = scope, - upstreamUpdatesFlow = flowsUpdatesFilter.allUpdatesFlow, - triggersHolder = triggersHolder, - subcontextInitialAction = subcontextInitialAction.optionallyWithDefaultReceiver(useDefaultSubcontextInitialAction) -).run(block) +): T { + val data = BehaviourContextData() + return DefaultBehaviourContext( + bot = bot, + scope = scope, + upstreamUpdatesFlow = flowsUpdatesFilter.allUpdatesFlow, + triggersHolder = triggersHolder, + data = data, + subcontextInitialAction = subcontextInitialAction.optionallyWithDefaultReceiver(useDefaultSubcontextInitialAction, data) + ).run(block) +} + +inline fun BehaviourContext( + bot: TelegramBot, + scope: CoroutineScope, + upstreamUpdatesFlow: Flow, + triggersHolder: TriggersHolder = TriggersHolder(), + noinline subcontextInitialAction: CustomBehaviourContextAndTypeReceiver = {}, + useDefaultSubcontextInitialAction: Boolean = true, + crossinline block: BehaviourContext.() -> T +): T { + val data = BehaviourContextData() + return DefaultBehaviourContext( + bot = bot, + scope = scope, + upstreamUpdatesFlow = upstreamUpdatesFlow, + triggersHolder = triggersHolder, + data = data, + subcontextInitialAction = subcontextInitialAction.optionallyWithDefaultReceiver(useDefaultSubcontextInitialAction, data) + ).run(block) +} + +fun BehaviourContext( + bot: TelegramBot, + scope: CoroutineScope, + upstreamUpdatesFlow: Flow, + subcontextInitialAction: CustomBehaviourContextAndTypeReceiver, + triggersHolder: TriggersHolder = TriggersHolder(), + useDefaultSubcontextInitialAction: Boolean = true +): DefaultBehaviourContext { + val data = BehaviourContextData() + return DefaultBehaviourContext( + bot = bot, + scope = scope, + upstreamUpdatesFlow = upstreamUpdatesFlow, + triggersHolder = triggersHolder, + data = data, + subcontextInitialAction = subcontextInitialAction.optionallyWithDefaultReceiver(useDefaultSubcontextInitialAction, data) + ) +} /** * Creates new [BehaviourContext] using its [BehaviourContext.copy] method @@ -183,7 +228,7 @@ fun BC.createSubContext( ) as BC /** - * Launch [behaviourContextReceiver] in context of [this] as [BehaviourContext] and as [kotlin.coroutines.CoroutineContext] + * Launch [behaviourContextReceiver] in context of [this] as [BehaviourContext] and as [CoroutineContext] * * [this] [BehaviourContext] will **NOT** be closed automatically */ @@ -196,7 +241,7 @@ suspend fun BC.doInContext( } /** - * Launch [behaviourContextReceiver] in context of [this] as [BehaviourContext] and as [kotlin.coroutines.CoroutineContext] + * Launch [behaviourContextReceiver] in context of [this] as [BehaviourContext] and as [CoroutineContext] * * [this] [BehaviourContext] will **NOT** be closed automatically */ @@ -218,7 +263,7 @@ suspend fun BC.doInNewSubContext( } /** - * Launch [behaviourContextReceiver] in context of [this] as [BehaviourContext] and as [kotlin.coroutines.CoroutineContext] + * Launch [behaviourContextReceiver] in context of [this] as [BehaviourContext] and as [CoroutineContext] * * [this] [BehaviourContext] will **NOT** be closed automatically */ diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/DefaultCustomBehaviourContextAndTypeReceiver.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/DefaultCustomBehaviourContextAndTypeReceiver.kt index fd09aa9cae..99cc4395fd 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/DefaultCustomBehaviourContextAndTypeReceiver.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/DefaultCustomBehaviourContextAndTypeReceiver.kt @@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.utils import dev.inmo.micro_utils.common.Warning import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextData import dev.inmo.tgbotapi.extensions.behaviour_builder.CustomBehaviourContextAndTypeReceiver import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.DefaultCustomBehaviourContextAndTypeReceiver.Companion.BOT_INFO_RECEIVER import dev.inmo.tgbotapi.requests.bot.GetMe @@ -28,12 +29,17 @@ suspend fun BehaviourContext.botInfo(): ExtendedBot? { } @Warning("It is internal API and can be changed without notes") -fun CustomBehaviourContextAndTypeReceiver.withDefaultReceiver() = DefaultCustomBehaviourContextAndTypeReceiver(this) +fun CustomBehaviourContextAndTypeReceiver.withDefaultReceiver( + data: BehaviourContextData +) = DefaultCustomBehaviourContextAndTypeReceiver(this).also { + it(data) +} @Warning("It is internal API and can be changed without notes") fun CustomBehaviourContextAndTypeReceiver.optionallyWithDefaultReceiver( - include: Boolean + include: Boolean, + data: BehaviourContextData ) = if (include) { - withDefaultReceiver() + withDefaultReceiver(data) } else { this } @@ -81,6 +87,10 @@ class DefaultCustomBehaviourContextAndTypeReceiver