diff --git a/CHANGELOG.md b/CHANGELOG.md index eabd6a44c3..3b064a4f38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,20 @@ * `closePollExactAfter` * `closePollAfter` +### 0.27.4 + +* `TelegramBotAPI-extensions-utils`: + * Several extensions for updates was added: + * `onlyBaseMessageUpdates` + * `onlySentMessageUpdates` + * `onlyEditMessageUpdates` + * `onlyMediaGroupsUpdates` + * `onlySentMediaGroupUpdates` + * `onlyEditMediaGroupUpdates` + * Renames in chat filters extensions: + * `filterBaseMessageUpdates` -> `filterBaseMessageUpdatesByChatId` and `filterBaseMessageUpdatesByChat` + * `filterSentMediaGroupUpdates` -> `filterSentMediaGroupUpdatesByChatId` and `filterSentMediaGroupUpdatesByChat` + ### 0.27.3 * `TelegramBotAPI`: diff --git a/TelegramBotAPI-all/maven.publish.gradle b/TelegramBotAPI-all/maven.publish.gradle index b81cdc6f73..173e11888f 100644 --- a/TelegramBotAPI-all/maven.publish.gradle +++ b/TelegramBotAPI-all/maven.publish.gradle @@ -20,37 +20,33 @@ publishing { publications.all { artifact javadocsJar - pom.withXml { - asNode().children().last() + { - resolveStrategy = Closure.DELEGATE_FIRST + pom { + description = "This project just include all subproject of TelegramBotAPI" + name = "Telegram Bot API All" + url = "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-all" - description "This project just include all subproject of TelegramBotAPI" - name "Telegram Bot API All" - url "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-all" + scm { + developerConnection = "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git" + url = "https://github.com/insanusmokrassar/TelegramBotAPI.git" + } - scm { - developerConnection "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git" - url "https://github.com/insanusmokrassar/TelegramBotAPI.git" - } + developers { + + developer { + id = "InsanusMokrassar" + name = "Ovsiannikov Aleksei" + email = "ovsyannikov.alexey95@gmail.com" + } + + } - developers { - - developer { - id "InsanusMokrassar" - name "Ovsiannikov Aleksei" - email "ovsyannikov.alexey95@gmail.com" - } - - } - - licenses { - - license { - name "Apache Software License 2.0" - url "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE" - } - - } + licenses { + + license { + name = "Apache Software License 2.0" + url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE" + } + } } } diff --git a/TelegramBotAPI-extensions-api/maven.publish.gradle b/TelegramBotAPI-extensions-api/maven.publish.gradle index ec352c0e8c..799421de47 100644 --- a/TelegramBotAPI-extensions-api/maven.publish.gradle +++ b/TelegramBotAPI-extensions-api/maven.publish.gradle @@ -20,37 +20,33 @@ publishing { publications.all { artifact javadocsJar - pom.withXml { - asNode().children().last() + { - resolveStrategy = Closure.DELEGATE_FIRST + pom { + description = "API extensions which provide work with RequestsExecutor of TelegramBotAPI almost like it is described in original Telegram Bot API reference" + name = "Telegram Bot API Extensions for API" + url = "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-api" - description "API extensions which provide work with RequestsExecutor of TelegramBotAPI almost like it is described in original Telegram Bot API reference" - name "Telegram Bot API Extensions for API" - url "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-api" + scm { + developerConnection = "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git" + url = "https://github.com/insanusmokrassar/TelegramBotAPI.git" + } - scm { - developerConnection "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git" - url "https://github.com/insanusmokrassar/TelegramBotAPI.git" - } + developers { + + developer { + id = "InsanusMokrassar" + name = "Ovsiannikov Aleksei" + email = "ovsyannikov.alexey95@gmail.com" + } + + } - developers { - - developer { - id "InsanusMokrassar" - name "Ovsiannikov Aleksei" - email "ovsyannikov.alexey95@gmail.com" - } - - } - - licenses { - - license { - name "Apache Software License 2.0" - url "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE" - } - - } + licenses { + + license { + name = "Apache Software License 2.0" + url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE" + } + } } } diff --git a/TelegramBotAPI-extensions-utils/README.md b/TelegramBotAPI-extensions-utils/README.md index e2078e7f8b..b5b17083d1 100644 --- a/TelegramBotAPI-extensions-utils/README.md +++ b/TelegramBotAPI-extensions-utils/README.md @@ -166,6 +166,32 @@ application without creating of new one server (as it is happening in `startList There are several filters for flows. +#### Updates + +In the next table it is supposed that you are using some `Flow` with type from `Base type of update` and apply +extension `Extension` and will get `Flow` with type from `Result type of update` column. + +| Base type of update | Extension | Result type of update | +| ------------------- | --------- | --------------------- | +| `Update` | `onlyBaseMessageUpdates` | `BaseMessageUpdate` | +| | | | +| `BaseMessageUpdate` | `onlySentMessageUpdates` | `BaseSentMessageUpdate` | +| `BaseMessageUpdate` | `onlyEditMessageUpdates` | `BaseEditMessageUpdate` | +| `BaseMessageUpdate` | `onlyMediaGroupsUpdates` | `MediaGroupUpdate` | +| | | | +| `MediaGroupUpdate` | `onlySentMediaGroupUpdates` | `SentMediaGroupUpdate` | +| `MediaGroupUpdate` | `onlyEditMediaGroupUpdates` | `EditMediaGroupUpdate` | + +All of these extensions was made for more simple work with the others: + +```kotlin +val flow: Flow = ...; // here we are getting flow from somewhere, + // for example, FlowsUpdatesFilter#messageFlow +flow.onlySentMessageUpdates().filterExactCommands(Regex("start")) +``` + +Here we have used filter `filterExactCommands` which will pass only `ContentMessage` with only one command `start` + #### Sent messages All sent messages can be filtered for three types: diff --git a/TelegramBotAPI-extensions-utils/maven.publish.gradle b/TelegramBotAPI-extensions-utils/maven.publish.gradle index 61f4b51a17..c8600ea641 100644 --- a/TelegramBotAPI-extensions-utils/maven.publish.gradle +++ b/TelegramBotAPI-extensions-utils/maven.publish.gradle @@ -20,37 +20,33 @@ publishing { publications.all { artifact javadocsJar - pom.withXml { - asNode().children().last() + { - resolveStrategy = Closure.DELEGATE_FIRST + pom { + description = "Util extensions for more useful work with updates and other things" + name = "Telegram Bot API Utility Extensions" + url = "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-utils" - description "Util extensions for more useful work with updates and other things" - name "Telegram Bot API Utility Extensions" - url "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-utils" + scm { + developerConnection = "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git" + url = "https://github.com/insanusmokrassar/TelegramBotAPI.git" + } - scm { - developerConnection "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git" - url "https://github.com/insanusmokrassar/TelegramBotAPI.git" - } + developers { + + developer { + id = "InsanusMokrassar" + name = "Ovsiannikov Aleksei" + email = "ovsyannikov.alexey95@gmail.com" + } + + } - developers { - - developer { - id "InsanusMokrassar" - name "Ovsiannikov Aleksei" - email "ovsyannikov.alexey95@gmail.com" - } - - } - - licenses { - - license { - name "Apache Software License 2.0" - url "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE" - } - - } + licenses { + + license { + name = "Apache Software License 2.0" + url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE" + } + } } } diff --git a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/BaseMessagesUpdatesConversations.kt b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/BaseMessagesUpdatesConversations.kt new file mode 100644 index 0000000000..1280b4a397 --- /dev/null +++ b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/BaseMessagesUpdatesConversations.kt @@ -0,0 +1,49 @@ +package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates + +import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.* +import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.* +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.mapNotNull + +fun Flow.onlyBaseMessageUpdates(): Flow = mapNotNull { + it as? BaseMessageUpdate +} + +/** + * Converts flow to [Flow] of [BaseSentMessageUpdate] + */ +fun Flow.onlySentMessageUpdates(): Flow = mapNotNull { + it as? BaseSentMessageUpdate +} + +/** + * Converts flow to [Flow] of [BaseSentMessageUpdate] + */ +fun Flow.onlyEditMessageUpdates(): Flow = mapNotNull { + it as? BaseEditMessageUpdate +} + +/** + * Converts flow to [Flow] of [MediaGroupUpdate]. Please, remember that it could be either [EditMediaGroupUpdate] + * or [SentMediaGroupUpdate] + * + * @see onlySentMediaGroupUpdates + * @see onlyEditMediaGroupUpdates + */ +fun Flow.onlyMediaGroupsUpdates(): Flow = mapNotNull { + it as? MediaGroupUpdate +} + +/** + * Converts flow to [Flow] of [SentMediaGroupUpdate] + */ +fun Flow.onlySentMediaGroupUpdates(): Flow = mapNotNull { + it as? SentMediaGroupUpdate +} + +/** + * Converts flow to [Flow] of [EditMediaGroupUpdate] + */ +fun Flow.onlyEditMediaGroupUpdates(): Flow = mapNotNull { + it as? EditMediaGroupUpdate +} diff --git a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/UpdatesChatFilters.kt b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/UpdatesChatFilters.kt index 4ee90dd8f9..1812a94ec1 100644 --- a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/UpdatesChatFilters.kt +++ b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/UpdatesChatFilters.kt @@ -10,22 +10,38 @@ import kotlinx.coroutines.flow.filter /** * [Flow.filter] incoming [BaseMessageUpdate]s by their [ChatId] */ -fun Flow.filterBaseMessageUpdates(chatId: ChatId): Flow = filter { - it.data.chat.id == chatId -} +fun Flow.filterBaseMessageUpdatesByChatId(chatId: ChatId): Flow = filter { it.data.chat.id == chatId } /** * [Flow.filter] incoming [BaseMessageUpdate]s by their [ChatId] using [Chat.id] of [chat] */ -fun Flow.filterBaseMessageUpdates(chat: Chat): Flow = filterBaseMessageUpdates(chat.id) +fun Flow.filterBaseMessageUpdatesByChat(chat: Chat): Flow = filterBaseMessageUpdatesByChatId(chat.id) +/** + * [Flow.filter] incoming [BaseMessageUpdate]s by their [ChatId] + */ +@Deprecated("Renamed", ReplaceWith("filterBaseMessageUpdatesByChatId")) +fun Flow.filterBaseMessageUpdates(chatId: ChatId): Flow = filterBaseMessageUpdatesByChatId(chatId) +/** + * [Flow.filter] incoming [BaseMessageUpdate]s by their [ChatId] using [Chat.id] of [chat] + */ +@Deprecated("Renamed", ReplaceWith("filterBaseMessageUpdatesByChat")) +fun Flow.filterBaseMessageUpdates(chat: Chat): Flow = filterBaseMessageUpdatesByChatId(chat.id) /** * [Flow.filter] incoming [SentMediaGroupUpdate]s by their [ChatId] */ -fun Flow.filterSentMediaGroupUpdates(chatId: ChatId): Flow = filter { - it.data.first().chat.id == chatId -} +fun Flow.filterSentMediaGroupUpdatesByChatId(chatId: ChatId): Flow = filter { it.data.first().chat.id == chatId } /** * [Flow.filter] incoming [SentMediaGroupUpdate]s by their [ChatId] using [Chat.id] of [chat] */ -fun Flow.filterSentMediaGroupUpdates(chat: Chat): Flow = filterSentMediaGroupUpdates(chat.id) +fun Flow.filterSentMediaGroupUpdatesByChat(chat: Chat): Flow = filterSentMediaGroupUpdatesByChatId(chat.id) +/** + * [Flow.filter] incoming [SentMediaGroupUpdate]s by their [ChatId] + */ +@Deprecated("Renamed", ReplaceWith("filterSentMediaGroupUpdatesByChatId")) +fun Flow.filterSentMediaGroupUpdates(chatId: ChatId): Flow = filterSentMediaGroupUpdatesByChatId(chatId) +/** + * [Flow.filter] incoming [SentMediaGroupUpdate]s by their [ChatId] using [Chat.id] of [chat] + */ +@Deprecated("Renamed", ReplaceWith("filterSentMediaGroupUpdatesByChat")) +fun Flow.filterSentMediaGroupUpdates(chat: Chat): Flow = filterSentMediaGroupUpdatesByChatId(chat.id) diff --git a/TelegramBotAPI/maven.publish.gradle b/TelegramBotAPI/maven.publish.gradle index 4b5c24a389..9dc4d90cfa 100644 --- a/TelegramBotAPI/maven.publish.gradle +++ b/TelegramBotAPI/maven.publish.gradle @@ -20,37 +20,33 @@ publishing { publications.all { artifact javadocsJar - pom.withXml { - asNode().children().last() + { - resolveStrategy = Closure.DELEGATE_FIRST + pom { + description = "Library for Object-Oriented and type-safe work with Telegram Bot API" + name = "Telegram Bot API" + url = "https://insanusmokrassar.github.io/TelegramBotAPI" - description "Library for Object-Oriented and type-safe work with Telegram Bot API" - name "Telegram Bot API" - url "https://insanusmokrassar.github.io/TelegramBotAPI" + scm { + developerConnection = "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git" + url = "https://github.com/insanusmokrassar/TelegramBotAPI.git" + } - scm { - developerConnection "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git" - url "https://github.com/insanusmokrassar/TelegramBotAPI.git" - } + developers { + + developer { + id = "InsanusMokrassar" + name = "Ovsiannikov Aleksei" + email = "ovsyannikov.alexey95@gmail.com" + } + + } - developers { - - developer { - id "InsanusMokrassar" - name "Ovsiannikov Aleksei" - email "ovsyannikov.alexey95@gmail.com" - } - - } - - licenses { - - license { - name "Apache Software License 2.0" - url "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE" - } - - } + licenses { + + license { + name = "Apache Software License 2.0" + url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE" + } + } } } diff --git a/gradle.properties b/gradle.properties index 6a07572a4d..3c87806a9d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,6 +9,6 @@ ktor_version=1.3.2 javax_activation_version=1.1.1 library_group=com.github.insanusmokrassar -library_version=0.27.3 +library_version=0.27.4 gradle_bintray_plugin_version=1.8.4