diff --git a/CHANGELOG.md b/CHANGELOG.md index c883766613..df0060bdcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # 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`: diff --git a/gradle.properties b/gradle.properties index b680197455..507af88d65 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.7 +library_version=3.3.0 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 180ee2b47f..1f2b41c1c9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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.2" -ksp = "1.7.10-1.0.6" +ksp = "1.7.20-1.0.7" kotlin-poet = "1.12.0" -microutils = "0.12.17" +microutils = "0.13.1" github-release-plugin = "2.4.1" diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/get/GetStickerSet.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/get/GetStickerSet.kt index 94400fa7a9..6b73341d94 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/get/GetStickerSet.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/get/GetStickerSet.kt @@ -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") +) diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCommandsMessages.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCommandsMessages.kt index df34cfab1f..bd2927e5d5 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCommandsMessages.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCommandsMessages.kt @@ -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>.requireCommandAtStart() = filter { it.content.textSources.firstOrNull() is BotCommandTextSource } diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt index f59aa80629..3802ee5dc1 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt @@ -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.command( scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = command(command.toRegex(), requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) +suspend fun BC.command( + botCommand: BotCommand, + requireOnlyCommandInMessage: Boolean = true, + initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + markerFactory: MarkerFactory = ByChatMessageMarkerFactory, + scenarioReceiver: CustomBehaviourContextAndTypeReceiver +) = command(botCommand.command, requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) + suspend fun BC.onCommand( commandRegex: Regex, requireOnlyCommandInMessage: Boolean = true, @@ -100,6 +110,15 @@ suspend fun BC.onCommand( scenarioReceiver: CustomBehaviourContextAndTypeReceiver ): Job = onCommand(command.toRegex(), requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) +suspend fun BC.onCommand( + botCommand: BotCommand, + requireOnlyCommandInMessage: Boolean = true, + initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + markerFactory: MarkerFactory = ByChatMessageMarkerFactory, + scenarioReceiver: CustomBehaviourContextAndTypeReceiver +): Job = onCommand(botCommand.command, requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) + suspend fun BC.commandWithArgs( commandRegex: Regex, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, @@ -134,6 +153,20 @@ suspend fun BC.commandWithArgs( scenarioReceiver = scenarioReceiver ) +suspend fun BC.commandWithArgs( + botCommand: BotCommand, + initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + markerFactory: MarkerFactory = ByChatMessageMarkerFactory, + scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver> +) = commandWithArgs( + botCommand.command, + initialFilter = initialFilter, + subcontextUpdatesFilter = subcontextUpdatesFilter, + markerFactory = markerFactory, + scenarioReceiver = scenarioReceiver +) + suspend fun BC.onCommandWithArgs( commandRegex: Regex, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, @@ -149,3 +182,11 @@ suspend fun BC.onCommandWithArgs( markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver> ): Job = onCommandWithArgs(command.toRegex(), initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) + +suspend fun BC.onCommandWithArgs( + botCommand: BotCommand, + initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + markerFactory: MarkerFactory = ByChatMessageMarkerFactory, + scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver> +): Job = onCommandWithArgs(botCommand.command, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/BotCommandTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/BotCommandTextSource.kt index bb143c5fe0..5c3d49e741 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/BotCommandTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/BotCommandTextSource.kt @@ -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) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/EntitiesBuilder.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/EntitiesBuilder.kt index 8960195a75..8e6f52a42a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/EntitiesBuilder.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/EntitiesBuilder.kt @@ -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 + /**