From 3de3bb61337a6e0a4dab163a9ea2fa8f5e13eb85 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 19 Mar 2021 20:18:32 +0600 Subject: [PATCH 1/7] start 0.33.1 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d5a5d1710..cad4cd21f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.33.1 + ## 0.33.0 **UPDATE UP TO Telegram Bot API 5.1** diff --git a/gradle.properties b/gradle.properties index d338fd8535..1ca36552a2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,6 +17,6 @@ micro_utils_version=0.4.29 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.33.0 +library_version=0.33.1 github_release_plugin_version=2.2.12 From 9f8e8ee21ba63594e93c452422d995b3c88e7f7d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 19 Mar 2021 20:20:07 +0600 Subject: [PATCH 2/7] update dependencies --- CHANGELOG.md | 5 +++++ gradle.properties | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cad4cd21f7..26f27a8e69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## 0.33.1 +* `Common`: + * `Version`: + * `MicroUtils`: `0.4.29` -> `0.4.30` + * `Klocks`: `2.0.6` -> `2.0.7` + ## 0.33.0 **UPDATE UP TO Telegram Bot API 5.1** diff --git a/gradle.properties b/gradle.properties index 1ca36552a2..386d5dc86d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,11 +8,11 @@ kotlin.incremental.js=true kotlin_version=1.4.31 kotlin_coroutines_version=1.4.3 kotlin_serialisation_runtime_version=1.1.0 -klock_version=2.0.6 +klock_version=2.0.7 uuid_version=0.2.3 ktor_version=1.5.2 -micro_utils_version=0.4.29 +micro_utils_version=0.4.30 javax_activation_version=1.1.1 From 5b620014cb1a822b145467144a07798ce0af8105 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 24 Mar 2021 13:14:09 +0600 Subject: [PATCH 3/7] update kotlin version --- CHANGELOG.md | 1 + gradle.properties | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26f27a8e69..93c4a23e0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * `Common`: * `Version`: + * `Kotlin`: `1.4.31` -> `1.4.32` * `MicroUtils`: `0.4.29` -> `0.4.30` * `Klocks`: `2.0.6` -> `2.0.7` diff --git a/gradle.properties b/gradle.properties index 386d5dc86d..3163a8b867 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ kotlin.js.generate.externals=true kotlin.incremental=true kotlin.incremental.js=true -kotlin_version=1.4.31 +kotlin_version=1.4.32 kotlin_coroutines_version=1.4.3 kotlin_serialisation_runtime_version=1.1.0 klock_version=2.0.7 From 1a5d1cde78f3da792db30b84a6626b4ffec0d257 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 24 Mar 2021 13:41:37 +0600 Subject: [PATCH 4/7] add parseCommandsWithParams for text inputs --- CHANGELOG.md | 2 + .../tgbotapi/CommonAbstracts/Captioned.kt | 1 + .../TextCaptionBotCommandsParser.kt | 63 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 93c4a23e0e..2bf5ab0e0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ * `Kotlin`: `1.4.31` -> `1.4.32` * `MicroUtils`: `0.4.29` -> `0.4.30` * `Klocks`: `2.0.6` -> `2.0.7` +* `Utils Extensions`: + * Add extensions `parseCommandsWithParams` ## 0.33.0 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt index 7cee50ae0b..0b5ed05d2c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt @@ -6,6 +6,7 @@ interface Captioned { val caption: String? } +@Deprecated("This interface is not used in library and will be removed soon") interface CaptionedOutput : Captioned { val parseMode: ParseMode? } diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt new file mode 100644 index 0000000000..4ad76dddac --- /dev/null +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt @@ -0,0 +1,63 @@ +package dev.inmo.tgbotapi.extensions.utils.extensions + +import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.types.MessageEntity.textsources.BotCommandTextSource +import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage +import dev.inmo.tgbotapi.types.message.content.TextContent +import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent + + +val defaultArgsSeparator = Regex(" ") +/** + * Parse commands and their args. Logic will find command, get all subsequent data as args until new command + */ +fun List.parseCommandsWithParams( + argsSeparator: Regex = defaultArgsSeparator +): MutableMap> { + val result = mutableMapOf>() + var currentBotCommandSource: BotCommandTextSource? = null + var currentArgs = "" + fun includeCurrent() = currentBotCommandSource ?.let { + result[it.command] = currentArgs.split(argsSeparator).toTypedArray() + currentArgs = "" + } + for (textSource in this) { + if (textSource is BotCommandTextSource) { + includeCurrent() + currentBotCommandSource = textSource + } else { + currentArgs += textSource.source + } + } + includeCurrent() + return result +} + +/** + * Parse commands and their args. Logic will find command, get all subsequent data as args until new command + */ +fun TextedInput.parseCommandsWithParams( + argsSeparator: Regex = defaultArgsSeparator +) = textSources.parseCommandsWithParams(argsSeparator) + +/** + * Parse commands and their args. Logic will find command, get all subsequent data as args until new command + */ +fun TextedOutput.parseCommandsWithParams( + argsSeparator: Regex = defaultArgsSeparator +) = entities ?.parseCommandsWithParams(argsSeparator) ?: emptyMap() + +/** + * Parse commands and their args. Logic will find command, get all subsequent data as args until new command + */ +fun CaptionedInput.parseCommandsWithParams( + argsSeparator: Regex = defaultArgsSeparator +) = textSources.parseCommandsWithParams(argsSeparator) + +fun ContentMessage.parseCommandsWithParams( + argsSeparator: Regex = defaultArgsSeparator +) = content.parseCommandsWithParams(argsSeparator) + +fun ContentMessage.parseCommandsWithParams( + argsSeparator: Regex = defaultArgsSeparator +) where T : CaptionedInput, T : MessageContent = content.parseCommandsWithParams(argsSeparator) From 1ddd138ff7eb4d731d4c1fa6e603c2c5b307df14 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 24 Mar 2021 13:44:27 +0600 Subject: [PATCH 5/7] update kdocs for new function --- .../utils/extensions/TextCaptionBotCommandsParser.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt index 4ad76dddac..1eba49b1f4 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt @@ -54,10 +54,16 @@ fun CaptionedInput.parseCommandsWithParams( argsSeparator: Regex = defaultArgsSeparator ) = textSources.parseCommandsWithParams(argsSeparator) +/** + * Parse commands and their args. Logic will find command, get all subsequent data as args until new command + */ fun ContentMessage.parseCommandsWithParams( argsSeparator: Regex = defaultArgsSeparator ) = content.parseCommandsWithParams(argsSeparator) +/** + * Parse commands and their args. Logic will find command, get all subsequent data as args until new command + */ fun ContentMessage.parseCommandsWithParams( argsSeparator: Regex = defaultArgsSeparator ) where T : CaptionedInput, T : MessageContent = content.parseCommandsWithParams(argsSeparator) From 112c86c9da0e4d162541b03183cfdf14c01d8939 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 24 Mar 2021 13:56:51 +0600 Subject: [PATCH 6/7] remove caption based messages extension for parsing of commands --- .../utils/extensions/TextCaptionBotCommandsParser.kt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt index 1eba49b1f4..86a63efb23 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt @@ -60,10 +60,3 @@ fun CaptionedInput.parseCommandsWithParams( fun ContentMessage.parseCommandsWithParams( argsSeparator: Regex = defaultArgsSeparator ) = content.parseCommandsWithParams(argsSeparator) - -/** - * Parse commands and their args. Logic will find command, get all subsequent data as args until new command - */ -fun ContentMessage.parseCommandsWithParams( - argsSeparator: Regex = defaultArgsSeparator -) where T : CaptionedInput, T : MessageContent = content.parseCommandsWithParams(argsSeparator) From 0b2f7a38992c6f0d11c79ccd3cb133b1d46474fc Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 26 Mar 2021 07:03:33 +0600 Subject: [PATCH 7/7] update condition for ReplyMessageNotFoundException --- .../kotlin/dev/inmo/tgbotapi/bot/exceptions/RequestException.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/exceptions/RequestException.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/exceptions/RequestException.kt index 687392c696..a9c6ec5f56 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/exceptions/RequestException.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/exceptions/RequestException.kt @@ -12,7 +12,7 @@ fun newRequestException( cause: Throwable? = null ) = response.description ?.let { description -> when { - description == "Bad Request: reply message not found" -> ReplyMessageNotFoundException(response, plainAnswer, message, cause) + description == "Bad Request: reply message not found" || description == "Bad Request: replied message not found" -> ReplyMessageNotFoundException(response, plainAnswer, message, cause) description == "Bad Request: message to edit not found" -> MessageToEditNotFoundException(response, plainAnswer, message, cause) description.contains("Bad Request: message is not modified") -> MessageIsNotModifiedException(response, plainAnswer, message, cause) description == "Unauthorized" -> UnauthorizedException(response, plainAnswer, message, cause)