diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ec597eab9..2911765d28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,8 @@ * `filterExactCommands` * `filterCommandsInsideTextMessages` * `filterCommandsWithArgs` + * Extension `Flow.filterCommandsWithArgs` has changed its signature: now it will also have + original message paired with list of text sources ## 0.27.0 diff --git a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/shortcuts/CommandsShortcuts.kt b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/shortcuts/CommandsShortcuts.kt index bcca93193b..5ca97f63a3 100644 --- a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/shortcuts/CommandsShortcuts.kt +++ b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/shortcuts/CommandsShortcuts.kt @@ -59,7 +59,8 @@ fun > Flow.filterCommandsInsideTextMessages( * [RegularTextSource] will be split by " " for several [RegularTextSource] which will contains not empty args without * spaces. * - * @return Converted list with first entity [BotCommandTextSource] and than all others according to rules in description + * @return Paired original message and converted list with first entity [BotCommandTextSource] and than all others + * according to rules in description * * @see fullEntitiesList * @see asContentMessagesFlow @@ -72,7 +73,7 @@ fun > Flow.filterCommandsWithArgs( val allEntities = contentMessage.content.fullEntitiesList() (allEntities.firstOrNull() as? BotCommandTextSource) ?.let { if (commandRegex.matches(it.command)) { - allEntities.flatMap { + contentMessage to allEntities.flatMap { when (it) { is RegularTextSource -> it.source.split(" ").mapNotNull { regularTextSourcePart -> if (regularTextSourcePart.isNotBlank()) { diff --git a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/CommandsFilters.kt b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/CommandsFilters.kt index 826409e9d1..3a285f19ba 100644 --- a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/CommandsFilters.kt +++ b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/CommandsFilters.kt @@ -5,6 +5,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.onlyTextConte import com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.shortcuts.* import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.BotCommandTextSource import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.RegularTextSource +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.fullEntitiesList import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseSentMessageUpdate import kotlinx.coroutines.flow.* @@ -50,7 +52,8 @@ fun Flow.filterCommandsInsideTextMessages( * [RegularTextSource] will be split by " " for several [RegularTextSource] which will contains not empty args without * spaces. * - * @return Converted list with first entity [BotCommandTextSource] and than all others according to rules in description + * @return Paired original message and converted list with first entity [BotCommandTextSource] and than all others + * according to rules in description * * @see fullEntitiesList * @see asContentMessagesFlow @@ -58,4 +61,4 @@ fun Flow.filterCommandsInsideTextMessages( */ fun Flow.filterCommandsWithArgs( commandRegex: Regex -): Flow> = textMessages().filterCommandsWithArgs(commandRegex) +): Flow, List>> = textMessages().filterCommandsWithArgs(commandRegex)