add copyText sample button

This commit is contained in:
InsanusMokrassar 2024-11-01 23:21:33 +06:00
parent 0bbe430374
commit 86790ee414
2 changed files with 21 additions and 2 deletions

View File

@ -45,6 +45,9 @@ fun InlineKeyboardBuilder.includePageButtons(page: Int, count: Int) {
} }
} }
} }
row {
copyTextButton("Command copy button", "/inline $page $count")
}
row { row {
if (page - 1 > 2) { if (page - 1 > 2) {
@ -84,11 +87,13 @@ suspend fun activateKeyboardsBot(
bot.buildBehaviourWithLongPolling(CoroutineScope(currentCoroutineContext() + SupervisorJob())) { bot.buildBehaviourWithLongPolling(CoroutineScope(currentCoroutineContext() + SupervisorJob())) {
onCommandWithArgs("inline") { message, args -> 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( reply(
message, message,
replyMarkup = inlineKeyboard { replyMarkup = inlineKeyboard {
includePageButtons(1, numberOfPages) includePageButtons(page, numberOfPages)
} }
) { ) {
regular("Your inline keyboard with $numberOfPages pages") regular("Your inline keyboard with $numberOfPages pages")

View File

@ -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.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
suspend fun main(args: Array<String>) { 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 withContext(Dispatchers.IO) { // IO for inheriting of it in side of activateKeyboardsBot
activateKeyboardsBot(args.first()) { activateKeyboardsBot(args.first()) {
println(it) println(it)