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:
parent
f1be8bf16e
commit
9d40e598f1
@ -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`:
|
||||||
|
@ -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,18 +29,18 @@ 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) {
|
it
|
||||||
it
|
} else {
|
||||||
} else {
|
it + ContextSafelyExceptionHandler(defaultExceptionsHandler)
|
||||||
it + ContextSafelyExceptionHandler(defaultExceptionsHandler)
|
}
|
||||||
}
|
},
|
||||||
},
|
flowUpdatesFilter
|
||||||
flowUpdatesFilter
|
).apply {
|
||||||
).block()
|
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
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user