@@ -4,10 +4,23 @@ import dev.inmo.kslog.common.defaultMessageFormatter
44import dev.inmo.kslog.common.setDefaultKSLog
55import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
66import dev.inmo.tgbotapi.extensions.api.bot.getMe
7+ import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextData
8+ import dev.inmo.tgbotapi.extensions.behaviour_builder.buildSubcontextInitialAction
79import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
10+ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
11+ import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
12+ import dev.inmo.tgbotapi.types.update.abstracts.Update
813import kotlinx.coroutines.CoroutineScope
914import kotlinx.coroutines.Dispatchers
1015
16+ private var BehaviourContextData .update: Update ?
17+ get() = get(" update" ) as ? Update
18+ set(value) = set(" update" , value)
19+
20+ private var BehaviourContextData .commonMessage: CommonMessage <* >?
21+ get() = get(" commonMessage" ) as ? CommonMessage <* >
22+ set(value) = set(" commonMessage" , value)
23+
1124/* *
1225 * This place can be the playground for your code.
1326 */
@@ -38,12 +51,32 @@ suspend fun main(vararg args: String) {
3851 }
3952 }
4053 }
54+ },
55+ subcontextInitialAction = buildSubcontextInitialAction {
56+ add {
57+ data.update = it
58+ }
4159 }
4260 ) {
4361 // start here!!
4462 val me = getMe()
4563 println (me)
4664
65+ onCommand(" start" ) {
66+ println (data.update)
67+ println (data.commonMessage)
68+ }
69+
70+ onCommand(
71+ " additional_command" ,
72+ additionalSubcontextInitialAction = { update, commonMessage ->
73+ data.commonMessage = commonMessage
74+ }
75+ ) {
76+ println (data.update)
77+ println (data.commonMessage)
78+ }
79+
4780 allUpdatesFlow.subscribeSafelyWithoutExceptions(this ) {
4881 println (it)
4982 }
0 commit comments