mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
complete fix of issue with subcontexts
This commit is contained in:
parent
89d13de307
commit
3e3adab46b
@ -147,6 +147,26 @@ class DefaultBehaviourContextWithFSM<T : State>(
|
||||
launch { statePerformer(it) }
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Add NON STRICT [handler] to list of available in future [BehaviourContextWithFSM]. Non strict means that
|
||||
* for input [State] will be used [KClass.isInstance] and any inheritor of [kClass] will pass this requirement
|
||||
*
|
||||
* @see BehaviourWithFSMStateHandlerHolder
|
||||
* @see BehaviourContextWithFSM.add
|
||||
*/
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
inline fun <reified I : T> onStateOrSubstate(handler: BehaviourWithFSMStateHandler<I, T>) = add(I::class, strict = false, handler)
|
||||
|
||||
/**
|
||||
* Add STRICT [handler] to list of available in future [BehaviourContextWithFSM]. Strict means that
|
||||
* for input [State] will be used [State]::class == [kClass] and any [State] with exactly the same type will pass
|
||||
* requirements
|
||||
*
|
||||
* @see BehaviourWithFSMStateHandlerHolder
|
||||
* @see BehaviourContextWithFSM.addStrict
|
||||
*/
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
inline fun <reified I : T> strictlyOn(handler: BehaviourWithFSMStateHandler<I, T>) = addStrict(I::class, handler)
|
||||
|
||||
override suspend fun startChain(state: T) {
|
||||
statesManager.startChain(state)
|
||||
|
@ -33,8 +33,8 @@ suspend fun <T : State> TelegramBot.buildBehaviourWithFSM(
|
||||
defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
|
||||
statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
|
||||
presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*, T>> = mutableListOf(),
|
||||
block: CustomBehaviourContextReceiver<BehaviourContextWithFSM<T>, Unit>
|
||||
): BehaviourContextWithFSM<T> = BehaviourContextWithFSM(
|
||||
block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit>
|
||||
): DefaultBehaviourContextWithFSM<T> = BehaviourContextWithFSM(
|
||||
DefaultBehaviourContext(
|
||||
this,
|
||||
defaultExceptionsHandler ?.let { scope + ContextSafelyExceptionHandler(it) } ?: scope,
|
||||
@ -55,8 +55,8 @@ suspend fun <T : State> TelegramBot.buildBehaviourWithFSMAndStartLongPolling(
|
||||
defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
|
||||
statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
|
||||
presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*, T>> = mutableListOf(),
|
||||
block: CustomBehaviourContextReceiver<BehaviourContextWithFSM<T>, Unit>
|
||||
): Pair<BehaviourContextWithFSM<T>, Job> = buildBehaviourWithFSM(
|
||||
block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit>
|
||||
): Pair<DefaultBehaviourContextWithFSM<T>, Job> = buildBehaviourWithFSM(
|
||||
upstreamUpdatesFlow,
|
||||
scope,
|
||||
defaultExceptionsHandler,
|
||||
@ -95,8 +95,8 @@ suspend fun <T : State> TelegramBot.buildBehaviourWithFSM(
|
||||
defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
|
||||
statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
|
||||
presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*, T>> = mutableListOf(),
|
||||
block: CustomBehaviourContextReceiver<BehaviourContextWithFSM<T>, Unit>
|
||||
): BehaviourContextWithFSM<T> = BehaviourContextWithFSM(
|
||||
block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit>
|
||||
): DefaultBehaviourContextWithFSM<T> = BehaviourContextWithFSM(
|
||||
DefaultBehaviourContext(
|
||||
this,
|
||||
defaultExceptionsHandler ?.let { scope + ContextSafelyExceptionHandler(it) } ?: scope,
|
||||
@ -123,7 +123,7 @@ suspend fun <T : State> TelegramBot.buildBehaviourWithFSMAndStartLongPolling(
|
||||
defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
|
||||
statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
|
||||
presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*, T>> = mutableListOf(),
|
||||
block: CustomBehaviourContextReceiver<BehaviourContextWithFSM<T>, Unit>
|
||||
block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit>
|
||||
) = FlowsUpdatesFilter().let {
|
||||
buildBehaviourWithFSM(
|
||||
it,
|
||||
|
@ -39,7 +39,7 @@ suspend fun <T : State> telegramBotWithBehaviourAndFSM(
|
||||
statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
|
||||
presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*, T>> = mutableListOf(),
|
||||
testServer: Boolean = false,
|
||||
block: CustomBehaviourContextReceiver<BehaviourContextWithFSM<T>, Unit>
|
||||
block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit>
|
||||
): TelegramBot = telegramBot(
|
||||
token,
|
||||
apiUrl,
|
||||
@ -76,7 +76,7 @@ suspend fun <T : State> telegramBotWithBehaviourAndFSMAndStartLongPolling(
|
||||
statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
|
||||
presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*, T>> = mutableListOf(),
|
||||
testServer: Boolean = false,
|
||||
block: CustomBehaviourContextReceiver<BehaviourContextWithFSM<T>, Unit>
|
||||
block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit>
|
||||
): Pair<TelegramBot, Job> {
|
||||
return telegramBot(
|
||||
token,
|
||||
|
Loading…
Reference in New Issue
Block a user