From 0bf7e33df34e699fb3ff927855c53126a177a574 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 22 May 2022 12:57:53 +0600 Subject: [PATCH] migration onto 2.0.0 and several improvements --- FSMBot/src/main/kotlin/SimpleFSMBot.kt | 1 + RandomFileSenderBot/src/main/kotlin/RandomFileSenderBot.kt | 5 +++-- gradle.properties | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/FSMBot/src/main/kotlin/SimpleFSMBot.kt b/FSMBot/src/main/kotlin/SimpleFSMBot.kt index 24c8fd6..53ee72a 100644 --- a/FSMBot/src/main/kotlin/SimpleFSMBot.kt +++ b/FSMBot/src/main/kotlin/SimpleFSMBot.kt @@ -10,6 +10,7 @@ import dev.inmo.tgbotapi.types.ChatId import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage import dev.inmo.tgbotapi.types.message.content.TextContent import kotlinx.coroutines.* +import kotlinx.coroutines.flow.first sealed interface BotState : State data class ExpectContentOrStopState(override val context: ChatId, val sourceMessage: CommonMessage) : BotState diff --git a/RandomFileSenderBot/src/main/kotlin/RandomFileSenderBot.kt b/RandomFileSenderBot/src/main/kotlin/RandomFileSenderBot.kt index 87e8cbc..ab56fe1 100644 --- a/RandomFileSenderBot/src/main/kotlin/RandomFileSenderBot.kt +++ b/RandomFileSenderBot/src/main/kotlin/RandomFileSenderBot.kt @@ -1,3 +1,4 @@ +import dev.inmo.micro_utils.common.filesize import dev.inmo.tgbotapi.bot.ktor.telegramBot import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.extensions.api.bot.getMe @@ -64,9 +65,9 @@ suspend fun main(args: Array) { val chosen = mutableListOf() while (left > 0) { - left-- - val picked = pickFile() ?: continue + val picked = pickFile() ?.takeIf { it.filesize > 0 } ?: continue chosen.add(picked) + left-- if (chosen.size >= mediaCountInMediaGroup.last) { sendFiles(message.chat, chosen) chosen.clear() diff --git a/gradle.properties b/gradle.properties index 8f6df7c..de113cb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx768m kotlin_version=1.6.21 -telegram_bot_api_version=1.1.3 +telegram_bot_api_version=2.0.0 micro_utils_version=0.10.5 serialization_version=1.3.3 ktor_version=2.0.1