1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2026-03-03 17:32:23 +00:00

extend support of styles and iconEmojiCustomId

This commit is contained in:
2026-02-16 23:22:04 +06:00
parent c4f2566b71
commit 10b1c359fa
6 changed files with 604 additions and 235 deletions

View File

@@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.extensions.utils.types.buttons
import dev.inmo.tgbotapi.types.LoginURL
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.KeyboardButtonStyle
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.*
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
@@ -70,8 +71,10 @@ inline fun InlineKeyboardMarkup.modified(
* @see InlineKeyboardBuilder.row
*/
fun InlineKeyboardRowBuilder.payButton(
text: String
) = add(PayInlineKeyboardButton(text))
text: String,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = add(PayInlineKeyboardButton(text, iconCustomEmojiId, style))
/**
* Creates and put [CallbackDataInlineKeyboardButton]
@@ -81,8 +84,10 @@ fun InlineKeyboardRowBuilder.payButton(
*/
fun InlineKeyboardRowBuilder.dataButton(
text: String,
data: String
) = add(CallbackDataInlineKeyboardButton(text, data))
data: String,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = add(CallbackDataInlineKeyboardButton(text, data, iconCustomEmojiId, style))
/**
* Creates and put [CallbackGameInlineKeyboardButton]
@@ -91,8 +96,10 @@ fun InlineKeyboardRowBuilder.dataButton(
* @see InlineKeyboardBuilder.row
*/
fun InlineKeyboardRowBuilder.gameButton(
text: String
) = add(CallbackGameInlineKeyboardButton(text))
text: String,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = add(CallbackGameInlineKeyboardButton(text, iconCustomEmojiId, style))
/**
* Creates and put [LoginURLInlineKeyboardButton]
@@ -102,8 +109,10 @@ fun InlineKeyboardRowBuilder.gameButton(
*/
fun InlineKeyboardRowBuilder.loginButton(
text: String,
loginUrl: LoginURL
) = add(LoginURLInlineKeyboardButton(text, loginUrl))
loginUrl: LoginURL,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = add(LoginURLInlineKeyboardButton(text, loginUrl, iconCustomEmojiId, style))
/**
* Creates [CopyTextButton]
@@ -113,8 +122,10 @@ fun InlineKeyboardRowBuilder.loginButton(
*/
fun InlineKeyboardRowBuilder.copyTextButton(
text: String,
data: CopyTextButtonData
) = add(CopyTextButton(text, data))
data: CopyTextButtonData,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = add(CopyTextButton(text, data, iconCustomEmojiId, style))
/**
* Creates [CopyTextButton]
@@ -124,8 +135,10 @@ fun InlineKeyboardRowBuilder.copyTextButton(
*/
fun InlineKeyboardRowBuilder.copyTextButton(
text: String,
data: String
) = copyTextButton(text, CopyTextButtonData(data))
data: String,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = copyTextButton(text, CopyTextButtonData(data), iconCustomEmojiId, style)
/**
* Creates and put [SwitchInlineQueryCurrentChatInlineKeyboardButton]
@@ -135,8 +148,10 @@ fun InlineKeyboardRowBuilder.copyTextButton(
*/
fun InlineKeyboardRowBuilder.inlineQueryInCurrentChatButton(
text: String,
data: String
) = add(SwitchInlineQueryCurrentChatInlineKeyboardButton(text, data))
data: String,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = add(SwitchInlineQueryCurrentChatInlineKeyboardButton(text, data, iconCustomEmojiId, style))
/**
* Creates and put [SwitchInlineQueryChosenChatInlineKeyboardButton]
@@ -146,8 +161,10 @@ fun InlineKeyboardRowBuilder.inlineQueryInCurrentChatButton(
*/
fun InlineKeyboardRowBuilder.inlineQueryInChosenChatButton(
text: String,
parameters: SwitchInlineQueryChosenChat
) = add(SwitchInlineQueryChosenChatInlineKeyboardButton(text, parameters))
parameters: SwitchInlineQueryChosenChat,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = add(SwitchInlineQueryChosenChatInlineKeyboardButton(text, parameters, iconCustomEmojiId, style))
/**
* Creates and put [SwitchInlineQueryChosenChatInlineKeyboardButton]
@@ -162,6 +179,8 @@ fun InlineKeyboardRowBuilder.inlineQueryInChosenChatButton(
allowBots: Boolean = false,
allowGroups: Boolean = false,
allowChannels: Boolean = false,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = inlineQueryInChosenChatButton(
text,
SwitchInlineQueryChosenChat(
@@ -170,12 +189,16 @@ fun InlineKeyboardRowBuilder.inlineQueryInChosenChatButton(
allowBots = allowBots,
allowGroups = allowGroups,
allowChannels = allowChannels
)
),
iconCustomEmojiId,
style
)
fun InlineKeyboardRowBuilder.inlineQueryInAnyChosenChatButton(
text: String,
query: String? = null,
) = inlineQueryInChosenChatButton(text, query, allowUsers = true, allowBots = true, allowGroups = true, allowChannels = true)
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = inlineQueryInChosenChatButton(text, query, allowUsers = true, allowBots = true, allowGroups = true, allowChannels = true, iconCustomEmojiId = iconCustomEmojiId, style = style)
/**
* Creates and put [SwitchInlineQueryInlineKeyboardButton]
@@ -185,8 +208,10 @@ fun InlineKeyboardRowBuilder.inlineQueryInAnyChosenChatButton(
*/
fun InlineKeyboardRowBuilder.inlineQueryButton(
text: String,
data: String
) = add(SwitchInlineQueryInlineKeyboardButton(text, data))
data: String,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = add(SwitchInlineQueryInlineKeyboardButton(text, data, iconCustomEmojiId, style))
/**
* Creates and put [URLInlineKeyboardButton]
@@ -196,8 +221,10 @@ fun InlineKeyboardRowBuilder.inlineQueryButton(
*/
fun InlineKeyboardRowBuilder.urlButton(
text: String,
url: String
) = add(URLInlineKeyboardButton(text, url))
url: String,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = add(URLInlineKeyboardButton(text, url, iconCustomEmojiId, style))
/**
* Creates and put [WebAppInlineKeyboardButton]. Please, remember that this button is available in private chats only
@@ -207,8 +234,10 @@ fun InlineKeyboardRowBuilder.urlButton(
*/
fun InlineKeyboardRowBuilder.webAppButton(
text: String,
webApp: WebAppInfo
) = add(WebAppInlineKeyboardButton(text, webApp))
webApp: WebAppInfo,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = add(WebAppInlineKeyboardButton(text, webApp, iconCustomEmojiId, style))
/**
* Creates and put [WebAppInlineKeyboardButton]. Please, remember that this button is available in private chats only
@@ -218,5 +247,7 @@ fun InlineKeyboardRowBuilder.webAppButton(
*/
fun InlineKeyboardRowBuilder.webAppButton(
text: String,
url: String
) = webAppButton(text, WebAppInfo(url))
url: String,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = webAppButton(text, WebAppInfo(url), iconCustomEmojiId, style)

View File

@@ -2,6 +2,7 @@
package dev.inmo.tgbotapi.extensions.utils.types.buttons
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.*
import dev.inmo.tgbotapi.types.buttons.reply.requestChatReplyButton
import dev.inmo.tgbotapi.types.buttons.reply.requestUserReplyButton
@@ -78,8 +79,10 @@ inline fun flatReplyKeyboard(
* @see ReplyKeyboardBuilder.row
*/
fun ReplyKeyboardRowBuilder.simpleButton(
text: String
) = add(SimpleKeyboardButton(text))
text: String,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = add(SimpleKeyboardButton(text, iconCustomEmojiId, style))
/**
* Creates and put [RequestContactKeyboardButton]
@@ -88,8 +91,10 @@ fun ReplyKeyboardRowBuilder.simpleButton(
* @see ReplyKeyboardBuilder.row
*/
fun ReplyKeyboardRowBuilder.requestContactButton(
text: String
) = add(RequestContactKeyboardButton(text))
text: String,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = add(RequestContactKeyboardButton(text, iconCustomEmojiId, style))
/**
* Creates and put [RequestLocationKeyboardButton]
@@ -98,8 +103,10 @@ fun ReplyKeyboardRowBuilder.requestContactButton(
* @see ReplyKeyboardBuilder.row
*/
fun ReplyKeyboardRowBuilder.requestLocationButton(
text: String
) = add(RequestLocationKeyboardButton(text))
text: String,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = add(RequestLocationKeyboardButton(text, iconCustomEmojiId, style))
/**
* Creates and put [RequestPollKeyboardButton]
@@ -109,8 +116,10 @@ fun ReplyKeyboardRowBuilder.requestLocationButton(
*/
fun ReplyKeyboardRowBuilder.requestPollButton(
text: String,
pollType: KeyboardButtonPollType
) = add(RequestPollKeyboardButton(text, pollType))
pollType: KeyboardButtonPollType,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = add(RequestPollKeyboardButton(text, pollType, iconCustomEmojiId, style))
/**
* Creates and put [WebAppKeyboardButton]
@@ -120,8 +129,10 @@ fun ReplyKeyboardRowBuilder.requestPollButton(
*/
fun ReplyKeyboardRowBuilder.webAppButton(
text: String,
webApp: WebAppInfo
) = add(WebAppKeyboardButton(text, webApp))
webApp: WebAppInfo,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = add(WebAppKeyboardButton(text, webApp, iconCustomEmojiId, style))
/**
* Creates and put [WebAppKeyboardButton]
@@ -131,8 +142,10 @@ fun ReplyKeyboardRowBuilder.webAppButton(
*/
fun ReplyKeyboardRowBuilder.webAppButton(
text: String,
url: String
) = webAppButton(text, WebAppInfo(url))
url: String,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = webAppButton(text, WebAppInfo(url), iconCustomEmojiId, style)
/**
@@ -143,11 +156,15 @@ fun ReplyKeyboardRowBuilder.webAppButton(
*/
fun ReplyKeyboardRowBuilder.requestUsersButton(
text: String,
requestUser: KeyboardButtonRequestUsers
requestUser: KeyboardButtonRequestUsers,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = add(
requestUsersReplyButton(
text,
requestUser
requestUser,
iconCustomEmojiId,
style
)
)
@@ -164,6 +181,8 @@ fun ReplyKeyboardRowBuilder.requestBotsButton(
requestName: Boolean? = null,
requestUsername: Boolean? = null,
requestPhoto: Boolean? = null,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = requestUsersButton(
text,
KeyboardButtonRequestUsers.Bot(
@@ -172,7 +191,9 @@ fun ReplyKeyboardRowBuilder.requestBotsButton(
requestName = requestName,
requestUsername = requestUsername,
requestPhoto = requestPhoto
)
),
iconCustomEmojiId,
style
)
/**
@@ -187,13 +208,17 @@ fun ReplyKeyboardRowBuilder.requestBotButton(
requestName: Boolean? = null,
requestUsername: Boolean? = null,
requestPhoto: Boolean? = null,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = requestBotsButton(
text,
requestId,
maxCount = keyboardButtonRequestUserLimit.first,
requestName = requestName,
requestUsername = requestUsername,
requestPhoto = requestPhoto
requestPhoto = requestPhoto,
iconCustomEmojiId = iconCustomEmojiId,
style = style
)
/**
@@ -210,6 +235,8 @@ fun ReplyKeyboardRowBuilder.requestUsersButton(
requestName: Boolean? = null,
requestUsername: Boolean? = null,
requestPhoto: Boolean? = null,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = requestUsersButton(
text,
KeyboardButtonRequestUsers.Common(
@@ -219,7 +246,9 @@ fun ReplyKeyboardRowBuilder.requestUsersButton(
requestName = requestName,
requestUsername = requestUsername,
requestPhoto = requestPhoto
)
),
iconCustomEmojiId,
style
)
/**
@@ -235,6 +264,8 @@ fun ReplyKeyboardRowBuilder.requestUserButton(
requestName: Boolean? = null,
requestUsername: Boolean? = null,
requestPhoto: Boolean? = null,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = requestUsersButton(
text = text,
requestId = requestId,
@@ -242,7 +273,9 @@ fun ReplyKeyboardRowBuilder.requestUserButton(
maxCount = keyboardButtonRequestUserLimit.first,
requestName = requestName,
requestUsername = requestUsername,
requestPhoto = requestPhoto
requestPhoto = requestPhoto,
iconCustomEmojiId = iconCustomEmojiId,
style = style
)
/**
@@ -259,6 +292,8 @@ fun ReplyKeyboardRowBuilder.requestUsersOrBotsButton(
requestName: Boolean? = null,
requestUsername: Boolean? = null,
requestPhoto: Boolean? = null,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = requestUsersButton(
text,
KeyboardButtonRequestUsers.Any(
@@ -268,7 +303,9 @@ fun ReplyKeyboardRowBuilder.requestUsersOrBotsButton(
requestName = requestName,
requestUsername = requestUsername,
requestPhoto = requestPhoto
)
),
iconCustomEmojiId,
style
)
/**
@@ -283,6 +320,8 @@ fun ReplyKeyboardRowBuilder.requestUserOrBotButton(
requestName: Boolean? = null,
requestUsername: Boolean? = null,
requestPhoto: Boolean? = null,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = requestUsersOrBotsButton(
text = text,
requestId = requestId,
@@ -290,6 +329,8 @@ fun ReplyKeyboardRowBuilder.requestUserOrBotButton(
requestName = requestName,
requestUsername = requestUsername,
requestPhoto = requestPhoto,
iconCustomEmojiId = iconCustomEmojiId,
style = style
)
@@ -301,11 +342,15 @@ fun ReplyKeyboardRowBuilder.requestUserOrBotButton(
*/
fun ReplyKeyboardRowBuilder.requestChatButton(
text: String,
requestChat: KeyboardButtonRequestChat
requestChat: KeyboardButtonRequestChat,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = add(
requestChatReplyButton(
text,
requestChat
requestChat,
iconCustomEmojiId,
style
)
)
@@ -328,6 +373,8 @@ fun ReplyKeyboardRowBuilder.requestChatButton(
requestTitle: Boolean? = null,
requestUsername: Boolean? = null,
requestPhoto: Boolean? = null,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = requestChatButton(
text,
KeyboardButtonRequestChat(
@@ -342,7 +389,9 @@ fun ReplyKeyboardRowBuilder.requestChatButton(
requestTitle = requestTitle,
requestUsername = requestUsername,
requestPhoto = requestPhoto,
)
),
iconCustomEmojiId,
style
)
/**
@@ -362,6 +411,8 @@ fun ReplyKeyboardRowBuilder.requestChannelButton(
requestTitle: Boolean? = null,
requestUsername: Boolean? = null,
requestPhoto: Boolean? = null,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = requestChatButton(
text,
KeyboardButtonRequestChat.Channel(
@@ -374,7 +425,9 @@ fun ReplyKeyboardRowBuilder.requestChannelButton(
requestTitle = requestTitle,
requestUsername = requestUsername,
requestPhoto = requestPhoto,
)
),
iconCustomEmojiId,
style
)
/**
@@ -395,6 +448,8 @@ fun ReplyKeyboardRowBuilder.requestGroupButton(
requestTitle: Boolean? = null,
requestUsername: Boolean? = null,
requestPhoto: Boolean? = null,
iconCustomEmojiId: CustomEmojiId? = null,
style: KeyboardButtonStyle? = null
) = requestChatButton(
text,
KeyboardButtonRequestChat.Group(
@@ -408,5 +463,7 @@ fun ReplyKeyboardRowBuilder.requestGroupButton(
requestTitle = requestTitle,
requestUsername = requestUsername,
requestPhoto = requestPhoto,
)
),
iconCustomEmojiId,
style
)