mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-17 12:30:20 +00:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c10da2a10a | |||
| 8ed216619d | |||
| 62a9c687d5 | |||
| c2918c308f | |||
|
|
81fbff0bf5 | ||
| 54fb58de81 | |||
| 94ed4fed10 | |||
| 63ceec70ca | |||
| 636382fc8f | |||
| ac7bf60182 | |||
| bd91d4a0c0 | |||
|
|
7488eb9d4b | ||
| 6fcd248aff | |||
| 5fa1804003 | |||
|
|
0c9919e9e7 | ||
|
|
9405aa4467 | ||
| 4f75bc792d | |||
| fda53cf171 | |||
| b588622c3d | |||
| 8b64a0c94e | |||
| 959f0dffba | |||
| 8fc9185884 |
30
CHANGELOG.md
30
CHANGELOG.md
@@ -1,5 +1,35 @@
|
||||
# TelegramBotAPI changelog
|
||||
|
||||
## 3.3.0
|
||||
|
||||
**THIS VERSION CONTAINS UPGRADE KOTLIN (AND ALL RELATED LIBRARIES) UP TO 1.7.20**
|
||||
|
||||
* `Versions`:
|
||||
* `Kotlin`: `1.7.10` -> `1.7.20`
|
||||
* `Kotlin Serialization`: `1.4.0` -> `1.4.1`
|
||||
* `Korlibs`: `3.1.0` -> `3.2.0`
|
||||
* `MicroUtils`: `0.12.17` -> `0.13.1`
|
||||
* `Core`:
|
||||
* Add opportunity to create command text source and add command in entities builder
|
||||
via `BotCommamd` (thanks to [d1shin](https://github.com/InsanusMokrassar/TelegramBotAPI/pull/664))
|
||||
* `API`:
|
||||
* New extensions `TelegramBot#getStickerSetOrNull` and `TelegramBot#getStickerSetOrThrow`
|
||||
* Old `TelegramBot#getStickerSet` has been deprecated
|
||||
* `Behaviour Builder`:
|
||||
* Add opportunity to use triggers and waiters with `BotCommand` (thanks to [d1shin](https://github.com/InsanusMokrassar/TelegramBotAPI/pull/664))
|
||||
|
||||
## 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
|
||||
|
||||
* `Core`:
|
||||
|
||||
@@ -6,4 +6,4 @@ kotlin.incremental=true
|
||||
kotlin.incremental.js=true
|
||||
|
||||
library_group=dev.inmo
|
||||
library_version=3.2.6
|
||||
library_version=3.3.0
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
[versions]
|
||||
|
||||
kotlin = "1.7.10"
|
||||
kotlin-serialization = "1.4.0"
|
||||
kotlin = "1.7.20"
|
||||
kotlin-serialization = "1.4.1"
|
||||
kotlin-coroutines = "1.6.4"
|
||||
|
||||
javax-activation = "1.1.1"
|
||||
|
||||
korlibs = "3.1.0"
|
||||
korlibs = "3.2.0"
|
||||
uuid = "0.5.0"
|
||||
ktor = "2.1.1"
|
||||
ktor = "2.1.2"
|
||||
|
||||
ksp = "1.7.10-1.0.6"
|
||||
ksp = "1.7.20-1.0.7"
|
||||
kotlin-poet = "1.12.0"
|
||||
|
||||
microutils = "0.12.13"
|
||||
microutils = "0.13.1"
|
||||
|
||||
github-release-plugin = "2.4.1"
|
||||
|
||||
|
||||
@@ -10,8 +10,21 @@ suspend fun TelegramBot.getStickerSet(
|
||||
GetStickerSet(name)
|
||||
)
|
||||
|
||||
@Deprecated("Renamed", ReplaceWith("getStickerSetOrThrow(sticker)", "dev.inmo.tgbotapi.extensions.api.get.getStickerSetOrThrow"))
|
||||
suspend fun TelegramBot.getStickerSet(
|
||||
sticker: Sticker
|
||||
) = getStickerSet(
|
||||
sticker.stickerSetName ?: error("Sticker must contains stickerSetName to be correctly used in getStickerSet method")
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.getStickerSetOrNull(
|
||||
sticker: Sticker
|
||||
) = sticker.stickerSetName ?.let {
|
||||
getStickerSet(it)
|
||||
}
|
||||
|
||||
suspend fun TelegramBot.getStickerSetOrThrow(
|
||||
sticker: Sticker
|
||||
) = getStickerSet(
|
||||
sticker.stickerSetName ?: error("Sticker must contains stickerSetName to be correctly used in getStickerSet method")
|
||||
)
|
||||
|
||||
@@ -4,6 +4,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.handlers_registrar.doWithRegistration
|
||||
import dev.inmo.tgbotapi.extensions.utils.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.BotCommand
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
|
||||
@@ -39,6 +40,12 @@ suspend fun BehaviourContext.waitCommandMessage(
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitCommandMessage(Regex(command), initRequest, errorFactory)
|
||||
|
||||
suspend fun BehaviourContext.waitCommandMessage(
|
||||
botCommand: BotCommand,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitCommandMessage(botCommand.command, initRequest, errorFactory)
|
||||
|
||||
fun Flow<CommonMessage<TextContent>>.requireCommandAtStart() = filter {
|
||||
it.content.textSources.firstOrNull() is BotCommandTextSource
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.Mar
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times
|
||||
import dev.inmo.tgbotapi.extensions.utils.botCommandTextSourceOrNull
|
||||
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithParams
|
||||
import dev.inmo.tgbotapi.types.BotCommand
|
||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||
import dev.inmo.tgbotapi.types.message.content.TextMessage
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
@@ -82,6 +83,15 @@ suspend fun <BC : BehaviourContext> BC.command(
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, TextMessage>
|
||||
) = command(command.toRegex(), requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
suspend fun <BC : BehaviourContext> BC.command(
|
||||
botCommand: BotCommand,
|
||||
requireOnlyCommandInMessage: Boolean = true,
|
||||
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, TextMessage>
|
||||
) = command(botCommand.command, requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
suspend fun <BC : BehaviourContext> BC.onCommand(
|
||||
commandRegex: Regex,
|
||||
requireOnlyCommandInMessage: Boolean = true,
|
||||
@@ -100,6 +110,15 @@ suspend fun <BC : BehaviourContext> BC.onCommand(
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, TextMessage>
|
||||
): Job = onCommand(command.toRegex(), requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
suspend fun <BC : BehaviourContext> BC.onCommand(
|
||||
botCommand: BotCommand,
|
||||
requireOnlyCommandInMessage: Boolean = true,
|
||||
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, TextMessage>
|
||||
): Job = onCommand(botCommand.command, requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
suspend fun <BC : BehaviourContext> BC.commandWithArgs(
|
||||
commandRegex: Regex,
|
||||
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
@@ -134,6 +153,20 @@ suspend fun <BC : BehaviourContext> BC.commandWithArgs(
|
||||
scenarioReceiver = scenarioReceiver
|
||||
)
|
||||
|
||||
suspend fun <BC : BehaviourContext> BC.commandWithArgs(
|
||||
botCommand: BotCommand,
|
||||
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, Array<String>>
|
||||
) = commandWithArgs(
|
||||
botCommand.command,
|
||||
initialFilter = initialFilter,
|
||||
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
||||
markerFactory = markerFactory,
|
||||
scenarioReceiver = scenarioReceiver
|
||||
)
|
||||
|
||||
suspend fun <BC : BehaviourContext> BC.onCommandWithArgs(
|
||||
commandRegex: Regex,
|
||||
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
@@ -149,3 +182,11 @@ suspend fun <BC : BehaviourContext> BC.onCommandWithArgs(
|
||||
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, Array<String>>
|
||||
): Job = onCommandWithArgs(command.toRegex(), initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
suspend fun <BC : BehaviourContext> BC.onCommandWithArgs(
|
||||
botCommand: BotCommand,
|
||||
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, Array<String>>
|
||||
): Job = onCommandWithArgs(botCommand.command, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
@@ -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))
|
||||
@@ -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))
|
||||
@@ -1,7 +1,8 @@
|
||||
package dev.inmo.tgbotapi.types.message.textsources
|
||||
|
||||
import dev.inmo.tgbotapi.types.usernameRegex
|
||||
import dev.inmo.tgbotapi.types.BotCommand
|
||||
import dev.inmo.tgbotapi.types.Username
|
||||
import dev.inmo.tgbotapi.types.usernameRegex
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import dev.inmo.tgbotapi.utils.internal.*
|
||||
import kotlinx.serialization.Serializable
|
||||
@@ -32,3 +33,6 @@ data class BotCommandTextSource @RiskFeature(DirectInvocationOfTextSourceConstru
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun botCommand(command: String) = BotCommandTextSource("/$command")
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun botCommand(botCommand: BotCommand) = botCommand(botCommand.command)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package dev.inmo.tgbotapi.utils
|
||||
|
||||
import dev.inmo.micro_utils.common.joinTo
|
||||
import dev.inmo.tgbotapi.types.BotCommand
|
||||
import dev.inmo.tgbotapi.types.CustomEmojiId
|
||||
import dev.inmo.tgbotapi.types.chat.User
|
||||
import dev.inmo.tgbotapi.types.message.textsources.*
|
||||
@@ -148,6 +149,15 @@ inline fun EntitiesBuilder.botCommand(command: String) = add(dev.inmo.tgbotapi.t
|
||||
* Version of [EntitiesBuilder.botCommand] with new line at the end
|
||||
*/
|
||||
inline fun EntitiesBuilder.botCommandln(command: String) = botCommand(command) + newLine
|
||||
/**
|
||||
* Add botCommand using [EntitiesBuilder.add] with [dev.inmo.tgbotapi.types.message.textsources.botCommand]
|
||||
*/
|
||||
inline fun EntitiesBuilder.botCommand(botCommand: BotCommand) = add(dev.inmo.tgbotapi.types.message.textsources.botCommand(botCommand))
|
||||
/**
|
||||
* Version of [EntitiesBuilder.botCommand] with new line at the end
|
||||
*/
|
||||
inline fun EntitiesBuilder.botCommandln(botCommand: BotCommand) = botCommand(botCommand) + newLine
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 <T> row(block: RowBuilder<T>.() -> Unit): List<T> {
|
||||
return RowBuilder<T>().also(block).row
|
||||
inline fun <T> row(block: RowBuilder<T>.() -> Unit): List<T> {
|
||||
return RowBuilder<T>().apply(block).row
|
||||
}
|
||||
|
||||
/**
|
||||
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardRowBuilder
|
||||
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardRowBuilder
|
||||
*/
|
||||
fun <T> MatrixBuilder<T>.row(block: RowBuilder<T>.() -> Unit) {
|
||||
add(RowBuilder<T>().also(block).row)
|
||||
inline fun <T> MatrixBuilder<T>.row(block: RowBuilder<T>.() -> Unit) {
|
||||
add(RowBuilder<T>().apply(block).row)
|
||||
}
|
||||
|
||||
/**
|
||||
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardRowBuilder
|
||||
* @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())
|
||||
}
|
||||
|
||||
@@ -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.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
|
||||
}
|
||||
|
||||
@@ -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.ReplyKeyboardBuilder
|
||||
*/
|
||||
fun <T> flatMatrix(block: RowBuilder<T>.() -> Unit): Matrix<T> {
|
||||
inline fun <T> flatMatrix(block: RowBuilder<T>.() -> Unit): Matrix<T> {
|
||||
return MatrixBuilder<T>().apply {
|
||||
row(block)
|
||||
}.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.ReplyKeyboardBuilder
|
||||
*/
|
||||
fun <T> flatMatrix(vararg elements: T): Matrix<T> {
|
||||
inline fun <T> flatMatrix(vararg elements: T): Matrix<T> {
|
||||
return MatrixBuilder<T>().apply {
|
||||
row { elements.forEach { +it } }
|
||||
}.matrix
|
||||
|
||||
@@ -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
|
||||
@@ -15,12 +14,12 @@ import dev.inmo.tgbotapi.utils.RowBuilder
|
||||
* @see InlineKeyboardBuilder.row
|
||||
* @see InlineKeyboardRowBuilder
|
||||
*/
|
||||
class InlineKeyboardBuilder : MatrixBuilder<InlineKeyboardButton>() {
|
||||
typealias InlineKeyboardBuilder = MatrixBuilder<InlineKeyboardButton>
|
||||
|
||||
/**
|
||||
* Creates [InlineKeyboardMarkup] using internal [matrix]
|
||||
*/
|
||||
fun build() = InlineKeyboardMarkup(matrix)
|
||||
}
|
||||
fun InlineKeyboardBuilder.build() = InlineKeyboardMarkup(matrix)
|
||||
|
||||
/**
|
||||
* Row builder of [InlineKeyboardBuilder]
|
||||
@@ -28,7 +27,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]
|
||||
@@ -48,7 +47,7 @@ inline fun inlineKeyboard(
|
||||
*/
|
||||
inline fun flatInlineKeyboard(
|
||||
block: InlineKeyboardRowBuilder.() -> Unit
|
||||
) = inlineKeyboard { row(block) }
|
||||
) = inlineKeyboard { row<InlineKeyboardButton>(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)
|
||||
|
||||
@@ -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
|
||||
@@ -13,17 +12,17 @@ import dev.inmo.tgbotapi.utils.RowBuilder
|
||||
* @see ReplyKeyboardBuilder.row
|
||||
* @see ReplyKeyboardRowBuilder
|
||||
*/
|
||||
class ReplyKeyboardBuilder : MatrixBuilder<KeyboardButton>() {
|
||||
typealias ReplyKeyboardBuilder = MatrixBuilder<KeyboardButton>
|
||||
|
||||
/**
|
||||
* Creates [InlineKeyboardMarkup] using internal [matrix]
|
||||
*/
|
||||
fun build(
|
||||
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 +30,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]
|
||||
@@ -58,7 +57,7 @@ inline fun flatReplyKeyboard(
|
||||
selective: Boolean? = null,
|
||||
block: ReplyKeyboardRowBuilder.() -> Unit
|
||||
) = replyKeyboard(resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective) {
|
||||
row(block)
|
||||
row<KeyboardButton>(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)
|
||||
|
||||
Reference in New Issue
Block a user