diff --git a/CHANGELOG.md b/CHANGELOG.md index df0060bdcf..ad6e1197b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # TelegramBotAPI changelog +## 3.3.1 + +* `Versions`: + * `Ktor`: `2.1.2` -> `2.1.3` + * `Klock`: `3.2.0` -> `3.3.1` + * `MicroUtils`: `0.13.1` -> `0.13.2` +* `Utils`: + * New extensions on `CommonMessage`: `hasCommands` and `hasNoCommands`. Useful for the `initialFilter` parameter in behaviour builder triggers. + ## 3.3.0 **THIS VERSION CONTAINS UPGRADE KOTLIN (AND ALL RELATED LIBRARIES) UP TO 1.7.20** diff --git a/gradle.properties b/gradle.properties index 507af88d65..e27721d3cb 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.3.0 +library_version=3.3.1 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1f2b41c1c9..f9a27255a7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,14 +6,14 @@ kotlin-coroutines = "1.6.4" javax-activation = "1.1.1" -korlibs = "3.2.0" +korlibs = "3.3.1" uuid = "0.5.0" -ktor = "2.1.2" +ktor = "2.1.3" ksp = "1.7.20-1.0.7" kotlin-poet = "1.12.0" -microutils = "0.13.1" +microutils = "0.13.2" github-release-plugin = "2.4.1" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/MultipartRequestCallFactory.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/MultipartRequestCallFactory.kt index f52a9e87b3..0fdcd1c5af 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/MultipartRequestCallFactory.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/MultipartRequestCallFactory.kt @@ -17,7 +17,7 @@ class MultipartRequestCallFactory : AbstractRequestCallFactory() { ): Any? = (request as? MultipartRequest) ?.let { castedRequest -> MultiPartFormDataContent( formData { - val params = castedRequest.paramsJson.mapWithCommonValues() + val params = castedRequest.paramsJson.mapWithCommonValues() - castedRequest.mediaMap.keys for ((key, value) in castedRequest.mediaMap + params) { when (value) { is MultipartFile -> appendInput( diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/SetChatPhoto.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/SetChatPhoto.kt index be2dbcfc6d..aaf3817a4b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/SetChatPhoto.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/SetChatPhoto.kt @@ -13,6 +13,7 @@ import kotlinx.serialization.json.JsonObject data class SetChatPhoto ( @SerialName(chatIdField) override val chatId: ChatIdentifier, + @Transient val photo: MultipartFile = throw IllegalArgumentException("Unfortunately, this type of objects can't be parsed automatically") ): ChatRequest, MultipartRequest { override fun method(): String = "setChatPhoto" diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/MessageFilters.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/MessageFilters.kt new file mode 100644 index 0000000000..40d996bc6f --- /dev/null +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/MessageFilters.kt @@ -0,0 +1,44 @@ +package dev.inmo.tgbotapi.extensions.utils.updates + +import dev.inmo.tgbotapi.extensions.utils.* +import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage +import dev.inmo.tgbotapi.types.message.content.TextContent +import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource + +/** + * A predicate to test whether a message contains any commands in its body. + * Use it as the `initialFilter` parameter in behaviour builder triggers. + * E.g. + * + * ```kotlin + * onContentMessage( + * initialFilter = CommonMessage::hasCommands + * ) { + * // the message contains at least one command here + * } + * ``` + * + * @return true if this [CommonMessage] contains any commands. False otherwise. + * @see hasNoCommands + */ +fun CommonMessage<*>.hasCommands(): Boolean = withContentOrNull() ?.content ?.textSources ?.any { + it is BotCommandTextSource +} ?: false + +/** + * A predicate to test whether a message contains any commands in its body. + * Use it as the `initialFilter` parameter in behaviour builder triggers. + * E.g. + * + * ```kotlin + * onContentMessage( + * initialFilter = CommonMessage::hasNoCommands + * ) { + * // the message contains no commands here + * } + * ``` + * + * @return true if this [CommonMessage] does not contain any commands. False otherwise. + * @see hasCommands + */ +fun CommonMessage<*>.hasNoCommands(): Boolean = !this.hasCommands()