From 9405aa4467406e4b32deb6e415b1c455037bf356 Mon Sep 17 00:00:00 2001 From: d1snin Date: Wed, 12 Oct 2022 20:57:42 +0300 Subject: [PATCH 01/14] added `EntitiesBuilder.botCommand` and `EntitiesBuilder.botCommandln` overloads supporting `BotCommand` --- .../kotlin/dev/inmo/tgbotapi/utils/EntitiesBuilder.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) 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..b9aa8e93d5 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.command)) +/** + * Version of [EntitiesBuilder.botCommand] with new line at the end + */ +inline fun EntitiesBuilder.botCommandln(botCommand: BotCommand) = botCommand(botCommand.command) + newLine + /** From 0c9919e9e7a0a742d3384bcbec25f31dd55bbafc Mon Sep 17 00:00:00 2001 From: d1snin Date: Wed, 12 Oct 2022 21:04:20 +0300 Subject: [PATCH 02/14] added command handling functions supporting `BotCommand` --- .../triggers_handling/CommandHandling.kt | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) 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..b7b18735b3 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.toRegex(), 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.toRegex(), 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.toRegex(), + 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.toRegex(), initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) From 5fa18040032d727e8aa66fb7e283e2d42e26dae8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 13 Oct 2022 18:24:59 +0600 Subject: [PATCH 03/14] start 0.3.3 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c883766613..2935d56cd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 3.3.0 + ## 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 From 6fcd248aff7b581f504812a6f46d2c739ba19aed Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 13 Oct 2022 18:25:44 +0600 Subject: [PATCH 04/14] update microutils --- CHANGELOG.md | 3 +++ gradle/libs.versions.toml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2935d56cd0..34b003cac2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 3.3.0 +* `Versions`: + * `MicroUtils`: `0.12.17` -> `0.13.0` + ## 3.2.7 * `Versions`: diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 180ee2b47f..52f7a4f703 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,7 +13,7 @@ ktor = "2.1.2" ksp = "1.7.10-1.0.6" kotlin-poet = "1.12.0" -microutils = "0.12.17" +microutils = "0.13.0" github-release-plugin = "2.4.1" From 7488eb9d4b4e4355252ac62123800e2d63054710 Mon Sep 17 00:00:00 2001 From: d1snin Date: Thu, 13 Oct 2022 19:56:26 +0300 Subject: [PATCH 05/14] added `botCommand` text source factory function supporting `BotCommand` --- .../message/textsources/BotCommandTextSource.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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..8dbbfe804e 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 @@ -12,14 +13,14 @@ private val commandRegex = Regex("[/!][^@\\s]*") * @see botCommand */ @Serializable -data class BotCommandTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( +data class BotCommandTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor( override val source: String ) : TextSource { val command: String by lazy { - commandRegex.find(source) ?.value ?.substring(1) ?: source.substring(1)// skip first symbol like "/" or "!" + commandRegex.find(source)?.value?.substring(1) ?: source.substring(1)// skip first symbol like "/" or "!" } val username: Username? by lazy { - Username(usernameRegex.find(source) ?.value ?: return@lazy null) + Username(usernameRegex.find(source)?.value ?: return@lazy null) } override val markdown: String by lazy { source.commandMarkdown() } @@ -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) \ No newline at end of file From bd91d4a0c014c8f7b464f06bfae86031b00c4384 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 13 Oct 2022 23:29:36 +0600 Subject: [PATCH 06/14] Update CommandHandling.kt --- .../triggers_handling/CommandHandling.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 b7b18735b3..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 @@ -90,7 +90,7 @@ suspend fun BC.command( subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver -) = command(botCommand.command.toRegex(), requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) +) = command(botCommand.command, requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) suspend fun BC.onCommand( commandRegex: Regex, @@ -117,7 +117,7 @@ suspend fun BC.onCommand( subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver -): Job = onCommand(botCommand.command.toRegex(), requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) +): Job = onCommand(botCommand.command, requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) suspend fun BC.commandWithArgs( commandRegex: Regex, @@ -160,7 +160,7 @@ suspend fun BC.commandWithArgs( markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver> ) = commandWithArgs( - botCommand.command.toRegex(), + botCommand.command, initialFilter = initialFilter, subcontextUpdatesFilter = subcontextUpdatesFilter, markerFactory = markerFactory, @@ -189,4 +189,4 @@ suspend fun BC.onCommandWithArgs( subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver> -): Job = onCommandWithArgs(botCommand.command.toRegex(), initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) +): Job = onCommandWithArgs(botCommand.command, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) From ac7bf60182aeae2d3e2b2dfe9e87155d01eca0f1 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 13 Oct 2022 23:30:34 +0600 Subject: [PATCH 07/14] Update BotCommandTextSource.kt --- .../types/message/textsources/BotCommandTextSource.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 8dbbfe804e..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 @@ -13,14 +13,14 @@ private val commandRegex = Regex("[/!][^@\\s]*") * @see botCommand */ @Serializable -data class BotCommandTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor( +data class BotCommandTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String ) : TextSource { val command: String by lazy { - commandRegex.find(source)?.value?.substring(1) ?: source.substring(1)// skip first symbol like "/" or "!" + commandRegex.find(source) ?.value ?.substring(1) ?: source.substring(1)// skip first symbol like "/" or "!" } val username: Username? by lazy { - Username(usernameRegex.find(source)?.value ?: return@lazy null) + Username(usernameRegex.find(source) ?.value ?: return@lazy null) } override val markdown: String by lazy { source.commandMarkdown() } @@ -35,4 +35,4 @@ data class BotCommandTextSource @RiskFeature(DirectInvocationOfTextSourceConstru inline fun botCommand(command: String) = BotCommandTextSource("/$command") @Suppress("NOTHING_TO_INLINE") -inline fun botCommand(botCommand: BotCommand) = botCommand(botCommand.command) \ No newline at end of file +inline fun botCommand(botCommand: BotCommand) = botCommand(botCommand.command) From 636382fc8fee8253ab30266edfa5b0e975a2bec7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 13 Oct 2022 23:31:41 +0600 Subject: [PATCH 08/14] Update EntitiesBuilder.kt --- .../kotlin/dev/inmo/tgbotapi/utils/EntitiesBuilder.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 b9aa8e93d5..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 @@ -152,11 +152,11 @@ inline fun EntitiesBuilder.botCommandln(command: String) = botCommand(command) + /** * 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.command)) +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.command) + newLine +inline fun EntitiesBuilder.botCommandln(botCommand: BotCommand) = botCommand(botCommand) + newLine From 94ed4fed10ffd38ebf781f8875934e36b1aaa7be Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 19 Oct 2022 19:19:14 +0600 Subject: [PATCH 09/14] Update libs.versions.toml --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 52f7a4f703..265643540c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,7 +13,7 @@ ktor = "2.1.2" ksp = "1.7.10-1.0.6" kotlin-poet = "1.12.0" -microutils = "0.13.0" +microutils = "0.13.1" github-release-plugin = "2.4.1" From 54fb58de8165aab3a293936c4f2469937b30350d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 19 Oct 2022 19:25:01 +0600 Subject: [PATCH 10/14] Update CHANGELOG.md --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34b003cac2..1aeefae6bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,12 @@ ## 3.3.0 * `Versions`: - * `MicroUtils`: `0.12.17` -> `0.13.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)) +* `Behaviour Builder`: + * Add opportunity to use triggers with `BotCommand` (thanks to [d1shin](https://github.com/InsanusMokrassar/TelegramBotAPI/pull/664)) ## 3.2.7 From 81fbff0bf5370d65547eb0e67ad4d4b2ec09c6c3 Mon Sep 17 00:00:00 2001 From: d1snin Date: Wed, 19 Oct 2022 22:15:15 +0300 Subject: [PATCH 11/14] added `BehaviourContext.waitCommandMessage` supporting `BotCommand` --- .../behaviour_builder/expectations/WaitCommandsMessages.kt | 7 +++++++ 1 file changed, 7 insertions(+) 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 } From 62a9c687d5a83bc647fe6fa75d147fd3f21a2b41 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 22 Oct 2022 14:33:43 +0600 Subject: [PATCH 12/14] update dependencies and changelog --- CHANGELOG.md | 5 ++++- gradle/libs.versions.toml | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aeefae6bf..e6a74ebeb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,12 +3,15 @@ ## 3.3.0 * `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)) * `Behaviour Builder`: - * Add opportunity to use triggers with `BotCommand` (thanks to [d1shin](https://github.com/InsanusMokrassar/TelegramBotAPI/pull/664)) + * Add opportunity to use triggers and waiters with `BotCommand` (thanks to [d1shin](https://github.com/InsanusMokrassar/TelegramBotAPI/pull/664)) ## 3.2.7 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 265643540c..1f2b41c1c9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,16 +1,16 @@ [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.13.1" From 8ed216619d4ed07f4da63b444ae2146cb28d9758 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 22 Oct 2022 17:41:55 +0600 Subject: [PATCH 13/14] deprecate TelegramBot#getStickerSet --- CHANGELOG.md | 3 +++ .../tgbotapi/extensions/api/get/GetStickerSet.kt | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6a74ebeb3..bc75606fdb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ * `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)) 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") +) From c10da2a10a769316e308896eade294cf1cf567e0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 22 Oct 2022 17:59:54 +0600 Subject: [PATCH 14/14] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc75606fdb..df0060bdcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 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`