1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

Merge pull request #659 from InsanusMokrassar/3.2.7

3.2.7
This commit is contained in:
InsanusMokrassar 2022-10-01 23:36:51 +06:00 committed by GitHub
commit 4f75bc792d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 219 additions and 36 deletions

View File

@ -1,5 +1,17 @@
# TelegramBotAPI changelog # TelegramBotAPI changelog
## 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`
* `ReplyKeyboardRowBuilder`
* `InlineKeyboardBuilder`
* `InlineKeyboardRowBuilder`
## 3.2.6 ## 3.2.6
* `Core`: * `Core`:

View File

@ -6,4 +6,4 @@ kotlin.incremental=true
kotlin.incremental.js=true kotlin.incremental.js=true
library_group=dev.inmo library_group=dev.inmo
library_version=3.2.6 library_version=3.2.7

View File

@ -8,12 +8,12 @@ javax-activation = "1.1.1"
korlibs = "3.1.0" korlibs = "3.1.0"
uuid = "0.5.0" uuid = "0.5.0"
ktor = "2.1.1" ktor = "2.1.2"
ksp = "1.7.10-1.0.6" ksp = "1.7.10-1.0.6"
kotlin-poet = "1.12.0" kotlin-poet = "1.12.0"
microutils = "0.12.13" microutils = "0.12.17"
github-release-plugin = "2.4.1" github-release-plugin = "2.4.1"

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

@ -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.InlineKeyboardRowBuilder
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardRowBuilder * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardRowBuilder
*/ */
fun <T> row(block: RowBuilder<T>.() -> Unit): List<T> { inline fun <T> row(block: RowBuilder<T>.() -> Unit): List<T> {
return RowBuilder<T>().also(block).row return RowBuilder<T>().apply(block).row
} }
/** /**
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardRowBuilder * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardRowBuilder
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardRowBuilder * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardRowBuilder
*/ */
fun <T> MatrixBuilder<T>.row(block: RowBuilder<T>.() -> Unit) { inline fun <T> MatrixBuilder<T>.row(block: RowBuilder<T>.() -> Unit) {
add(RowBuilder<T>().also(block).row) add(RowBuilder<T>().apply(block).row)
} }
/** /**
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardRowBuilder * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardRowBuilder
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardRowBuilder * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardRowBuilder
*/ */
fun <T> MatrixBuilder<T>.row(vararg elements: T) { inline fun <T> MatrixBuilder<T>.row(vararg elements: T) {
add(elements.toList()) add(elements.toList())
} }
@ -30,7 +30,7 @@ fun <T> MatrixBuilder<T>.row(vararg elements: T) {
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardBuilder * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardBuilder
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardBuilder * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardBuilder
*/ */
fun <T> matrix(block: MatrixBuilder<T>.() -> Unit): Matrix<T> { inline fun <T> matrix(block: MatrixBuilder<T>.() -> Unit): Matrix<T> {
return MatrixBuilder<T>().also(block).matrix return MatrixBuilder<T>().also(block).matrix
} }
@ -38,7 +38,7 @@ fun <T> matrix(block: MatrixBuilder<T>.() -> Unit): Matrix<T> {
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardBuilder * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardBuilder
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardBuilder * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardBuilder
*/ */
fun <T> flatMatrix(block: RowBuilder<T>.() -> Unit): Matrix<T> { inline fun <T> flatMatrix(block: RowBuilder<T>.() -> Unit): Matrix<T> {
return MatrixBuilder<T>().apply { return MatrixBuilder<T>().apply {
row(block) row(block)
}.matrix }.matrix
@ -48,7 +48,7 @@ fun <T> flatMatrix(block: RowBuilder<T>.() -> Unit): Matrix<T> {
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardBuilder * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardBuilder
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardBuilder * @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardBuilder
*/ */
fun <T> flatMatrix(vararg elements: T): Matrix<T> { inline fun <T> flatMatrix(vararg elements: T): Matrix<T> {
return MatrixBuilder<T>().apply { return MatrixBuilder<T>().apply {
row { elements.forEach { +it } } row { elements.forEach { +it } }
}.matrix }.matrix

View File

@ -4,8 +4,7 @@ import dev.inmo.tgbotapi.types.LoginURL
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.*
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.webapps.WebAppInfo import dev.inmo.tgbotapi.types.webapps.WebAppInfo
import dev.inmo.tgbotapi.utils.MatrixBuilder import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RowBuilder
/** /**
* Core DSL part of Inline Keyboard DSL. Can accept only [InlineKeyboardButton] and returns ready to use * Core DSL part of Inline Keyboard DSL. Can accept only [InlineKeyboardButton] and returns ready to use
@ -15,12 +14,12 @@ import dev.inmo.tgbotapi.utils.RowBuilder
* @see InlineKeyboardBuilder.row * @see InlineKeyboardBuilder.row
* @see InlineKeyboardRowBuilder * @see InlineKeyboardRowBuilder
*/ */
class InlineKeyboardBuilder : MatrixBuilder<InlineKeyboardButton>() { typealias InlineKeyboardBuilder = MatrixBuilder<InlineKeyboardButton>
/**
/**
* Creates [InlineKeyboardMarkup] using internal [matrix] * Creates [InlineKeyboardMarkup] using internal [matrix]
*/ */
fun build() = InlineKeyboardMarkup(matrix) fun InlineKeyboardBuilder.build() = InlineKeyboardMarkup(matrix)
}
/** /**
* Row builder of [InlineKeyboardBuilder] * Row builder of [InlineKeyboardBuilder]
@ -28,7 +27,7 @@ class InlineKeyboardBuilder : MatrixBuilder<InlineKeyboardButton>() {
* @see inlineKeyboard * @see inlineKeyboard
* @see InlineKeyboardBuilder.row * @see InlineKeyboardBuilder.row
*/ */
class InlineKeyboardRowBuilder : RowBuilder<InlineKeyboardButton>() typealias InlineKeyboardRowBuilder = RowBuilder<InlineKeyboardButton>
/** /**
* Factory-function for [InlineKeyboardBuilder]. It will [apply] [block] to internally created [InlineKeyboardMarkup] * Factory-function for [InlineKeyboardBuilder]. It will [apply] [block] to internally created [InlineKeyboardMarkup]
@ -48,7 +47,7 @@ inline fun inlineKeyboard(
*/ */
inline fun flatInlineKeyboard( inline fun flatInlineKeyboard(
block: InlineKeyboardRowBuilder.() -> Unit block: InlineKeyboardRowBuilder.() -> Unit
) = inlineKeyboard { row(block) } ) = inlineKeyboard { row<InlineKeyboardButton>(block) }
/** /**
* Creates an [InlineKeyboardRowBuilder] and [apply] [block] with this builder * Creates an [InlineKeyboardRowBuilder] and [apply] [block] with this builder
@ -61,6 +60,7 @@ inline fun flatInlineKeyboard(
* @see inlineQueryButton * @see inlineQueryButton
* @see urlButton * @see urlButton
*/ */
@Deprecated("Redundant", ReplaceWith("this.row(block)", "dev.inmo.tgbotapi.utils.row"))
inline fun InlineKeyboardBuilder.row( inline fun InlineKeyboardBuilder.row(
block: InlineKeyboardRowBuilder.() -> Unit block: InlineKeyboardRowBuilder.() -> Unit
) = add(InlineKeyboardRowBuilder().apply(block).row) ) = add(InlineKeyboardRowBuilder().apply(block).row)

View File

@ -2,8 +2,7 @@ package dev.inmo.tgbotapi.extensions.utils.types.buttons
import dev.inmo.tgbotapi.types.buttons.* import dev.inmo.tgbotapi.types.buttons.*
import dev.inmo.tgbotapi.types.webapps.WebAppInfo import dev.inmo.tgbotapi.types.webapps.WebAppInfo
import dev.inmo.tgbotapi.utils.MatrixBuilder import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RowBuilder
/** /**
* Core DSL part of Keyboard DSL. Can accept only [KeyboardButton] and returns ready to use * Core DSL part of Keyboard DSL. Can accept only [KeyboardButton] and returns ready to use
@ -13,17 +12,17 @@ import dev.inmo.tgbotapi.utils.RowBuilder
* @see ReplyKeyboardBuilder.row * @see ReplyKeyboardBuilder.row
* @see ReplyKeyboardRowBuilder * @see ReplyKeyboardRowBuilder
*/ */
class ReplyKeyboardBuilder : MatrixBuilder<KeyboardButton>() { typealias ReplyKeyboardBuilder = MatrixBuilder<KeyboardButton>
/**
/**
* Creates [InlineKeyboardMarkup] using internal [matrix] * Creates [InlineKeyboardMarkup] using internal [matrix]
*/ */
fun build( fun ReplyKeyboardBuilder.build(
resizeKeyboard: Boolean? = null, resizeKeyboard: Boolean? = null,
oneTimeKeyboard: Boolean? = null, oneTimeKeyboard: Boolean? = null,
inputFieldPlaceholder: String? = null, inputFieldPlaceholder: String? = null,
selective: Boolean? = null, selective: Boolean? = null,
) = ReplyKeyboardMarkup(matrix, resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective) ) = ReplyKeyboardMarkup(matrix, resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective)
}
/** /**
* Row builder of [KeyboardButton] * Row builder of [KeyboardButton]
@ -31,7 +30,7 @@ class ReplyKeyboardBuilder : MatrixBuilder<KeyboardButton>() {
* @see replyKeyboard * @see replyKeyboard
* @see ReplyKeyboardBuilder.row * @see ReplyKeyboardBuilder.row
*/ */
class ReplyKeyboardRowBuilder : RowBuilder<KeyboardButton>() typealias ReplyKeyboardRowBuilder = RowBuilder<KeyboardButton>
/** /**
* Factory-function for [ReplyKeyboardBuilder]. It will [apply] [block] to internally created [ReplyKeyboardMarkup] * Factory-function for [ReplyKeyboardBuilder]. It will [apply] [block] to internally created [ReplyKeyboardMarkup]
@ -58,7 +57,7 @@ inline fun flatReplyKeyboard(
selective: Boolean? = null, selective: Boolean? = null,
block: ReplyKeyboardRowBuilder.() -> Unit block: ReplyKeyboardRowBuilder.() -> Unit
) = replyKeyboard(resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective) { ) = replyKeyboard(resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective) {
row(block) row<KeyboardButton>(block)
} }
/** /**
@ -69,6 +68,7 @@ inline fun flatReplyKeyboard(
* @see requestLocationButton * @see requestLocationButton
* @see requestPollButton * @see requestPollButton
*/ */
@Deprecated("Redundant", ReplaceWith("this.row(block)", "dev.inmo.tgbotapi.utils.row"))
inline fun ReplyKeyboardBuilder.row( inline fun ReplyKeyboardBuilder.row(
block: ReplyKeyboardRowBuilder.() -> Unit block: ReplyKeyboardRowBuilder.() -> Unit
) = add(ReplyKeyboardRowBuilder().apply(block).row) ) = add(ReplyKeyboardRowBuilder().apply(block).row)