mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-24 19:18:44 +00:00
add CommonMessageFilterIncludeText
This commit is contained in:
parent
5ee87ac78d
commit
be25f705ef
@ -1,10 +1,8 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.filters
|
||||
|
||||
import dev.inmo.tgbotapi.abstracts.TextedInput
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.CommonMessageFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.not
|
||||
import dev.inmo.tgbotapi.extensions.utils.textedContentOrNull
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.content.MessageContent
|
||||
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
|
||||
|
||||
/**
|
||||
@ -21,13 +19,12 @@ fun CommonMessageFilterExcludeCommand(
|
||||
command: String?,
|
||||
textBeginOnly: Boolean = true
|
||||
): CommonMessageFilter<*> {
|
||||
val regex = when {
|
||||
return !CommonMessageFilterIncludeText(
|
||||
when {
|
||||
command == null -> BotCommandTextSource.CommandRegex
|
||||
textBeginOnly -> Regex("^[/!]$command(\\s|$)")
|
||||
!textBeginOnly -> Regex("[/!]$command(\\s|$)")
|
||||
else -> error("Unreachable code has been reached. It is error and must not happen")
|
||||
}
|
||||
return CommonMessageFilter {
|
||||
it.content.textedContentOrNull() ?.text ?.contains(regex) == true
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.filters
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.CommonMessageFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.textedContentOrNull
|
||||
|
||||
/**
|
||||
* Includes messages only contains text with [textRegex]
|
||||
*/
|
||||
fun CommonMessageFilterIncludeText(
|
||||
textRegex: Regex,
|
||||
): CommonMessageFilter<*> {
|
||||
return CommonMessageFilter {
|
||||
it.content.textedContentOrNull() ?.text ?.contains(textRegex) == true
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user