Skip to content

Commit

Permalink
start including context data in BehaviourContext
Browse files Browse the repository at this point in the history
  • Loading branch information
InsanusMokrassar committed Nov 28, 2024
1 parent 082aeab commit 3658403
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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.*

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 3658403

Please sign in to comment.