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)