From 8b64a0c94e01c8ab7fb1566961122bfab075b63e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 28 Sep 2022 20:38:16 +0600 Subject: [PATCH] keyboard builders become typealiases --- CHANGELOG.md | 7 ++ .../inline/InlineKeyboardButtonsShortcuts.kt | 102 ++++++++++++++++++ .../reply/ReplyKeyboardButtonsShortcuts.kt | 69 ++++++++++++ .../types/buttons/InlineKeyboardBuilder.kt | 14 +-- .../types/buttons/ReplyKeyboardBuilder.kt | 24 ++--- 5 files changed, 197 insertions(+), 19 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/inline/InlineKeyboardButtonsShortcuts.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/reply/ReplyKeyboardButtonsShortcuts.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 77e1f13658..7203c44daa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ ## 3.2.7 +* `Utils`: + * Next classes become typealiases instead of classes: + * `ReplyKeyboardBuilder` + * `ReplyKeyboardRowBuilder` + * `InlineKeyboardBuilder` + * `InlineKeyboardRowBuilder` + ## 3.2.6 * `Core`: diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/inline/InlineKeyboardButtonsShortcuts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/inline/InlineKeyboardButtonsShortcuts.kt new file mode 100644 index 0000000000..9f148a98fe --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/inline/InlineKeyboardButtonsShortcuts.kt @@ -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)) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/reply/ReplyKeyboardButtonsShortcuts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/reply/ReplyKeyboardButtonsShortcuts.kt new file mode 100644 index 0000000000..d87ed524f4 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/reply/ReplyKeyboardButtonsShortcuts.kt @@ -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)) diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/InlineKeyboardBuilder.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/InlineKeyboardBuilder.kt index b458ba7ae0..93979b91a1 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/InlineKeyboardBuilder.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/InlineKeyboardBuilder.kt @@ -15,12 +15,12 @@ import dev.inmo.tgbotapi.utils.RowBuilder * @see InlineKeyboardBuilder.row * @see InlineKeyboardRowBuilder */ -class InlineKeyboardBuilder : MatrixBuilder() { - /** - * Creates [InlineKeyboardMarkup] using internal [matrix] - */ - fun build() = InlineKeyboardMarkup(matrix) -} +typealias InlineKeyboardBuilder = MatrixBuilder + +/** + * Creates [InlineKeyboardMarkup] using internal [matrix] + */ +fun InlineKeyboardBuilder.build() = InlineKeyboardMarkup(matrix) /** * Row builder of [InlineKeyboardBuilder] @@ -28,7 +28,7 @@ class InlineKeyboardBuilder : MatrixBuilder() { * @see inlineKeyboard * @see InlineKeyboardBuilder.row */ -class InlineKeyboardRowBuilder : RowBuilder() +typealias InlineKeyboardRowBuilder = RowBuilder /** * Factory-function for [InlineKeyboardBuilder]. It will [apply] [block] to internally created [InlineKeyboardMarkup] diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardBuilder.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardBuilder.kt index fd88ee744f..47cc7df2b4 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardBuilder.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardBuilder.kt @@ -13,17 +13,17 @@ import dev.inmo.tgbotapi.utils.RowBuilder * @see ReplyKeyboardBuilder.row * @see ReplyKeyboardRowBuilder */ -class ReplyKeyboardBuilder : MatrixBuilder() { - /** - * 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 + +/** + * 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() { * @see replyKeyboard * @see ReplyKeyboardBuilder.row */ -class ReplyKeyboardRowBuilder : RowBuilder() +typealias ReplyKeyboardRowBuilder = RowBuilder /** * Factory-function for [ReplyKeyboardBuilder]. It will [apply] [block] to internally created [ReplyKeyboardMarkup]