2021-10-01 13:38:22 +00:00
|
|
|
package dev.inmo.tgbotapi.extensions.utils.types.buttons
|
|
|
|
|
|
|
|
import dev.inmo.tgbotapi.types.buttons.*
|
2023-02-05 16:25:43 +00:00
|
|
|
import dev.inmo.tgbotapi.types.buttons.reply.requestChatReplyButton
|
|
|
|
import dev.inmo.tgbotapi.types.buttons.reply.requestUserReplyButton
|
2024-01-10 17:05:44 +00:00
|
|
|
import dev.inmo.tgbotapi.types.buttons.reply.requestUsersReplyButton
|
2023-09-24 14:11:58 +00:00
|
|
|
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
2024-01-09 12:21:20 +00:00
|
|
|
import dev.inmo.tgbotapi.types.keyboardButtonRequestUserLimit
|
2023-02-05 16:25:43 +00:00
|
|
|
import dev.inmo.tgbotapi.types.request.RequestId
|
2022-04-17 14:18:09 +00:00
|
|
|
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
2022-09-28 14:48:55 +00:00
|
|
|
import dev.inmo.tgbotapi.utils.*
|
2021-10-01 13:38:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Core DSL part of Keyboard DSL. Can accept only [KeyboardButton] and returns ready to use
|
|
|
|
* [ReplyKeyboardMarkup] via [build] method
|
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
* @see ReplyKeyboardRowBuilder
|
|
|
|
*/
|
2022-09-28 14:38:16 +00:00
|
|
|
typealias ReplyKeyboardBuilder = MatrixBuilder<KeyboardButton>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates [InlineKeyboardMarkup] using internal [matrix]
|
|
|
|
*/
|
|
|
|
fun ReplyKeyboardBuilder.build(
|
|
|
|
resizeKeyboard: Boolean? = null,
|
|
|
|
oneTimeKeyboard: Boolean? = null,
|
|
|
|
inputFieldPlaceholder: String? = null,
|
|
|
|
selective: Boolean? = null,
|
2022-12-30 13:38:26 +00:00
|
|
|
persistent: Boolean? = null,
|
|
|
|
) = ReplyKeyboardMarkup(matrix, resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective, persistent)
|
2021-10-01 13:38:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Row builder of [KeyboardButton]
|
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
2022-09-28 14:38:16 +00:00
|
|
|
typealias ReplyKeyboardRowBuilder = RowBuilder<KeyboardButton>
|
2021-10-01 13:38:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Factory-function for [ReplyKeyboardBuilder]. It will [apply] [block] to internally created [ReplyKeyboardMarkup]
|
|
|
|
* and [ReplyKeyboardBuilder.build] [ReplyKeyboardMarkup] then
|
|
|
|
*
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
|
|
|
inline fun replyKeyboard(
|
|
|
|
resizeKeyboard: Boolean? = null,
|
|
|
|
oneTimeKeyboard: Boolean? = null,
|
|
|
|
inputFieldPlaceholder: String? = null,
|
|
|
|
selective: Boolean? = null,
|
2022-12-30 13:38:26 +00:00
|
|
|
persistent: Boolean? = null,
|
2022-05-04 17:11:20 +00:00
|
|
|
block: ReplyKeyboardBuilder.() -> Unit
|
2022-12-30 13:38:26 +00:00
|
|
|
) = ReplyKeyboardBuilder().apply(block).build(resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective, persistent)
|
2021-10-01 13:38:22 +00:00
|
|
|
|
2022-07-10 19:10:35 +00:00
|
|
|
/**
|
|
|
|
* Factory-function for [ReplyKeyboardBuilder], but in difference with [replyKeyboard] this method will create single-row
|
|
|
|
* keyboard
|
|
|
|
*/
|
|
|
|
inline fun flatReplyKeyboard(
|
|
|
|
resizeKeyboard: Boolean? = null,
|
|
|
|
oneTimeKeyboard: Boolean? = null,
|
|
|
|
inputFieldPlaceholder: String? = null,
|
|
|
|
selective: Boolean? = null,
|
2022-12-30 13:38:26 +00:00
|
|
|
persistent: Boolean? = null,
|
2022-07-10 19:10:35 +00:00
|
|
|
block: ReplyKeyboardRowBuilder.() -> Unit
|
2022-12-30 13:38:26 +00:00
|
|
|
) = replyKeyboard(resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective, persistent) {
|
2022-09-28 14:48:55 +00:00
|
|
|
row<KeyboardButton>(block)
|
2022-07-10 19:10:35 +00:00
|
|
|
}
|
|
|
|
|
2021-10-01 13:38:22 +00:00
|
|
|
/**
|
|
|
|
* Creates and put [SimpleKeyboardButton]
|
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
|
|
|
inline fun ReplyKeyboardRowBuilder.simpleButton(
|
|
|
|
text: String
|
|
|
|
) = add(SimpleKeyboardButton(text))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and put [RequestContactKeyboardButton]
|
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
|
|
|
inline fun ReplyKeyboardRowBuilder.requestContactButton(
|
|
|
|
text: String
|
|
|
|
) = add(RequestContactKeyboardButton(text))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and put [RequestLocationKeyboardButton]
|
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
|
|
|
inline fun ReplyKeyboardRowBuilder.requestLocationButton(
|
|
|
|
text: String
|
|
|
|
) = add(RequestLocationKeyboardButton(text))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and put [RequestPollKeyboardButton]
|
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
|
|
|
inline fun ReplyKeyboardRowBuilder.requestPollButton(
|
|
|
|
text: String,
|
|
|
|
pollType: KeyboardButtonPollType
|
|
|
|
) = add(RequestPollKeyboardButton(text, pollType))
|
2022-04-17 14:18:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and put [WebAppKeyboardButton]
|
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
|
|
|
inline fun ReplyKeyboardRowBuilder.webAppButton(
|
|
|
|
text: String,
|
|
|
|
webApp: WebAppInfo
|
|
|
|
) = add(WebAppKeyboardButton(text, webApp))
|
2022-05-04 17:11:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and put [WebAppKeyboardButton]
|
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
|
|
|
inline fun ReplyKeyboardRowBuilder.webAppButton(
|
|
|
|
text: String,
|
|
|
|
url: String
|
|
|
|
) = webAppButton(text, WebAppInfo(url))
|
2023-02-05 16:25:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and put [RequestUserKeyboardButton]
|
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
2024-01-09 12:21:20 +00:00
|
|
|
inline fun ReplyKeyboardRowBuilder.requestUsersButton(
|
2023-02-05 16:25:43 +00:00
|
|
|
text: String,
|
2024-01-03 10:28:56 +00:00
|
|
|
requestUser: KeyboardButtonRequestUsers
|
2023-02-05 16:25:43 +00:00
|
|
|
) = add(
|
2024-01-10 17:05:44 +00:00
|
|
|
requestUsersReplyButton(
|
2023-02-05 16:25:43 +00:00
|
|
|
text,
|
|
|
|
requestUser
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2024-01-09 12:21:20 +00:00
|
|
|
/**
|
|
|
|
* Creates and put [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Bot]
|
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
|
|
|
inline fun ReplyKeyboardRowBuilder.requestBotsButton(
|
|
|
|
text: String,
|
|
|
|
requestId: RequestId,
|
2024-01-10 17:05:44 +00:00
|
|
|
maxCount: Int = keyboardButtonRequestUserLimit.first
|
2024-01-09 12:21:20 +00:00
|
|
|
) = requestUsersButton(
|
|
|
|
text,
|
|
|
|
KeyboardButtonRequestUsers.Bot(requestId, maxCount)
|
|
|
|
)
|
|
|
|
|
2023-02-05 16:25:43 +00:00
|
|
|
/**
|
2024-01-03 10:28:56 +00:00
|
|
|
* Creates and put [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Bot]
|
2023-02-05 16:25:43 +00:00
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
|
|
|
inline fun ReplyKeyboardRowBuilder.requestBotButton(
|
|
|
|
text: String,
|
|
|
|
requestId: RequestId
|
2024-01-09 12:21:20 +00:00
|
|
|
) = requestBotsButton(
|
2023-02-05 16:25:43 +00:00
|
|
|
text,
|
2024-01-09 12:21:20 +00:00
|
|
|
requestId,
|
|
|
|
maxCount = keyboardButtonRequestUserLimit.first
|
|
|
|
)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and put [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Common]
|
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
|
|
|
inline fun ReplyKeyboardRowBuilder.requestUsersButton(
|
|
|
|
text: String,
|
|
|
|
requestId: RequestId,
|
|
|
|
premiumUser: Boolean? = null,
|
2024-01-10 17:05:44 +00:00
|
|
|
maxCount: Int = keyboardButtonRequestUserLimit.first
|
2024-01-09 12:21:20 +00:00
|
|
|
) = requestUsersButton(
|
|
|
|
text,
|
|
|
|
KeyboardButtonRequestUsers.Common(requestId, premiumUser, maxCount)
|
2023-02-05 16:25:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
/**
|
2024-01-03 10:28:56 +00:00
|
|
|
* Creates and put [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Common]
|
2023-02-05 16:25:43 +00:00
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
|
|
|
inline fun ReplyKeyboardRowBuilder.requestUserButton(
|
|
|
|
text: String,
|
|
|
|
requestId: RequestId,
|
|
|
|
premiumUser: Boolean? = null
|
2024-01-09 12:21:20 +00:00
|
|
|
) = requestUsersButton(text, requestId, premiumUser, maxCount = keyboardButtonRequestUserLimit.first)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and put [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Any]
|
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
|
|
|
inline fun ReplyKeyboardRowBuilder.requestUsersOrBotsButton(
|
|
|
|
text: String,
|
|
|
|
requestId: RequestId,
|
2024-01-10 17:05:44 +00:00
|
|
|
premiumUser: Boolean? = null,
|
|
|
|
maxCount: Int = keyboardButtonRequestUserLimit.first
|
2024-01-09 12:21:20 +00:00
|
|
|
) = requestUsersButton(
|
2023-02-05 16:25:43 +00:00
|
|
|
text,
|
2024-01-10 17:05:44 +00:00
|
|
|
KeyboardButtonRequestUsers.Any(requestId, premiumUser, maxCount)
|
2023-02-05 16:25:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
/**
|
2024-01-03 10:28:56 +00:00
|
|
|
* Creates and put [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Any]
|
2023-02-05 16:25:43 +00:00
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
|
|
|
inline fun ReplyKeyboardRowBuilder.requestUserOrBotButton(
|
|
|
|
text: String,
|
|
|
|
requestId: RequestId
|
2024-01-09 12:21:20 +00:00
|
|
|
) = requestUsersOrBotsButton(
|
2023-02-05 16:25:43 +00:00
|
|
|
text,
|
2024-01-09 12:21:20 +00:00
|
|
|
requestId,
|
|
|
|
maxCount = keyboardButtonRequestUserLimit.first
|
2023-02-05 16:25:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and put [RequestChatKeyboardButton]
|
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
|
|
|
inline fun ReplyKeyboardRowBuilder.requestChatButton(
|
|
|
|
text: String,
|
|
|
|
requestChat: KeyboardButtonRequestChat
|
|
|
|
) = add(
|
|
|
|
requestChatReplyButton(
|
|
|
|
text,
|
|
|
|
requestChat
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and put [RequestChatKeyboardButton] with [KeyboardButtonRequestChat]
|
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
|
|
|
inline fun ReplyKeyboardRowBuilder.requestChatButton(
|
|
|
|
text: String,
|
|
|
|
requestId: RequestId,
|
|
|
|
isChannel: Boolean? = null,
|
|
|
|
isForum: Boolean? = null,
|
2023-02-05 17:26:41 +00:00
|
|
|
isPublic: Boolean? = null,
|
|
|
|
isOwnedBy: Boolean? = null,
|
2023-09-24 14:11:58 +00:00
|
|
|
userRightsInChat: ChatCommonAdministratorRights? = null,
|
|
|
|
botRightsInChat: ChatCommonAdministratorRights? = null,
|
2023-02-05 17:18:14 +00:00
|
|
|
botIsMember: Boolean? = null
|
2023-02-05 16:25:43 +00:00
|
|
|
) = requestChatButton(
|
|
|
|
text,
|
|
|
|
KeyboardButtonRequestChat(
|
2023-02-05 17:26:41 +00:00
|
|
|
requestId = requestId,
|
|
|
|
isChannel = isChannel,
|
|
|
|
isForum = isForum,
|
|
|
|
isPublic = isPublic,
|
|
|
|
isOwnedBy = isOwnedBy,
|
|
|
|
userRightsInChat = userRightsInChat,
|
|
|
|
botRightsInChat = botRightsInChat,
|
|
|
|
botIsMember = botIsMember
|
2023-02-05 16:25:43 +00:00
|
|
|
)
|
|
|
|
)
|
2023-02-05 17:41:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and put [RequestChatKeyboardButton] with [KeyboardButtonRequestChat.Channel]
|
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
|
|
|
inline fun ReplyKeyboardRowBuilder.requestChannelButton(
|
|
|
|
text: String,
|
|
|
|
requestId: RequestId,
|
|
|
|
isPublic: Boolean? = null,
|
|
|
|
isOwnedBy: Boolean? = null,
|
2023-09-24 14:11:58 +00:00
|
|
|
userRightsInChat: ChatCommonAdministratorRights? = null,
|
|
|
|
botRightsInChat: ChatCommonAdministratorRights? = null,
|
2023-02-05 17:41:02 +00:00
|
|
|
botIsMember: Boolean? = null
|
|
|
|
) = requestChatButton(
|
|
|
|
text,
|
|
|
|
KeyboardButtonRequestChat.Channel(
|
|
|
|
requestId = requestId,
|
|
|
|
isPublic = isPublic,
|
|
|
|
isOwnedBy = isOwnedBy,
|
|
|
|
userRightsInChat = userRightsInChat,
|
|
|
|
botRightsInChat = botRightsInChat,
|
|
|
|
botIsMember = botIsMember
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and put [RequestChatKeyboardButton] with [KeyboardButtonRequestChat.Group]
|
|
|
|
*
|
|
|
|
* @see replyKeyboard
|
|
|
|
* @see ReplyKeyboardBuilder.row
|
|
|
|
*/
|
|
|
|
inline fun ReplyKeyboardRowBuilder.requestGroupButton(
|
|
|
|
text: String,
|
|
|
|
requestId: RequestId,
|
|
|
|
isForum: Boolean? = null,
|
|
|
|
isPublic: Boolean? = null,
|
|
|
|
isOwnedBy: Boolean? = null,
|
2023-09-24 14:11:58 +00:00
|
|
|
userRightsInChat: ChatCommonAdministratorRights? = null,
|
|
|
|
botRightsInChat: ChatCommonAdministratorRights? = null,
|
2023-02-05 17:41:02 +00:00
|
|
|
botIsMember: Boolean? = null
|
|
|
|
) = requestChatButton(
|
|
|
|
text,
|
|
|
|
KeyboardButtonRequestChat.Group(
|
|
|
|
requestId = requestId,
|
|
|
|
isForum = isForum,
|
|
|
|
isPublic = isPublic,
|
|
|
|
isOwnedBy = isOwnedBy,
|
|
|
|
userRightsInChat = userRightsInChat,
|
|
|
|
botRightsInChat = botRightsInChat,
|
|
|
|
botIsMember = botIsMember
|
|
|
|
)
|
|
|
|
)
|