mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2026-10-25 14:07:28 +00:00
Add Bot API 10.3 Reply markup support
This commit is contained in:
1 parent
752689447b
commit
efd4667ffa
15 files changed
+247
-36
No files matched your search
+7
@@ -121,6 +121,7 @@ import dev.inmo.tgbotapi.types.business_connection.BusinessConnection
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackGameInlineKeyboardButton
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CopyTextButton
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.DisabledInlineKeyboardButton
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.InlineKeyboardButton
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.LoginURLInlineKeyboardButton
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.PayInlineKeyboardButton
|
||||
@@ -4237,6 +4238,12 @@ public inline fun KeyboardButtonRequestUsers.botOrThrow(): KeyboardButtonRequest
|
||||
|
||||
public inline fun <T> KeyboardButtonRequestUsers.ifBot(block: (KeyboardButtonRequestUsers.Bot) -> T): T? = botOrNull() ?.let(block)
|
||||
|
||||
public inline fun InlineKeyboardButton.disabledInlineKeyboardButtonOrNull(): DisabledInlineKeyboardButton? = this as? dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.DisabledInlineKeyboardButton
|
||||
|
||||
public inline fun InlineKeyboardButton.disabledInlineKeyboardButtonOrThrow(): DisabledInlineKeyboardButton = this as dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.DisabledInlineKeyboardButton
|
||||
|
||||
public inline fun <T> InlineKeyboardButton.ifDisabledInlineKeyboardButton(block: (DisabledInlineKeyboardButton) -> T): T? = disabledInlineKeyboardButtonOrNull() ?.let(block)
|
||||
|
||||
public inline fun InlineKeyboardButton.unknownInlineKeyboardButtonOrNull(): UnknownInlineKeyboardButton? = this as? dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.UnknownInlineKeyboardButton
|
||||
|
||||
public inline fun InlineKeyboardButton.unknownInlineKeyboardButtonOrThrow(): UnknownInlineKeyboardButton = this as dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.UnknownInlineKeyboardButton
|
||||
|
||||
+21
-4
@@ -20,7 +20,9 @@ typealias InlineKeyboardBuilder = MatrixBuilder<InlineKeyboardButton>
|
||||
/**
|
||||
* Creates [InlineKeyboardMarkup] using internal [matrix]
|
||||
*/
|
||||
fun InlineKeyboardBuilder.build() = InlineKeyboardMarkup(matrix)
|
||||
fun InlineKeyboardBuilder.build(
|
||||
forceReply: Boolean? = null
|
||||
) = InlineKeyboardMarkup(matrix, forceReply)
|
||||
|
||||
/**
|
||||
* Row builder of [InlineKeyboardBuilder]
|
||||
@@ -37,8 +39,9 @@ typealias InlineKeyboardRowBuilder = RowBuilder<InlineKeyboardButton>
|
||||
* @see InlineKeyboardBuilder.row
|
||||
*/
|
||||
inline fun inlineKeyboard(
|
||||
forceReply: Boolean? = null,
|
||||
block: InlineKeyboardBuilder.() -> Unit
|
||||
) = InlineKeyboardBuilder().apply(block).build()
|
||||
) = InlineKeyboardBuilder().apply(block).build(forceReply)
|
||||
|
||||
/**
|
||||
* Factory-function for [InlineKeyboardBuilder], but in difference with [inlineKeyboard] this function will create single-row
|
||||
@@ -47,8 +50,9 @@ inline fun inlineKeyboard(
|
||||
* @see InlineKeyboardBuilder.row
|
||||
*/
|
||||
inline fun flatInlineKeyboard(
|
||||
forceReply: Boolean? = null,
|
||||
block: InlineKeyboardRowBuilder.() -> Unit
|
||||
) = inlineKeyboard { row<InlineKeyboardButton>(block) }
|
||||
) = inlineKeyboard(forceReply) { row<InlineKeyboardButton>(block) }
|
||||
|
||||
/**
|
||||
* Factory-function for [InlineKeyboardBuilder]. It will [apply] [block] to internally created [InlineKeyboardMarkup]
|
||||
@@ -57,11 +61,24 @@ inline fun flatInlineKeyboard(
|
||||
* @see InlineKeyboardBuilder.row
|
||||
*/
|
||||
inline fun InlineKeyboardMarkup.modified(
|
||||
forceReply: Boolean? = this.forceReply,
|
||||
block: InlineKeyboardBuilder.() -> Unit
|
||||
) = InlineKeyboardBuilder().apply {
|
||||
keyboard.forEach { add(it) }
|
||||
block()
|
||||
}.build()
|
||||
}.build(forceReply)
|
||||
|
||||
/**
|
||||
* Creates and puts [DisabledInlineKeyboardButton].
|
||||
*
|
||||
* @see inlineKeyboard
|
||||
* @see InlineKeyboardBuilder.row
|
||||
*/
|
||||
fun InlineKeyboardRowBuilder.disabledButton(
|
||||
text: String,
|
||||
iconCustomEmojiId: CustomEmojiId? = null,
|
||||
style: KeyboardButtonStyle? = null
|
||||
) = add(DisabledInlineKeyboardButton(text, iconCustomEmojiId, style))
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+4
-2
@@ -5,7 +5,9 @@ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||
import dev.inmo.tgbotapi.utils.flatMatrix
|
||||
|
||||
fun InlineKeyboardMarkup(
|
||||
vararg buttons: InlineKeyboardButton
|
||||
vararg buttons: InlineKeyboardButton,
|
||||
forceReply: Boolean? = null
|
||||
): InlineKeyboardMarkup = InlineKeyboardMarkup(
|
||||
flatMatrix { buttons.forEach { +it } }
|
||||
keyboard = flatMatrix { buttons.forEach { +it } },
|
||||
forceReply = forceReply
|
||||
)
|
||||
+6
-3
@@ -33,7 +33,8 @@ fun ReplyKeyboardBuilder.build(
|
||||
inputFieldPlaceholder: String? = null,
|
||||
selective: Boolean? = null,
|
||||
persistent: Boolean? = null,
|
||||
) = ReplyKeyboardMarkup(matrix, resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective, persistent)
|
||||
forceReply: Boolean? = null,
|
||||
) = ReplyKeyboardMarkup(matrix, resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective, persistent, forceReply)
|
||||
|
||||
/**
|
||||
* Row builder of [KeyboardButton]
|
||||
@@ -55,8 +56,9 @@ inline fun replyKeyboard(
|
||||
inputFieldPlaceholder: String? = null,
|
||||
selective: Boolean? = null,
|
||||
persistent: Boolean? = null,
|
||||
forceReply: Boolean? = null,
|
||||
block: ReplyKeyboardBuilder.() -> Unit
|
||||
) = ReplyKeyboardBuilder().apply(block).build(resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective, persistent)
|
||||
) = ReplyKeyboardBuilder().apply(block).build(resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective, persistent, forceReply)
|
||||
|
||||
/**
|
||||
* Factory-function for [ReplyKeyboardBuilder], but in difference with [replyKeyboard] this method will create single-row
|
||||
@@ -68,8 +70,9 @@ inline fun flatReplyKeyboard(
|
||||
inputFieldPlaceholder: String? = null,
|
||||
selective: Boolean? = null,
|
||||
persistent: Boolean? = null,
|
||||
forceReply: Boolean? = null,
|
||||
block: ReplyKeyboardRowBuilder.() -> Unit
|
||||
) = replyKeyboard(resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective, persistent) {
|
||||
) = replyKeyboard(resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective, persistent, forceReply) {
|
||||
row<KeyboardButton>(block)
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -10,12 +10,14 @@ fun ReplyKeyboardMarkup(
|
||||
oneTimeKeyboard: Boolean? = null,
|
||||
inputFieldPlaceholder: String? = null,
|
||||
selective: Boolean? = null,
|
||||
persistent: Boolean? = null
|
||||
persistent: Boolean? = null,
|
||||
forceReply: Boolean? = null
|
||||
): ReplyKeyboardMarkup = ReplyKeyboardMarkup(
|
||||
flatMatrix { buttons.forEach { +it } },
|
||||
resizeKeyboard,
|
||||
oneTimeKeyboard,
|
||||
inputFieldPlaceholder,
|
||||
selective,
|
||||
persistent
|
||||
persistent,
|
||||
forceReply
|
||||
)
|
||||
Reference in new issue
Block a user