From 30e6f682287a5fbd2b10476f627f55352dddfbda Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 6 Jan 2021 23:21:33 +0600 Subject: [PATCH] small update of scenarios --- .../tgbotapi/extensions/steps/Scenario.kt | 6 ++--- .../extensions/steps/ScenarioBuilders.kt | 23 ++++++++++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/tgbotapi.extensions.steps/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/steps/Scenario.kt b/tgbotapi.extensions.steps/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/steps/Scenario.kt index 9524c459d1..9d34dee99f 100644 --- a/tgbotapi.extensions.steps/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/steps/Scenario.kt +++ b/tgbotapi.extensions.steps/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/steps/Scenario.kt @@ -9,8 +9,6 @@ typealias ScenarioAndTypeReceiver = suspend Scenario.(I) -> T data class Scenario( val bot: TelegramBot, - val flowsUpdatesFilter: FlowsUpdatesFilter, - val scope: CoroutineScope + val scope: CoroutineScope, + val flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter() ) - - diff --git a/tgbotapi.extensions.steps/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/steps/ScenarioBuilders.kt b/tgbotapi.extensions.steps/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/steps/ScenarioBuilders.kt index c5a1001dbd..23cdbb4bd5 100644 --- a/tgbotapi.extensions.steps/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/steps/ScenarioBuilders.kt +++ b/tgbotapi.extensions.steps/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/steps/ScenarioBuilders.kt @@ -1,17 +1,34 @@ package dev.inmo.tgbotapi.extensions.steps import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingFlowsUpdatesByLongPolling +import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter import kotlinx.coroutines.CoroutineScope suspend fun TelegramBot.buildScenarios( scope: CoroutineScope, - flowUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter(), + flowUpdatesFilter: FlowsUpdatesFilter, block: ScenarioReceiver ) { Scenario( this, - flowUpdatesFilter, - scope + scope, + flowUpdatesFilter ).block() } + +suspend fun TelegramBot.buildScenarios( + scope: CoroutineScope, + block: ScenarioReceiver +) = FlowsUpdatesFilter().also { + buildScenarios( + scope, + it, + block + ) + startGettingOfUpdatesByLongPolling( + updatesFilter = it, + scope = scope + ) +}