From 0bbe430374192b1053d92808f56616466115cfb4 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 1 Nov 2024 15:27:17 +0600 Subject: [PATCH 1/3] update ktgbotapi --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index d0319f0..12a3052 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ kotlin.daemon.jvmargs=-Xmx3g -Xms500m kotlin_version=2.0.21 -telegram_bot_api_version=19.0.0 +telegram_bot_api_version=19.1.0 micro_utils_version=0.23.0 serialization_version=1.7.3 ktor_version=3.0.1 From 86790ee414a7854cb26d4d7dacab61b4ec249ae0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 1 Nov 2024 23:21:33 +0600 Subject: [PATCH 2/3] add copyText sample button --- .../src/commonMain/kotlin/KeyboardsBot.kt | 9 +++++++-- .../src/main/kotlin/KeyboardsBotJvm.kt | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/KeyboardsBot/KeyboardsBotLib/src/commonMain/kotlin/KeyboardsBot.kt b/KeyboardsBot/KeyboardsBotLib/src/commonMain/kotlin/KeyboardsBot.kt index 1873050..9781465 100644 --- a/KeyboardsBot/KeyboardsBotLib/src/commonMain/kotlin/KeyboardsBot.kt +++ b/KeyboardsBot/KeyboardsBotLib/src/commonMain/kotlin/KeyboardsBot.kt @@ -45,6 +45,9 @@ fun InlineKeyboardBuilder.includePageButtons(page: Int, count: Int) { } } } + row { + copyTextButton("Command copy button", "/inline $page $count") + } row { if (page - 1 > 2) { @@ -84,11 +87,13 @@ suspend fun activateKeyboardsBot( bot.buildBehaviourWithLongPolling(CoroutineScope(currentCoroutineContext() + SupervisorJob())) { onCommandWithArgs("inline") { message, args -> - val numberOfPages = args.firstOrNull() ?.toIntOrNull() ?: 10 + val numberArgs = args.mapNotNull { it.toIntOrNull() } + val numberOfPages = numberArgs.getOrNull(1) ?: numberArgs.firstOrNull() ?: 10 + val page = numberArgs.firstOrNull() ?.takeIf { numberArgs.size > 1 } ?.coerceAtLeast(1) ?: 1 reply( message, replyMarkup = inlineKeyboard { - includePageButtons(1, numberOfPages) + includePageButtons(page, numberOfPages) } ) { regular("Your inline keyboard with $numberOfPages pages") diff --git a/KeyboardsBot/jvm_launcher/src/main/kotlin/KeyboardsBotJvm.kt b/KeyboardsBot/jvm_launcher/src/main/kotlin/KeyboardsBotJvm.kt index 9ef93b6..d40e789 100644 --- a/KeyboardsBot/jvm_launcher/src/main/kotlin/KeyboardsBotJvm.kt +++ b/KeyboardsBot/jvm_launcher/src/main/kotlin/KeyboardsBotJvm.kt @@ -1,7 +1,21 @@ +import dev.inmo.kslog.common.KSLog +import dev.inmo.kslog.common.LogLevel +import dev.inmo.kslog.common.defaultMessageFormatter +import dev.inmo.kslog.common.setDefaultKSLog import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext suspend fun main(args: Array) { + val isDebug = args.any { it == "debug" } + + if (isDebug) { + setDefaultKSLog( + KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? -> + println(defaultMessageFormatter(level, tag, message, throwable)) + } + ) + } + withContext(Dispatchers.IO) { // IO for inheriting of it in side of activateKeyboardsBot activateKeyboardsBot(args.first()) { println(it) From 5b580b5a151daa9e1b25b05793622388a2929a90 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 1 Nov 2024 23:48:29 +0600 Subject: [PATCH 3/3] migration onto 20.0.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 12a3052..a9b3363 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ kotlin.daemon.jvmargs=-Xmx3g -Xms500m kotlin_version=2.0.21 -telegram_bot_api_version=19.1.0 +telegram_bot_api_version=20.0.0 micro_utils_version=0.23.0 serialization_version=1.7.3 ktor_version=3.0.1