1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

BehaviourContext now is interface

This commit is contained in:
InsanusMokrassar 2021-06-28 10:29:45 +06:00
parent 77dff639f0
commit 21c5d42dc2
2 changed files with 44 additions and 8 deletions

View File

@ -11,6 +11,8 @@
* All triggers (`on*` extensions) have been modified to work in parallel by default (new parameter * All triggers (`on*` extensions) have been modified to work in parallel by default (new parameter
`performInParallel`, by default `true`) `performInParallel`, by default `true`)
* All behaviour builder extensions got new parameter `defaultExceptionsHandler` * All behaviour builder extensions got new parameter `defaultExceptionsHandler`
* Class `BehaviourContext` was rewritten as an interface with default realization `DefaultBehaviourContext` and
factory `BehaviourContext(TelegramBot, CoroutineScope, FlowsUpdatesFilter)`
* `API`: * `API`:
* All `reply` and subsequent extension have been replaced in send package * All `reply` and subsequent extension have been replaced in send package
* `Bot API 5.3`: * `Bot API 5.3`:

View File

@ -14,15 +14,49 @@ typealias BehaviourContextAndTypeReceiver<T, I> = suspend BehaviourContext.(I) -
/** /**
* This class contains all necessary tools for work with bots and especially for [buildBehaviour] * This class contains all necessary tools for work with bots and especially for [buildBehaviour]
* *
* @param scope This param will be used for creating of some subscriptions inside of methods, updates listening and * @see DefaultBehaviourContext
* different other things in context of working with [CoroutineScope] and coroutines.
* @param flowsUpdatesFilter This parameter will be used to subscribe on different types of update
*/ */
data class BehaviourContext( interface BehaviourContext : FlowsUpdatesFilter, TelegramBot, CoroutineScope {
val bot: TelegramBot, val bot: TelegramBot
val scope: CoroutineScope, get() = this
val flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter()
) : FlowsUpdatesFilter by flowsUpdatesFilter, TelegramBot by bot, CoroutineScope by scope /**
* Will be used for creating of some subscriptions inside of methods, updates listening and different other things
* in context of working with [CoroutineScope] and coroutines.
*/
val scope: CoroutineScope
get() = this
/**
* This parameter will be used to subscribe on different types of update
*/
val flowsUpdatesFilter: FlowsUpdatesFilter
get() = this
fun copy(
bot: TelegramBot = this.bot,
scope: CoroutineScope = this.scope,
flowsUpdatesFilter: FlowsUpdatesFilter = this.flowsUpdatesFilter
): BehaviourContext
}
class DefaultBehaviourContext(
override val bot: TelegramBot,
override val scope: CoroutineScope,
override val flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter()
) : FlowsUpdatesFilter by flowsUpdatesFilter, TelegramBot by bot, CoroutineScope by scope, BehaviourContext {
override fun copy(
bot: TelegramBot,
scope: CoroutineScope,
flowsUpdatesFilter: FlowsUpdatesFilter
): DefaultBehaviourContext = DefaultBehaviourContext(bot, scope, flowsUpdatesFilter)
}
fun BehaviourContext(
bot: TelegramBot,
scope: CoroutineScope,
flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter()
) = DefaultBehaviourContext(bot, scope, flowsUpdatesFilter)
/** /**
* Creates new one [BehaviourContext], adding subsequent [FlowsUpdatesFilter] in case [newFlowsUpdatesFilterSetUp] is provided and * Creates new one [BehaviourContext], adding subsequent [FlowsUpdatesFilter] in case [newFlowsUpdatesFilterSetUp] is provided and