From 81fbff0bf5370d65547eb0e67ad4d4b2ec09c6c3 Mon Sep 17 00:00:00 2001 From: d1snin Date: Wed, 19 Oct 2022 22:15:15 +0300 Subject: [PATCH] added `BehaviourContext.waitCommandMessage` supporting `BotCommand` --- .../behaviour_builder/expectations/WaitCommandsMessages.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCommandsMessages.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCommandsMessages.kt index df34cfab1f..bd2927e5d5 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCommandsMessages.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCommandsMessages.kt @@ -4,6 +4,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.handlers_registrar.doWithRegistration import dev.inmo.tgbotapi.extensions.utils.* import dev.inmo.tgbotapi.requests.abstracts.Request +import dev.inmo.tgbotapi.types.BotCommand import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage import dev.inmo.tgbotapi.types.message.content.TextContent import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource @@ -39,6 +40,12 @@ suspend fun BehaviourContext.waitCommandMessage( errorFactory: NullableRequestBuilder<*> = { null } ) = waitCommandMessage(Regex(command), initRequest, errorFactory) +suspend fun BehaviourContext.waitCommandMessage( + botCommand: BotCommand, + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitCommandMessage(botCommand.command, initRequest, errorFactory) + fun Flow>.requireCommandAtStart() = filter { it.content.textSources.firstOrNull() is BotCommandTextSource }