mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 00:27:14 +00:00
start including context data in BehaviourContext
This commit is contained in:
parent
082aeab700
commit
3658403f01
@ -1,16 +1,13 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder
|
||||
|
||||
import dev.inmo.kslog.common.e
|
||||
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.extensions.DefaultKTgBotAPIPrivacyCommand
|
||||
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
|
||||
import dev.inmo.tgbotapi.types.Seconds
|
||||
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
|
||||
import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
/**
|
||||
|
@ -52,6 +52,8 @@ interface BehaviourContext : FlowsUpdatesFilter, TelegramBot, CoroutineScope {
|
||||
|
||||
val triggersHolder: TriggersHolder
|
||||
|
||||
val data: BehaviourContextData
|
||||
|
||||
fun copy(
|
||||
bot: TelegramBot = this.bot,
|
||||
scope: CoroutineScope = this.scope,
|
||||
@ -92,6 +94,8 @@ class DefaultBehaviourContext(
|
||||
}.accumulatorFlow(WeakScope(scope))
|
||||
override val asUpdateReceiver: UpdateReceiver<Update> = additionalUpdatesSharedFlow::emit
|
||||
|
||||
override val data: BehaviourContextData = BehaviourContextData()
|
||||
|
||||
override fun copy(
|
||||
bot: TelegramBot,
|
||||
scope: CoroutineScope,
|
||||
|
@ -0,0 +1,13 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder
|
||||
|
||||
data class BehaviourContextData(
|
||||
val data: MutableMap<String, Any?> = mutableMapOf()
|
||||
) {
|
||||
fun mergedWith(other: BehaviourContextData): BehaviourContextData = BehaviourContextData(
|
||||
data.toMutableMap().apply {
|
||||
putAll(other.data)
|
||||
}
|
||||
)
|
||||
|
||||
operator fun plus(other: BehaviourContextData): BehaviourContextData = mergedWith(other)
|
||||
}
|
Loading…
Reference in New Issue
Block a user