From ce0fceb240384f9c874f99f3b86254b9bbb05732 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 8 Jan 2021 00:22:19 +0600 Subject: [PATCH] include media groups --- .../behaviour_builder/expectations/Base.kt | 18 +++--- .../expectations/WaitCallbackQuery.kt | 2 +- .../expectations/WaitContent.kt | 56 ++++++++++------- .../expectations/WaitEventAction.kt | 2 +- .../CallbackQueryTriggers.kt | 2 +- .../triggers_handling/ContentTriggers.kt | 62 +++++++++++-------- .../triggers_handling/EventTriggers.kt | 2 +- 7 files changed, 83 insertions(+), 61 deletions(-) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/Base.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/Base.kt index 7ce3c98fda..d1cc0925c3 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/Base.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/Base.kt @@ -34,11 +34,11 @@ suspend fun FlowsUpdatesFilter.expectFlow( errorFactory: NullableRequestBuilder<*> = { null }, cancelRequestFactory: NullableRequestBuilder<*> = { null }, cancelTrigger: suspend (Update) -> Boolean = { cancelRequestFactory(it) != null }, - filter: suspend (Update) -> T? + filter: suspend (Update) -> List ): Flow { - val flow = allUpdatesFlow.mapNotNull { + val flow = allUpdatesFlow.flatMapConcat { val result = safelyWithoutExceptions { filter(it) } - if (result == null) { + (if (result == null || result.isEmpty()) { if (cancelTrigger(it)) { cancelRequestFactory(it) ?.also { safelyWithoutExceptions { bot.execute(it) } @@ -48,10 +48,10 @@ suspend fun FlowsUpdatesFilter.expectFlow( errorFactory(it) ?.also { errorRequest -> safelyWithoutExceptions { bot.execute(errorRequest) } } - null + emptyList() } else { result - } + }).asFlow() } val result = if (count == null) { flow @@ -79,7 +79,7 @@ suspend fun BehaviourContext.expectFlow( errorFactory: NullableRequestBuilder<*> = { null }, cancelRequestFactory: NullableRequestBuilder<*> = { null }, cancelTrigger: suspend (Update) -> Boolean = { cancelRequestFactory(it) != null }, - filter: suspend (Update) -> T? + filter: suspend (Update) -> List ) = flowsUpdatesFilter.expectFlow(bot, initRequest, count, errorFactory, cancelRequestFactory, cancelTrigger, filter) /** @@ -99,8 +99,10 @@ suspend fun FlowsUpdatesFilter.expectOne( errorFactory: NullableRequestBuilder<*> = { null }, cancelRequestFactory: NullableRequestBuilder<*> = { null }, cancelTrigger: suspend (Update) -> Boolean = { cancelRequestFactory(it) != null }, - filter: suspend (Update) -> T?, -): T = expectFlow(bot, initRequest, 1, errorFactory, cancelRequestFactory, cancelTrigger, filter).first() + filter: suspend (Update) -> T? +): T = expectFlow(bot, initRequest, 1, errorFactory, cancelRequestFactory, cancelTrigger) { + listOfNotNull(filter.invoke(it)) +}.first() /** * @param initRequest If not null, this request will be sent by [bot] before returning value 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 e856bcf7ee..5676bb0054 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 @@ -20,7 +20,7 @@ private suspend fun BehaviourContext.waitCallbackQueries( count, errorFactory ) { - it.asCallbackQueryUpdate() ?.data ?.mapper() + it.asCallbackQueryUpdate() ?.data ?.mapper().let(::listOfNotNull) }.toList().toList() 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 059cc75466..0b9e5a6df4 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 @@ -3,10 +3,10 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext -import dev.inmo.tgbotapi.extensions.utils.asContentMessage -import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate +import dev.inmo.tgbotapi.extensions.utils.* import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.content.* import dev.inmo.tgbotapi.types.message.content.abstracts.* import dev.inmo.tgbotapi.types.message.content.media.* @@ -18,6 +18,7 @@ typealias ContentMessageToContentMapper = suspend ContentMessage.() -> T? private suspend fun BehaviourContext.waitContentMessage( count: Int = 1, initRequest: Request<*>? = null, + includeMediaGroups: Boolean = true, errorFactory: NullableRequestBuilder<*> = { null }, mapper: suspend ContentMessage.() -> O? ): List = expectFlow( @@ -25,17 +26,24 @@ private suspend fun BehaviourContext.waitContentMessage( count, errorFactory ) { - it.asMessageUpdate() ?.data ?.asContentMessage() ?.mapper() + if (includeMediaGroups) { + it.asSentMediaGroupUpdate() ?.data ?.mapNotNull { + (it as ContentMessage).mapper() + } ?.let { return@expectFlow it } + } + it.asMessageUpdate() ?.data ?.asContentMessage() ?.mapper().let(::listOfNotNull) }.toList().toList() private suspend inline fun BehaviourContext.waitContent( count: Int = 1, initRequest: Request<*>? = null, + includeMediaGroups: Boolean = true, noinline errorFactory: NullableRequestBuilder<*> = { null }, noinline filter: ContentMessageToContentMapper? = null ) : List = waitContentMessage( count, initRequest, + includeMediaGroups, errorFactory ) { if (content is T) { @@ -56,124 +64,124 @@ suspend fun BehaviourContext.waitContact( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, false, errorFactory, filter) suspend fun BehaviourContext.waitDice( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, false, errorFactory, filter) suspend fun BehaviourContext.waitGame( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, false, errorFactory, filter) suspend fun BehaviourContext.waitLocation( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, false, errorFactory, filter) suspend fun BehaviourContext.waitPoll( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, false, errorFactory, filter) suspend fun BehaviourContext.waitText( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, false, errorFactory, filter) suspend fun BehaviourContext.waitVenue( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, false, errorFactory, filter) suspend fun BehaviourContext.waitAudioMediaGroup( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, true, errorFactory, filter) suspend fun BehaviourContext.waitDocumentMediaGroup( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, true, errorFactory, filter) suspend fun BehaviourContext.waitMedia( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, true, errorFactory, filter) suspend fun BehaviourContext.waitMediaGroup( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, true, errorFactory, filter) suspend fun BehaviourContext.waitVisualMediaGroup( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, true, errorFactory, filter) suspend fun BehaviourContext.waitAnimation( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, false, errorFactory, filter) suspend fun BehaviourContext.waitAudio( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, true, errorFactory, filter) suspend fun BehaviourContext.waitDocument( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, true, errorFactory, filter) suspend fun BehaviourContext.waitPhoto( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, true, errorFactory, filter) suspend fun BehaviourContext.waitSticker( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, false, errorFactory, filter) suspend fun BehaviourContext.waitVideo( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, true, errorFactory, filter) suspend fun BehaviourContext.waitVideoNote( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, false, errorFactory, filter) suspend fun BehaviourContext.waitVoice( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, true, errorFactory, filter) suspend fun BehaviourContext.waitInvoice( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, filter: ContentMessageToContentMapper? = null -) = waitContent(count, initRequest, errorFactory, filter) +) = waitContent(count, initRequest, false, errorFactory, filter) 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 b4f67e1a35..e9ee547eb7 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 @@ -23,7 +23,7 @@ private suspend fun BehaviourContext.waitEventMessages( count, errorFactory ) { - it.asMessageUpdate() ?.data ?.asChatEventMessage() ?.mapper() + it.asMessageUpdate() ?.data ?.asChatEventMessage() ?.mapper().let(::listOfNotNull) }.toList().toList() diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt index 139e2a1f75..5432c7fa58 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt @@ -25,7 +25,7 @@ internal suspend inline fun BehaviourContext.onCallb } else { null } - } + }.let(::listOfNotNull) }.subscribeSafelyWithoutExceptions(scope) { triggerQuery -> val (jobToCancel, scenario) = if (includeFilterByChatInBehaviourSubContext) { val subFilter = FlowsUpdatesFilter() diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt index 451f9dad4f..deab6df207 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt @@ -6,8 +6,7 @@ import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTypeReceiver import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow -import dev.inmo.tgbotapi.extensions.utils.asContentMessage -import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate +import dev.inmo.tgbotapi.extensions.utils.* import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage @@ -21,9 +20,22 @@ import kotlinx.coroutines.flow.filter internal suspend inline fun BehaviourContext.onContent( includeFilterByChatInBehaviourSubContext: Boolean = true, + includeMediaGroups: Boolean = true, noinline additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> ) = flowsUpdatesFilter.expectFlow(bot) { + if (includeMediaGroups) { + it.asSentMediaGroupUpdate() ?.data ?.mapNotNull { + if (it.content is T) { + val adaptedMessage = it as ContentMessage + if (additionalFilter == null || additionalFilter(adaptedMessage)) adaptedMessage else null + } else { + null + } + } ?.let { + return@expectFlow it + } + } it.asMessageUpdate() ?.data ?.asContentMessage() ?.let { message -> if (message.content is T) { val adaptedMessage = message as ContentMessage @@ -31,7 +43,7 @@ internal suspend inline fun BehaviourContext.onCont } else { null } - } + }.let(::listOfNotNull) }.subscribeSafelyWithoutExceptions(scope) { triggerMessage -> val (jobToCancel, scenario) = if (includeFilterByChatInBehaviourSubContext) { val subFilter = FlowsUpdatesFilter() @@ -52,109 +64,109 @@ suspend fun BehaviourContext.onContact( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onDice( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onGame( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onLocation( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onPoll( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onText( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onVenue( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onAudioMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onDocumentMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onMediaCollection( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage>) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onMedia( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onVisualMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onAnimation( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onAudio( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onDocument( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onPhoto( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onSticker( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onVideo( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onVideoNote( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onVoice( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onInvoice( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ContentMessage) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt index 9befcde684..c3a9d1b0da 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt @@ -29,7 +29,7 @@ internal suspend inline fun BehaviourContext.onEvent( } else { null } - } + }.let(::listOfNotNull) }.subscribeSafelyWithoutExceptions(scope) { triggerMessage -> val (jobToCancel, scenario) = if (includeFilterByChatInBehaviourSubContext) { val subFilter = FlowsUpdatesFilter()