1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 16:47:13 +00:00

keyboard builders become typealiases

This commit is contained in:
InsanusMokrassar 2022-09-28 20:38:16 +06:00
parent 959f0dffba
commit 8b64a0c94e
5 changed files with 197 additions and 19 deletions

View File

@ -2,6 +2,13 @@
## 3.2.7
* `Utils`:
* Next classes become typealiases instead of classes:
* `ReplyKeyboardBuilder`
* `ReplyKeyboardRowBuilder`
* `InlineKeyboardBuilder`
* `InlineKeyboardRowBuilder`
## 3.2.6
* `Core`:

View File

@ -0,0 +1,102 @@
package dev.inmo.tgbotapi.types.buttons.inline
import dev.inmo.tgbotapi.types.LoginURL
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.*
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
/**
* Creates and put [PayInlineKeyboardButton]
*
* @see inlineKeyboard
* @see InlineKeyboardBuilder.row
*/
inline fun payInlineButton(
text: String
) = PayInlineKeyboardButton(text)
/**
* Creates and put [CallbackDataInlineKeyboardButton]
*
* @see inlineKeyboard
* @see InlineKeyboardBuilder.row
*/
inline fun dataInlineButton(
text: String,
data: String
) = CallbackDataInlineKeyboardButton(text, data)
/**
* Creates and put [CallbackGameInlineKeyboardButton]
*
* @see inlineKeyboard
* @see InlineKeyboardBuilder.row
*/
inline fun gameInlineButton(
text: String
) = CallbackGameInlineKeyboardButton(text)
/**
* Creates and put [LoginURLInlineKeyboardButton]
*
* @see inlineKeyboard
* @see InlineKeyboardBuilder.row
*/
inline fun loginInlineButton(
text: String,
loginUrl: LoginURL
) = LoginURLInlineKeyboardButton(text, loginUrl)
/**
* Creates and put [SwitchInlineQueryCurrentChatInlineKeyboardButton]
*
* @see inlineKeyboard
* @see InlineKeyboardBuilder.row
*/
inline fun inlineQueryInCurrentChatInlineButton(
text: String,
data: String
) = SwitchInlineQueryCurrentChatInlineKeyboardButton(text, data)
/**
* Creates and put [SwitchInlineQueryInlineKeyboardButton]
*
* @see inlineKeyboard
* @see InlineKeyboardBuilder.row
*/
inline fun inlineQueryInlineButton(
text: String,
data: String
) = SwitchInlineQueryInlineKeyboardButton(text, data)
/**
* Creates and put [URLInlineKeyboardButton]
*
* @see inlineKeyboard
* @see InlineKeyboardBuilder.row
*/
inline fun urlInlineButton(
text: String,
url: String
) = URLInlineKeyboardButton(text, url)
/**
* Creates and put [WebAppInlineKeyboardButton]. Please, remember that this button is available in private chats only
*
* @see inlineKeyboard
* @see InlineKeyboardBuilder.row
*/
inline fun webAppInlineButton(
text: String,
webApp: WebAppInfo
) = WebAppInlineKeyboardButton(text, webApp)
/**
* Creates and put [WebAppInlineKeyboardButton]. Please, remember that this button is available in private chats only
*
* @see inlineKeyboard
* @see InlineKeyboardBuilder.row
*/
inline fun webAppInlineButton(
text: String,
url: String
) = webAppInlineButton(text, WebAppInfo(url))

View File

@ -0,0 +1,69 @@
package dev.inmo.tgbotapi.types.buttons.reply
import dev.inmo.tgbotapi.types.buttons.*
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.*
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
/**
* Creates and put [SimpleKeyboardButton]
*
* @see replyKeyboard
* @see ReplyKeyboardBuilder.row
*/
inline fun simpleReplyButton(
text: String
) = SimpleKeyboardButton(text)
/**
* Creates and put [RequestContactKeyboardButton]
*
* @see replyKeyboard
* @see ReplyKeyboardBuilder.row
*/
inline fun requestContactReplyButton(
text: String
) = RequestContactKeyboardButton(text)
/**
* Creates and put [RequestLocationKeyboardButton]
*
* @see replyKeyboard
* @see ReplyKeyboardBuilder.row
*/
inline fun requestLocationReplyButton(
text: String
) = RequestLocationKeyboardButton(text)
/**
* Creates and put [RequestPollKeyboardButton]
*
* @see replyKeyboard
* @see ReplyKeyboardBuilder.row
*/
inline fun requestPollReplyButton(
text: String,
pollType: KeyboardButtonPollType
) = RequestPollKeyboardButton(text, pollType)
/**
* Creates and put [WebAppKeyboardButton]
*
* @see replyKeyboard
* @see ReplyKeyboardBuilder.row
*/
inline fun webAppReplyButton(
text: String,
webApp: WebAppInfo
) = WebAppKeyboardButton(text, webApp)
/**
* Creates and put [WebAppKeyboardButton]
*
* @see replyKeyboard
* @see ReplyKeyboardBuilder.row
*/
inline fun webAppReplyButton(
text: String,
url: String
) = webAppReplyButton(text, WebAppInfo(url))

View File

@ -15,12 +15,12 @@ import dev.inmo.tgbotapi.utils.RowBuilder
* @see InlineKeyboardBuilder.row
* @see InlineKeyboardRowBuilder
*/
class InlineKeyboardBuilder : MatrixBuilder<InlineKeyboardButton>() {
/**
* Creates [InlineKeyboardMarkup] using internal [matrix]
*/
fun build() = InlineKeyboardMarkup(matrix)
}
typealias InlineKeyboardBuilder = MatrixBuilder<InlineKeyboardButton>
/**
* Creates [InlineKeyboardMarkup] using internal [matrix]
*/
fun InlineKeyboardBuilder.build() = InlineKeyboardMarkup(matrix)
/**
* Row builder of [InlineKeyboardBuilder]
@ -28,7 +28,7 @@ class InlineKeyboardBuilder : MatrixBuilder<InlineKeyboardButton>() {
* @see inlineKeyboard
* @see InlineKeyboardBuilder.row
*/
class InlineKeyboardRowBuilder : RowBuilder<InlineKeyboardButton>()
typealias InlineKeyboardRowBuilder = RowBuilder<InlineKeyboardButton>
/**
* Factory-function for [InlineKeyboardBuilder]. It will [apply] [block] to internally created [InlineKeyboardMarkup]

View File

@ -13,17 +13,17 @@ import dev.inmo.tgbotapi.utils.RowBuilder
* @see ReplyKeyboardBuilder.row
* @see ReplyKeyboardRowBuilder
*/
class ReplyKeyboardBuilder : MatrixBuilder<KeyboardButton>() {
/**
* Creates [InlineKeyboardMarkup] using internal [matrix]
*/
fun build(
resizeKeyboard: Boolean? = null,
oneTimeKeyboard: Boolean? = null,
inputFieldPlaceholder: String? = null,
selective: Boolean? = null,
) = ReplyKeyboardMarkup(matrix, resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective)
}
typealias ReplyKeyboardBuilder = MatrixBuilder<KeyboardButton>
/**
* Creates [InlineKeyboardMarkup] using internal [matrix]
*/
fun ReplyKeyboardBuilder.build(
resizeKeyboard: Boolean? = null,
oneTimeKeyboard: Boolean? = null,
inputFieldPlaceholder: String? = null,
selective: Boolean? = null,
) = ReplyKeyboardMarkup(matrix, resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective)
/**
* Row builder of [KeyboardButton]
@ -31,7 +31,7 @@ class ReplyKeyboardBuilder : MatrixBuilder<KeyboardButton>() {
* @see replyKeyboard
* @see ReplyKeyboardBuilder.row
*/
class ReplyKeyboardRowBuilder : RowBuilder<KeyboardButton>()
typealias ReplyKeyboardRowBuilder = RowBuilder<KeyboardButton>
/**
* Factory-function for [ReplyKeyboardBuilder]. It will [apply] [block] to internally created [ReplyKeyboardMarkup]