1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-25 03:28:44 +00:00

buildBehaciour returns BehaviourContext

This commit is contained in:
InsanusMokrassar 2022-05-16 18:58:19 +06:00
parent f1be8bf16e
commit 9d40e598f1
2 changed files with 23 additions and 22 deletions

View File

@ -2,6 +2,9 @@
## 1.1.1 ## 1.1.1
* `Behaviour Builder`:
* Extension `TelegramBot#buildBehaviour` now returns `BehaviourContext`
## 1.1.0 ## 1.1.0
* `Utils`: * `Utils`:

View File

@ -7,8 +7,7 @@ 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.startGettingOfUpdatesByLongPolling
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
import dev.inmo.tgbotapi.utils.PreviewFeature import dev.inmo.tgbotapi.utils.PreviewFeature
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.*
import kotlinx.coroutines.plus
/** /**
* This function is used in [buildBehaviour] extensions to provide default [CoroutineScope] and allow to avoid all * This function is used in [buildBehaviour] extensions to provide default [CoroutineScope] and allow to avoid all
@ -30,8 +29,7 @@ suspend fun TelegramBot.buildBehaviour(
scope: CoroutineScope = defaultCoroutineScopeProvider(), scope: CoroutineScope = defaultCoroutineScopeProvider(),
defaultExceptionsHandler: ExceptionHandler<Unit>? = null, defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
block: BehaviourContextReceiver<Unit> block: BehaviourContextReceiver<Unit>
) { ): BehaviourContext = BehaviourContext(
BehaviourContext(
this, this,
scope.let { scope.let {
if (defaultExceptionsHandler == null) { if (defaultExceptionsHandler == null) {
@ -41,7 +39,8 @@ suspend fun TelegramBot.buildBehaviour(
} }
}, },
flowUpdatesFilter flowUpdatesFilter
).block() ).apply {
block()
} }
/** /**
@ -56,15 +55,14 @@ suspend fun TelegramBot.buildBehaviourWithLongPolling(
scope: CoroutineScope = defaultCoroutineScopeProvider(), scope: CoroutineScope = defaultCoroutineScopeProvider(),
defaultExceptionsHandler: ExceptionHandler<Unit>? = null, defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
block: BehaviourContextReceiver<Unit> block: BehaviourContextReceiver<Unit>
) = FlowsUpdatesFilter().let { ): Job {
buildBehaviour( val behaviourContext = buildBehaviour(
it, scope = scope,
scope, defaultExceptionsHandler = defaultExceptionsHandler,
defaultExceptionsHandler, block = block
block
) )
longPolling( return longPolling(
it, behaviourContext,
scope = scope scope = scope
) )
} }