From d936bc4643b3a3ec4bf24706696c0755e47a4030 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 11 Nov 2021 12:34:52 +0600 Subject: [PATCH] upgrade up to 0.37.0 --- FSMBot/src/main/kotlin/SimpleFSMBot.kt | 2 +- FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt | 3 ++- .../src/main/kotlin/ForwardInfoSenderBot.kt | 7 ++----- HelloBot/src/main/kotlin/HelloBot.kt | 10 ++-------- .../src/main/kotlin/RandomFileSenderBot.kt | 3 ++- .../src/commonMain/kotlin/ResenderBot.kt | 2 +- gradle.properties | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- 8 files changed, 13 insertions(+), 20 deletions(-) diff --git a/FSMBot/src/main/kotlin/SimpleFSMBot.kt b/FSMBot/src/main/kotlin/SimpleFSMBot.kt index e152106..bc84902 100644 --- a/FSMBot/src/main/kotlin/SimpleFSMBot.kt +++ b/FSMBot/src/main/kotlin/SimpleFSMBot.kt @@ -17,7 +17,7 @@ data class StopState(override val context: ChatId) : BotState suspend fun main(args: Array) { val botToken = args.first() - telegramBotWithBehaviourAndFSMAndStartLongPolling(botToken, CoroutineScope(Dispatchers.IO)) { + telegramBotWithBehaviourAndFSMAndStartLongPolling(botToken, CoroutineScope(Dispatchers.IO)) { strictlyOn { sendMessage( it.context, diff --git a/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt b/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt index cb35183..ed2600d 100644 --- a/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt +++ b/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt @@ -2,6 +2,7 @@ import dev.inmo.tgbotapi.extensions.api.files.downloadFile import dev.inmo.tgbotapi.extensions.api.get.getFileAdditionalInfo import dev.inmo.tgbotapi.extensions.api.send.reply import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviour +import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMedia import dev.inmo.tgbotapi.utils.filenameFromUrl @@ -17,7 +18,7 @@ suspend fun main(args: Array) { val directoryOrFile = args.getOrNull(1) ?.let { File(it) } ?: File("") directoryOrFile.mkdirs() - telegramBotWithBehaviour(botToken, CoroutineScope(Dispatchers.IO)) { + telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) { onMedia(initialFilter = null) { val pathedFile = bot.getFileAdditionalInfo(it.content.media) val file = File(directoryOrFile, pathedFile.filePath.filenameFromUrl).apply { diff --git a/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt b/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt index c99e1f3..d4e95e4 100644 --- a/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt +++ b/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt @@ -1,11 +1,8 @@ -import dev.inmo.micro_utils.coroutines.defaultSafelyExceptionHandler -import dev.inmo.tgbotapi.bot.Ktor.telegramBot import dev.inmo.tgbotapi.extensions.api.send.reply -import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviour +import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage import dev.inmo.tgbotapi.extensions.utils.formatting.* import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2 import dev.inmo.tgbotapi.types.message.* import kotlinx.coroutines.* @@ -16,7 +13,7 @@ import kotlinx.coroutines.* suspend fun main(vararg args: String) { val botToken = args.first() - telegramBotWithBehaviour(botToken, CoroutineScope(Dispatchers.IO)) { + telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) { onContentMessage(subcontextUpdatesFilter = { _, _ -> true }) { val toAnswer = buildEntities { when (val forwardInfo = it.forwardInfo) { diff --git a/HelloBot/src/main/kotlin/HelloBot.kt b/HelloBot/src/main/kotlin/HelloBot.kt index 3f171a5..ccc61c0 100644 --- a/HelloBot/src/main/kotlin/HelloBot.kt +++ b/HelloBot/src/main/kotlin/HelloBot.kt @@ -1,21 +1,15 @@ -import dev.inmo.micro_utils.coroutines.safely import dev.inmo.tgbotapi.extensions.api.chat.get.getChat import dev.inmo.tgbotapi.extensions.api.send.reply import dev.inmo.tgbotapi.extensions.api.send.sendTextMessage -import dev.inmo.tgbotapi.bot.Ktor.telegramBot -import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviour +import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage -import dev.inmo.tgbotapi.extensions.utils.asChannelChat import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2 import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2 -import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2 import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.chat.abstracts.* import dev.inmo.tgbotapi.utils.extensions.escapeMarkdownV2Common import kotlinx.coroutines.* -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach /** * The main purpose of this bot is just to answer "Oh, hi, " and add user mention here @@ -23,7 +17,7 @@ import kotlinx.coroutines.flow.onEach suspend fun main(vararg args: String) { val botToken = args.first() - telegramBotWithBehaviour(botToken, CoroutineScope(Dispatchers.IO)) { + telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) { onContentMessage { message -> val chat = message.chat if (chat is ChannelChat) { diff --git a/RandomFileSenderBot/src/main/kotlin/RandomFileSenderBot.kt b/RandomFileSenderBot/src/main/kotlin/RandomFileSenderBot.kt index dde785d..03da081 100644 --- a/RandomFileSenderBot/src/main/kotlin/RandomFileSenderBot.kt +++ b/RandomFileSenderBot/src/main/kotlin/RandomFileSenderBot.kt @@ -7,6 +7,7 @@ import dev.inmo.tgbotapi.extensions.api.send.media.sendDocumentsGroup import dev.inmo.tgbotapi.extensions.api.send.reply import dev.inmo.tgbotapi.extensions.api.send.withUploadDocumentAction import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviour +import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommandWithArgs import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile @@ -55,7 +56,7 @@ suspend fun main(args: Array) { val bot = telegramBot(botToken) - bot.buildBehaviour(defaultExceptionsHandler = { it.printStackTrace() }) { + bot.buildBehaviourWithLongPolling (defaultExceptionsHandler = { it.printStackTrace() }) { onCommandWithArgs(command) { message, args -> withUploadDocumentAction(message.chat) { diff --git a/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt b/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt index cfec8f5..6b354a9 100644 --- a/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt +++ b/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt @@ -18,7 +18,7 @@ suspend fun activateResenderBot( print(bot.getMe()) - bot.buildBehaviour(CoroutineScope(coroutineContext + SupervisorJob())) { + bot.buildBehaviourWithLongPolling(CoroutineScope(coroutineContext + SupervisorJob())) { onContentMessage( subcontextUpdatesFilter = MessageFilterByChat + BehaviourContextAndTwoTypesReceiver { it, _ -> it !is MediaGroupMessage<*> } ) { diff --git a/gradle.properties b/gradle.properties index 53b88b0..0ebbeb3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,5 +3,5 @@ org.gradle.parallel=true kotlin_version=1.5.31 -telegram_bot_api_version=0.36.1 -micro_utils_version=0.7.2 +telegram_bot_api_version=0.37.0 +micro_utils_version=0.8.1 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8ad73a7..e7fa367 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip