From 6c39dc4d064be365cac53b16ff28026225fe5c3f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 8 Apr 2020 10:44:44 +0600 Subject: [PATCH] new startGettingOfUpdates extension --- CHANGELOG.md | 3 +++ .../extensions/api/updates/UpdatesPolling.kt | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f36474d50..3cd1e87da4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,9 @@ ### 0.26.2 +* `TelegramBotAPI-extensions-api`: + * `startGettingOfUpdates` extension which not require filter (but return a new one) was added + ### 0.26.1 * `TelegramBotAPI`: diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt index fe2fba5f2e..bdc3e64455 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt @@ -10,6 +10,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.update.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.* +import com.github.insanusmokrassar.TelegramBotAPI.utils.PreviewFeature import io.ktor.client.features.HttpRequestTimeoutException import kotlinx.coroutines.* @@ -63,6 +64,21 @@ fun RequestsExecutor.startGettingOfUpdates( } } +/** + * This method will create a new one [FlowsUpdatesFilter]. This method is unsafe due to the fact that it will start + * getting updates IMMEDIATELY. That means that your bot will be able to skip some of them until you will call + * [kotlinx.coroutines.flow.Flow.collect] on one of [FlowsUpdatesFilter] flows + */ +@PreviewFeature +fun RequestsExecutor.startGettingOfUpdates( + timeoutSeconds: Seconds = 30, + scope: CoroutineScope = CoroutineScope(Dispatchers.Default), + exceptionsHandler: (suspend (Exception) -> Unit)? = null, + flowsUpdatesFilterUpdatesKeeperCount: Int = 64 +): FlowsUpdatesFilter = FlowsUpdatesFilter(flowsUpdatesFilterUpdatesKeeperCount).apply { + startGettingOfUpdates(timeoutSeconds, scope, exceptionsHandler, allowedUpdates, asUpdateReceiver) +} + fun RequestsExecutor.startGettingOfUpdates( updatesFilter: UpdatesFilter, timeoutSeconds: Seconds = 30,