All Downloads are FREE. Search and download functionalities are using the official Maven repository.

utils.InlineButtonsHelpers.kt Maven / Gradle / Ivy

There is a newer version: 0.24.1
Show newest version
package dev.inmo.plagubot.plugins.inline.buttons.utils

import dev.inmo.plagubot.plugins.inline.buttons.InlineButtonsDrawer
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
import dev.inmo.tgbotapi.types.ChatId

fun extractChatIdAndData(data: String): Pair? {
    return runCatching {
        val (chatIdString, valuableData) = data.split(" ")
        val chatId = ChatId(chatIdString.toLong())
        return chatId to valuableData
    }.getOrNull()
}

fun createChatIdAndDataInlineButtonData(chatId: ChatId, data: String) = "${chatId.chatId} $data"

fun InlineKeyboardRowBuilder.inlineDataButton(text: String, chatId: ChatId, data: String) = dataButton(
    text,
    createChatIdAndDataInlineButtonData(chatId, data)
)

fun InlineKeyboardRowBuilder.drawerDataButton(drawer: InlineButtonsDrawer, chatId: ChatId) = dataButton(
    drawer.name,
    createChatIdAndDataInlineButtonData(chatId, drawer.id)
)

fun InlineKeyboardBuilder.drawerDataButtonRow(drawer: InlineButtonsDrawer, chatId: ChatId) = row {
    drawerDataButton(drawer, chatId)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy