From c6c418c3935448c375e673cabd18d81be09be449 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 24 Mar 2022 16:52:13 +0600 Subject: [PATCH] update up to 0.38.10 --- .../src/commonMain/kotlin/ResenderBot.kt | 25 ++++++++++++++----- gradle.properties | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt b/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt index 115e545..7cc6cec 100644 --- a/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt +++ b/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt @@ -1,14 +1,15 @@ import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.tgbotapi.extensions.api.bot.getMe import dev.inmo.tgbotapi.bot.Ktor.telegramBot +import dev.inmo.tgbotapi.extensions.api.send.* import dev.inmo.tgbotapi.extensions.api.send.media.* import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CommonMessageFilterExcludeMediaGroups import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.* import dev.inmo.tgbotapi.extensions.utils.shortcuts.* +import dev.inmo.tgbotapi.types.message.abstracts.Message import kotlinx.coroutines.* -import kotlin.coroutines.coroutineContext suspend fun activateResenderBot( token: String, @@ -18,21 +19,33 @@ suspend fun activateResenderBot( print(bot.getMe()) - bot.buildBehaviourWithLongPolling(CoroutineScope(coroutineContext + SupervisorJob())) { + bot.buildBehaviourWithLongPolling(CoroutineScope(currentCoroutineContext() + SupervisorJob())) { onContentMessage( initialFilter = CommonMessageFilterExcludeMediaGroups, subcontextUpdatesFilter = MessageFilterByChat ) { - executeUnsafe(it.content.createResend(it.chat.id, replyToMessageId = it.messageId)) + val chat = it.chat + withTypingAction(chat) { + executeUnsafe(it.content.createResend(chat.id, replyToMessageId = it.messageId)) + } } onVisualGallery { - sendVisualMediaGroup(it.chat!!, it.map { it.content.toMediaGroupMemberInputMedia() }) + val chat = it.chat ?: return@onVisualGallery + withUploadPhotoAction(chat) { + sendVisualMediaGroup(chat, it.map { it.content.toMediaGroupMemberInputMedia() }) + } } onPlaylist { - sendPlaylist(it.chat!!, it.map { it.content.toMediaGroupMemberInputMedia() }) + val chat = it.chat ?: return@onPlaylist + withUploadDocumentAction(chat) { + sendPlaylist(chat, it.map { it.content.toMediaGroupMemberInputMedia() }) + } } onDocumentsGroup { - sendDocumentsGroup(it.chat!!, it.map { it.content.toMediaGroupMemberInputMedia() }) + val chat = it.chat ?: return@onDocumentsGroup + withUploadDocumentAction(chat) { + sendDocumentsGroup(chat, it.map { it.content.toMediaGroupMemberInputMedia() }) + } } allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { diff --git a/gradle.properties b/gradle.properties index fe56586..c15608f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,5 +3,5 @@ org.gradle.parallel=true kotlin_version=1.6.10 -telegram_bot_api_version=0.38.8 +telegram_bot_api_version=0.38.10 micro_utils_version=0.9.16