-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #909 from InsanusMokrassar/18.2.2
18.2.2
- Loading branch information
Showing
19 changed files
with
555 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...v/inmo/tgbotapi/extensions/behaviour_builder/filters/CommonMessageFilterExcludeCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package dev.inmo.tgbotapi.extensions.behaviour_builder.filters | ||
|
||
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.textsources.BotCommandTextSource | ||
|
||
/** | ||
* 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. | ||
* | ||
* **It is supposed, that you will pass command name without `/` or `!`** | ||
* | ||
* @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( | ||
excludedCommand: String? = null, | ||
textBeginOnly: Boolean = true | ||
): CommonMessageFilter<*> { | ||
return !CommonMessageFilterIncludeText( | ||
when { | ||
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") | ||
} | ||
) | ||
} |
15 changes: 15 additions & 0 deletions
15
.../dev/inmo/tgbotapi/extensions/behaviour_builder/filters/CommonMessageFilterIncludeText.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.