From 959f0dffba04ce120cc00683b69b8616f9fd1e10 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 28 Sep 2022 20:02:45 +0600 Subject: [PATCH 1/4] start 3.2.7 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f1db96895..77e1f13658 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 3.2.7 + ## 3.2.6 * `Core`: diff --git a/gradle.properties b/gradle.properties index 7a9d06557d..b680197455 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ kotlin.incremental=true kotlin.incremental.js=true library_group=dev.inmo -library_version=3.2.6 +library_version=3.2.7 From 8b64a0c94e01c8ab7fb1566961122bfab075b63e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 28 Sep 2022 20:38:16 +0600 Subject: [PATCH 2/4] 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] From b588622c3dcc0f66960719845b241af1bac01bc0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 28 Sep 2022 20:48:55 +0600 Subject: [PATCH 3/4] deprecate old row methods for keyboard builders --- .../kotlin/dev/inmo/tgbotapi/utils/Matrix.kt | 16 ++++++++-------- .../utils/types/buttons/InlineKeyboardBuilder.kt | 6 +++--- .../utils/types/buttons/ReplyKeyboardBuilder.kt | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/Matrix.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/Matrix.kt index 51e9ca80a1..c14ae77d0e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/Matrix.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/Matrix.kt @@ -6,23 +6,23 @@ import dev.inmo.tgbotapi.types.buttons.Matrix * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardRowBuilder * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardRowBuilder */ -fun row(block: RowBuilder.() -> Unit): List { - return RowBuilder().also(block).row +inline fun row(block: RowBuilder.() -> Unit): List { + return RowBuilder().apply(block).row } /** * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardRowBuilder * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardRowBuilder */ -fun MatrixBuilder.row(block: RowBuilder.() -> Unit) { - add(RowBuilder().also(block).row) +inline fun MatrixBuilder.row(block: RowBuilder.() -> Unit) { + add(RowBuilder().apply(block).row) } /** * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardRowBuilder * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardRowBuilder */ -fun MatrixBuilder.row(vararg elements: T) { +inline fun MatrixBuilder.row(vararg elements: T) { add(elements.toList()) } @@ -30,7 +30,7 @@ fun MatrixBuilder.row(vararg elements: T) { * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardBuilder * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardBuilder */ -fun matrix(block: MatrixBuilder.() -> Unit): Matrix { +inline fun matrix(block: MatrixBuilder.() -> Unit): Matrix { return MatrixBuilder().also(block).matrix } @@ -38,7 +38,7 @@ fun matrix(block: MatrixBuilder.() -> Unit): Matrix { * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardBuilder * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardBuilder */ -fun flatMatrix(block: RowBuilder.() -> Unit): Matrix { +inline fun flatMatrix(block: RowBuilder.() -> Unit): Matrix { return MatrixBuilder().apply { row(block) }.matrix @@ -48,7 +48,7 @@ fun flatMatrix(block: RowBuilder.() -> Unit): Matrix { * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardBuilder * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardBuilder */ -fun flatMatrix(vararg elements: T): Matrix { +inline fun flatMatrix(vararg elements: T): Matrix { return MatrixBuilder().apply { row { elements.forEach { +it } } }.matrix 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 93979b91a1..69037b21e3 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 @@ -4,8 +4,7 @@ import dev.inmo.tgbotapi.types.LoginURL import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.webapps.WebAppInfo -import dev.inmo.tgbotapi.utils.MatrixBuilder -import dev.inmo.tgbotapi.utils.RowBuilder +import dev.inmo.tgbotapi.utils.* /** * Core DSL part of Inline Keyboard DSL. Can accept only [InlineKeyboardButton] and returns ready to use @@ -48,7 +47,7 @@ inline fun inlineKeyboard( */ inline fun flatInlineKeyboard( block: InlineKeyboardRowBuilder.() -> Unit -) = inlineKeyboard { row(block) } +) = inlineKeyboard { row(block) } /** * Creates an [InlineKeyboardRowBuilder] and [apply] [block] with this builder @@ -61,6 +60,7 @@ inline fun flatInlineKeyboard( * @see inlineQueryButton * @see urlButton */ +@Deprecated("Redundant", ReplaceWith("this.row(block)", "dev.inmo.tgbotapi.utils.row")) inline fun InlineKeyboardBuilder.row( block: InlineKeyboardRowBuilder.() -> Unit ) = add(InlineKeyboardRowBuilder().apply(block).row) 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 47cc7df2b4..2d913a1445 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 @@ -2,8 +2,7 @@ package dev.inmo.tgbotapi.extensions.utils.types.buttons import dev.inmo.tgbotapi.types.buttons.* import dev.inmo.tgbotapi.types.webapps.WebAppInfo -import dev.inmo.tgbotapi.utils.MatrixBuilder -import dev.inmo.tgbotapi.utils.RowBuilder +import dev.inmo.tgbotapi.utils.* /** * Core DSL part of Keyboard DSL. Can accept only [KeyboardButton] and returns ready to use @@ -58,7 +57,7 @@ inline fun flatReplyKeyboard( selective: Boolean? = null, block: ReplyKeyboardRowBuilder.() -> Unit ) = replyKeyboard(resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective) { - row(block) + row(block) } /** @@ -69,6 +68,7 @@ inline fun flatReplyKeyboard( * @see requestLocationButton * @see requestPollButton */ +@Deprecated("Redundant", ReplaceWith("this.row(block)", "dev.inmo.tgbotapi.utils.row")) inline fun ReplyKeyboardBuilder.row( block: ReplyKeyboardRowBuilder.() -> Unit ) = add(ReplyKeyboardRowBuilder().apply(block).row) From fda53cf171747a3c1605a10ab8490328cc0cf25d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 1 Oct 2022 22:09:01 +0600 Subject: [PATCH 4/4] update dependencies --- CHANGELOG.md | 3 +++ gradle/libs.versions.toml | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7203c44daa..c883766613 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 3.2.7 +* `Versions`: + * `MicroUtils`: `0.12.13` -> `0.12.17` + * `Ktor`: `2.1.1` -> `2.1.2` * `Utils`: * Next classes become typealiases instead of classes: * `ReplyKeyboardBuilder` diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index bbff748051..180ee2b47f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -8,12 +8,12 @@ javax-activation = "1.1.1" korlibs = "3.1.0" uuid = "0.5.0" -ktor = "2.1.1" +ktor = "2.1.2" ksp = "1.7.10-1.0.6" kotlin-poet = "1.12.0" -microutils = "0.12.13" +microutils = "0.12.17" github-release-plugin = "2.4.1"