1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-28 03:27:13 +00:00

Update CommonMessageFilterExcludeCommand.kt

This commit is contained in:
InsanusMokrassar 2024-10-17 00:42:40 +06:00 committed by GitHub
parent e895c2f3a8
commit bc8da1120e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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")
}
)