mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
signature change in filterCommandsWithArgs
This commit is contained in:
parent
3fa3aa50d9
commit
314ceed78e
@ -60,6 +60,8 @@
|
||||
* `filterExactCommands`
|
||||
* `filterCommandsInsideTextMessages`
|
||||
* `filterCommandsWithArgs`
|
||||
* Extension `Flow<BaseSentMessageUpdate>.filterCommandsWithArgs` has changed its signature: now it will also have
|
||||
original message paired with list of text sources
|
||||
|
||||
## 0.27.0
|
||||
|
||||
|
@ -59,7 +59,8 @@ fun <T : ContentMessage<TextContent>> Flow<T>.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 <T : ContentMessage<TextContent>> Flow<T>.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()) {
|
||||
|
@ -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 <T : BaseSentMessageUpdate> Flow<T>.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 <T : BaseSentMessageUpdate> Flow<T>.filterCommandsInsideTextMessages(
|
||||
*/
|
||||
fun <T : BaseSentMessageUpdate> Flow<T>.filterCommandsWithArgs(
|
||||
commandRegex: Regex
|
||||
): Flow<List<TextSource>> = textMessages().filterCommandsWithArgs(commandRegex)
|
||||
): Flow<Pair<ContentMessage<TextContent>, List<TextSource>>> = textMessages().filterCommandsWithArgs(commandRegex)
|
||||
|
Loading…
Reference in New Issue
Block a user