From f5b526e0c5990ee9d8f57717db791d1b11d59c74 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 18 Jan 2021 23:32:47 +0600 Subject: [PATCH] update up to tgbotapi 0.31.0 --- .../src/main/kotlin/FilesLoaderBot.kt | 4 +- .../src/main/kotlin/ForwardInfoSenderBot.kt | 2 + GetMeBot/src/main/kotlin/GetMeBot.kt | 2 +- .../src/main/kotlin/RandomFileSenderBot.kt | 42 +++++++------------ .../src/main/kotlin/SlotMachineDetectorBot.kt | 4 +- gradle.properties | 2 +- 6 files changed, 24 insertions(+), 32 deletions(-) diff --git a/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt b/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt index a831bbf..af0cbe8 100644 --- a/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt +++ b/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt @@ -1,8 +1,8 @@ +import dev.inmo.micro_utils.coroutines.safely +import dev.inmo.tgbotapi.bot.Ktor.telegramBot import dev.inmo.tgbotapi.extensions.api.downloadFile import dev.inmo.tgbotapi.extensions.api.get.getFileAdditionalInfo -import dev.inmo.tgbotapi.extensions.api.telegramBot import dev.inmo.tgbotapi.extensions.utils.flatMap -import dev.inmo.tgbotapi.extensions.utils.safely import dev.inmo.tgbotapi.extensions.utils.shortcuts.* import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingFlowsUpdatesByLongPolling import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent diff --git a/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt b/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt index 5e97f6b..1e8f632 100644 --- a/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt +++ b/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt @@ -1,3 +1,5 @@ +import dev.inmo.micro_utils.coroutines.safely +import dev.inmo.tgbotapi.bot.Ktor.telegramBot import dev.inmo.tgbotapi.extensions.api.send.sendTextMessage import dev.inmo.tgbotapi.extensions.api.telegramBot import dev.inmo.tgbotapi.extensions.utils.* diff --git a/GetMeBot/src/main/kotlin/GetMeBot.kt b/GetMeBot/src/main/kotlin/GetMeBot.kt index 7229172..3987703 100644 --- a/GetMeBot/src/main/kotlin/GetMeBot.kt +++ b/GetMeBot/src/main/kotlin/GetMeBot.kt @@ -1,5 +1,5 @@ +import dev.inmo.tgbotapi.bot.Ktor.telegramBot import dev.inmo.tgbotapi.extensions.api.bot.getMe -import dev.inmo.tgbotapi.extensions.api.telegramBot /** * This is one of the most easiest bot - it will just print information about itself diff --git a/RandomFileSenderBot/src/main/kotlin/RandomFileSenderBot.kt b/RandomFileSenderBot/src/main/kotlin/RandomFileSenderBot.kt index 0c6dceb..acfffd8 100644 --- a/RandomFileSenderBot/src/main/kotlin/RandomFileSenderBot.kt +++ b/RandomFileSenderBot/src/main/kotlin/RandomFileSenderBot.kt @@ -1,16 +1,13 @@ +import dev.inmo.tgbotapi.bot.Ktor.telegramBot import dev.inmo.tgbotapi.extensions.api.bot.getMe import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands import dev.inmo.tgbotapi.extensions.api.send.media.sendDocument -import dev.inmo.tgbotapi.extensions.api.send.sendTextMessage -import dev.inmo.tgbotapi.extensions.api.telegramBot -import dev.inmo.tgbotapi.extensions.utils.safely -import dev.inmo.tgbotapi.extensions.utils.updates.filterExactCommands -import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingFlowsUpdatesByLongPolling +import dev.inmo.tgbotapi.extensions.api.send.reply +import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviour +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand import dev.inmo.tgbotapi.requests.abstracts.toInputFile import dev.inmo.tgbotapi.types.BotCommand import kotlinx.coroutines.* -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach import java.io.File private const val command = "send_file" @@ -33,25 +30,18 @@ suspend fun main(args: Array) { val bot = telegramBot(botToken) val scope = CoroutineScope(Dispatchers.Default) - bot.startGettingFlowsUpdatesByLongPolling(scope = scope) { - messageFlow.filterExactCommands(Regex(command)).onEach { message -> - safely { - pickFile() ?.let { - bot.sendDocument( - message.chat.id, - it.toInputFile() - ) - } ?: bot.sendTextMessage(message.chat.id, "Nothing selected :(") - } - }.launchIn(scope) - } - - safely { - bot.setMyCommands( + bot.buildBehaviour(scope) { + onCommand(command.toRegex()) { message -> + pickFile() ?.let { + bot.sendDocument( + message.chat.id, + it.toInputFile() + ) + } ?: bot.reply(message, "Nothing selected :(") + } + setMyCommands( BotCommand(command, "Send some random file in picker directory") ) - println(bot.getMe()) - } - - scope.coroutineContext[Job]!!.join() + println(getMe()) + }.join() } diff --git a/SlotMachineDetectorBot/src/main/kotlin/SlotMachineDetectorBot.kt b/SlotMachineDetectorBot/src/main/kotlin/SlotMachineDetectorBot.kt index ab02785..3c0802f 100644 --- a/SlotMachineDetectorBot/src/main/kotlin/SlotMachineDetectorBot.kt +++ b/SlotMachineDetectorBot/src/main/kotlin/SlotMachineDetectorBot.kt @@ -1,6 +1,6 @@ +import dev.inmo.micro_utils.coroutines.safely +import dev.inmo.tgbotapi.bot.Ktor.telegramBot import dev.inmo.tgbotapi.extensions.api.send.reply -import dev.inmo.tgbotapi.extensions.api.send.sendTextMessage -import dev.inmo.tgbotapi.extensions.api.telegramBot import dev.inmo.tgbotapi.extensions.utils.* import dev.inmo.tgbotapi.extensions.utils.shortcuts.filterContentMessages import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingFlowsUpdatesByLongPolling diff --git a/gradle.properties b/gradle.properties index 6b50257..785bf47 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,4 +2,4 @@ kotlin.code.style=official org.gradle.parallel=true kotlin_version=1.4.21 -telegram_bot_api_version=0.30.13 +telegram_bot_api_version=0.31.0