Skip to content

Commit

Permalink
Merge pull request #301 from InsanusMokrassar/20.0.0
Browse files Browse the repository at this point in the history
20.0.0
  • Loading branch information
InsanusMokrassar authored Nov 1, 2024
2 parents b7d53a7 + 5b580b5 commit 541b76b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ fun InlineKeyboardBuilder.includePageButtons(page: Int, count: Int) {
}
}
}
row {
copyTextButton("Command copy button", "/inline $page $count")
}

row {
if (page - 1 > 2) {
Expand Down Expand Up @@ -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")
Expand Down
14 changes: 14 additions & 0 deletions KeyboardsBot/jvm_launcher/src/main/kotlin/KeyboardsBotJvm.kt
Original file line number Diff line number Diff line change
@@ -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<String>) {
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)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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=20.0.0
micro_utils_version=0.23.0
serialization_version=1.7.3
ktor_version=3.0.1

0 comments on commit 541b76b

Please sign in to comment.