diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCallbackQuery.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCallbackQuery.kt index efb5f7c33b..f02c6cd3bf 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCallbackQuery.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCallbackQuery.kt @@ -35,23 +35,23 @@ private suspend inline fun BehaviourContext.waitCall count: Int = 1, initRequest: Request<*>? = null, noinline errorFactory: NullableRequestBuilder<*> = { null }, - filter: SimpleFilter? = null, - noinline filter: CallbackQueryMapper? = null + noinline filter: SimpleFilter? = null, + noinline mapper: CallbackQueryMapper? = null ) : List = waitCallbackQueries( count, initRequest, errorFactory, filter ?.let { { - (it as? T) ?.let(::filter) + (it as? T) ?.let { filter(it) } == true } } ) { if (this is T) { - if (filter == null) { + if (mapper == null) { this } else { - filter(this) + mapper(this) } } else { null diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt index 450fcbd96c..801bdf0384 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt @@ -15,16 +15,16 @@ private suspend inline fun BehaviourContex count: Int = 1, initRequest: Request<*>? = null, noinline errorFactory: NullableRequestBuilder<*> = { null }, - filter: SimpleFilter? = null, + noinline filter: SimpleFilter? = null, noinline mapper: ChatMemberUpdatedMapper ): List = expectFlow( initRequest, count, errorFactory ) { - val data = (it as? T) ?.data ?: return@expectFlow emptyList() - if (filter == null || filter(data)) { - data.mapper().let(::listOfNotNull) + val casted = (it as? T) ?: return@expectFlow emptyList() + if (filter == null || filter(casted)) { + casted.data.mapper().let(::listOfNotNull) } else { emptyList() } @@ -34,7 +34,7 @@ private suspend inline fun BehaviourContex count: Int = 1, initRequest: Request<*>? = null, noinline errorFactory: NullableRequestBuilder<*> = { null }, - filter: SimpleFilter? = null, + noinline filter: SimpleFilter? = null, noinline mapper: ChatMemberUpdatedMapper? = null ) : List = waitChatMemberUpdated( count, diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt index 81a36a1282..d1415d89bd 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt @@ -56,14 +56,18 @@ private suspend inline fun BehaviourContext.waitCon initRequest: Request<*>? = null, includeMediaGroups: Boolean = true, noinline errorFactory: NullableRequestBuilder<*> = { null }, - filter: SimpleFilter>? = null, + noinline filter: SimpleFilter>? = null, noinline mapper: CommonMessageToContentMapper? = null ) : List = waitCommonMessage( count, initRequest, includeMediaGroups, errorFactory, - filter + filter ?.let { + { + it.withContent() ?.let { filter(it) } == true + } + } ) { if (content is T) { @Suppress("UNCHECKED_CAST") diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt index abae5ddeb9..c0f7d534be 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt @@ -39,13 +39,17 @@ private suspend inline fun BehaviourContext.waitEvents( count: Int = 1, initRequest: Request<*>? = null, noinline errorFactory: NullableRequestBuilder<*> = { null }, - filter: SimpleFilter>? = null, + noinline filter: SimpleFilter>? = null, noinline mapper: EventMessageToEventMapper? = null ) : List = waitEventMessages( initRequest, errorFactory, count, - filter + filter ?.let { + { + (it.chatEvent as? T) ?.let { filter(it as ChatEventMessage) } == true + } + } ) { if (chatEvent is T) { @Suppress("UNCHECKED_CAST") diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitInlineQuery.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitInlineQuery.kt index 9c287a2d4a..1089c62113 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitInlineQuery.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitInlineQuery.kt @@ -33,19 +33,23 @@ private suspend inline fun BehaviourContext.waitInline count: Int = 1, initRequest: Request<*>? = null, noinline errorFactory: NullableRequestBuilder<*> = { null }, - filter: SimpleFilter? = null, + noinline filter: SimpleFilter? = null, noinline mapper: InlineQueryMapper? = null ) : List = waitInlineQueries( count, initRequest, errorFactory, - filter + filter ?.let { + { + (it as? T) ?.let { casted -> filter(casted) } == true + } + } ) { if (this is T) { - if (filter == null) { + if (mapper == null) { this } else { - filter(this) + mapper(this) } } else { null diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt index 6a858c5aea..22fa5b7313 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt @@ -37,7 +37,7 @@ suspend inline fun BehaviourContext.waitP count: Int = 1, initRequest: Request<*>? = null, noinline errorFactory: NullableRequestBuilder<*> = { null }, - filter: SimpleFilter? = null, + noinline filter: SimpleFilter? = null, noinline mapper: PassportMessageMapper? = null ) : List = waitPassportMessages( initRequest,