1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-29 04:47:48 +00:00
tgbotapi/tgbotapi.extensions.steps/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/steps/triggers_handling/CommandHandling.kt

31 lines
1.0 KiB
Kotlin
Raw Normal View History

2021-01-06 17:06:48 +00:00
package dev.inmo.tgbotapi.extensions.steps.triggers_handling
import dev.inmo.tgbotapi.CommonAbstracts.textSources
import dev.inmo.tgbotapi.extensions.steps.*
import dev.inmo.tgbotapi.extensions.utils.*
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.TextContent
import kotlinx.coroutines.Job
2021-01-06 17:06:48 +00:00
suspend fun Scenario.command(
commandRegex: Regex,
requireOnlyCommandInMessage: Boolean = true,
includeFilterByChatInSubScenario: Boolean = true,
2021-01-06 17:06:48 +00:00
scenarioReceiver: ScenarioAndTypeReceiver<Unit, ContentMessage<TextContent>>
): Job = onText(
includeFilterByChatInSubScenario,
{ message ->
val content = message.content
val textSources = content.textSources
val sizeRequirement = if (requireOnlyCommandInMessage) {
textSources.size == 1
} else {
true
2021-01-06 17:06:48 +00:00
}
sizeRequirement && textSources.any { commandRegex.matches(it.asBotCommandTextSource() ?.command ?: return@any false) }
},
scenarioReceiver
)
2021-01-06 17:06:48 +00:00