mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-24 02:58:43 +00:00
Update CommonMessageFilterExcludeCommand.kt
This commit is contained in:
parent
e895c2f3a8
commit
bc8da1120e
@ -6,24 +6,24 @@ import dev.inmo.tgbotapi.extensions.utils.textedContentOrNull
|
||||
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
|
||||
|
||||
/**
|
||||
* Use as initialFilter. Will exclude messages with [command] if it is not null, if null - all messages with commands.
|
||||
* Use as initialFilter. Will exclude messages with [excludedCommand] if it is not null, if null - all messages with commands.
|
||||
* If [textBeginOnly] set to false, all commands inside of message will be taken in attention.
|
||||
*
|
||||
* **Command line starts with `/` or `!`**
|
||||
* **It is supposed, that you will pass command name without `/` or `!`**
|
||||
*
|
||||
* @param command Pass non-null value to search specific command or null (default) to search any command
|
||||
* @param excludedCommand Pass non-null value to search specific command or null (default) to search any command
|
||||
* @param textBeginOnly Pass true (default) to check only start of message. Pass false to search in whole text of
|
||||
* content
|
||||
*/
|
||||
fun CommonMessageFilterExcludeCommand(
|
||||
command: String? = null,
|
||||
excludedCommand: String? = null,
|
||||
textBeginOnly: Boolean = true
|
||||
): CommonMessageFilter<*> {
|
||||
return !CommonMessageFilterIncludeText(
|
||||
when {
|
||||
command == null -> BotCommandTextSource.CommandRegex
|
||||
textBeginOnly -> Regex("^[/!]$command(\\s|$)")
|
||||
!textBeginOnly -> Regex("[/!]$command(\\s|$)")
|
||||
excludedCommand == null -> BotCommandTextSource.CommandRegex
|
||||
textBeginOnly -> Regex("^[/!]$excludedCommand(\\s|$)")
|
||||
!textBeginOnly -> Regex("[/!]$excludedCommand(\\s|$)")
|
||||
else -> error("Unreachable code has been reached. It is error and must not happen")
|
||||
}
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user