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 5da55b1abb..e6e4c3b565 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 @@ -1,20 +1,18 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling - -import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow -import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.optionallyWrapWithLaunch +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserCallbackQueryMarkerFactory +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.asCallbackQueryUpdate import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.types.CallbackQuery.* -import kotlinx.coroutines.Job -import kotlinx.coroutines.launch internal suspend inline fun BehaviourContext.onCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (T) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver ) = flowsUpdatesFilter.expectFlow(bot) { it.asCallbackQueryUpdate() ?.data ?.let { query -> @@ -24,75 +22,75 @@ internal suspend inline fun BehaviourContext.onCallb null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions( +}.subscribeSafelyWithoutExceptionsAsync( scope, - optionallyWrapWithLaunch(performInParallel) { triggerQuery -> - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == triggerQuery.user.id.chatId } - } else { - null - }, - stopOnCompletion = false - ) { - scenarioReceiver(triggerQuery) - } + markerFactory::invoke +) { triggerQuery -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerQuery.user.id.chatId } + } else { + null + }, + stopOnCompletion = false + ) { + scenarioReceiver(triggerQuery) } -) +} suspend fun BehaviourContext.onDataCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (DataCallbackQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onGameShortNameCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (GameShortNameCallbackQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onInlineMessageIdCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (InlineMessageIdCallbackQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onInlineMessageIdDataCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (InlineMessageIdDataCallbackQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onInlineMessageIdGameShortNameCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (InlineMessageIdGameShortNameCallbackQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMessageCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (MessageCallbackQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMessageDataCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (MessageDataCallbackQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMessageGameShortNameCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (MessageGameShortNameCallbackQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onUnknownCallbackQueryType( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (UnknownCallbackQueryType) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt index bb9d7bb9e1..eff524264b 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt @@ -1,74 +1,73 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling -import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +import dev.inmo.micro_utils.coroutines.subscribeSafelySkippingExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow -import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.optionallyWrapWithLaunch +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatChatMemberUpdatedMarkerFactory +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.types.ChatMemberUpdated import dev.inmo.tgbotapi.types.update.CommonChatMemberUpdatedUpdate import dev.inmo.tgbotapi.types.update.MyChatMemberUpdatedUpdate import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate -import kotlinx.coroutines.Job -import kotlinx.coroutines.launch internal suspend inline fun BehaviourContext.onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver ) = flowsUpdatesFilter.expectFlow(bot) { (it as? U) ?.data ?.let { chatMemberUpdated -> if (additionalFilter == null || additionalFilter(chatMemberUpdated)) chatMemberUpdated else null }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions( +}.subscribeSafelySkippingExceptionsAsync( scope, - optionallyWrapWithLaunch(performInParallel) { triggerChatMemberUpdated -> - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == triggerChatMemberUpdated.chat.id.chatId } - } else { - null - }, - stopOnCompletion = false - ) { - scenarioReceiver(triggerChatMemberUpdated) - } + markerFactory::invoke +) { triggerChatMemberUpdated -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerChatMemberUpdated.chat.id.chatId } + } else { + null + }, + stopOnCompletion = false + ) { + scenarioReceiver(triggerChatMemberUpdated) } -) +} suspend fun BehaviourContext.onChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext, additionalFilter, - performInParallel, + markerFactory, scenarioReceiver ) suspend fun BehaviourContext.onCommonChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext, additionalFilter, - performInParallel, + markerFactory, scenarioReceiver ) suspend fun BehaviourContext.onMyChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext, additionalFilter, - performInParallel, + markerFactory, scenarioReceiver ) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt index 14fa5ac397..9e90a3cd70 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt @@ -2,6 +2,8 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTypeReceiver +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.asBotCommandTextSource import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage import dev.inmo.tgbotapi.types.message.content.TextContent @@ -12,7 +14,7 @@ suspend fun BehaviourContext.command( requireOnlyCommandInMessage: Boolean = true, includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ): Job = onText( includeFilterByChatInBehaviourSubContext, @@ -28,7 +30,7 @@ suspend fun BehaviourContext.command( commandRegex.matches(it.asBotCommandTextSource() ?.command ?: return@any false) } && (additionalFilter ?.invoke(message) != false) }, - performInParallel, + markerFactory, scenarioReceiver ) suspend fun BehaviourContext.command( @@ -36,24 +38,24 @@ suspend fun BehaviourContext.command( requireOnlyCommandInMessage: Boolean = true, includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = command(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = command(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend inline fun BehaviourContext.onCommand( commandRegex: Regex, requireOnlyCommandInMessage: Boolean = true, includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> -): Job = command(commandRegex, requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +): Job = command(commandRegex, requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend inline fun BehaviourContext.onCommand( command: String, requireOnlyCommandInMessage: Boolean = true, includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> -): Job = onCommand(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +): Job = onCommand(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) 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 5f078c986e..6dcab2502f 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 @@ -2,10 +2,11 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling -import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow -import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.optionallyWrapWithLaunch +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.* import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile @@ -23,7 +24,7 @@ internal suspend inline fun BehaviourContext.onCont includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = true, noinline additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> ) = flowsUpdatesFilter.expectFlow(bot) { if (includeMediaGroups) { @@ -46,152 +47,152 @@ internal suspend inline fun BehaviourContext.onCont null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions( +}.subscribeSafelyWithoutExceptionsAsync( scope, - optionallyWrapWithLaunch(performInParallel) { triggerMessage -> - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } - } else { - null - }, - stopOnCompletion = false - ) { - scenarioReceiver(triggerMessage) - } + markerFactory::invoke +) { triggerMessage -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } + } else { + null + }, + stopOnCompletion = false + ) { + scenarioReceiver(triggerMessage) } -) +} suspend fun BehaviourContext.onContentMessage( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onContact( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onDice( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onGame( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onLocation( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onPoll( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onText( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVenue( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onAudioMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onDocumentMediaGroupContent( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMediaCollection( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: (suspend (CommonMessage>) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory>, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMedia( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onAnimation( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onAudio( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onDocument( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onPhoto( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onSticker( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVideo( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVideoNote( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoice( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onInvoice( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, 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 8d2317218c..9e44c0d449 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 @@ -1,10 +1,11 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling -import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow -import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.optionallyWrapWithLaunch +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.asBaseSentMessageUpdate import dev.inmo.tgbotapi.extensions.utils.asChatEventMessage import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat @@ -16,7 +17,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage internal suspend inline fun BehaviourContext.onEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> ) = flowsUpdatesFilter.expectFlow(bot) { it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.let { message -> @@ -27,138 +28,138 @@ internal suspend inline fun BehaviourContext.onEvent( null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions( +}.subscribeSafelyWithoutExceptionsAsync( scope, - optionallyWrapWithLaunch(performInParallel) { triggerMessage -> - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } - } else null, - stopOnCompletion = false - ) { - scenarioReceiver(triggerMessage) - } + markerFactory::invoke +) { triggerMessage -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } + } else null, + stopOnCompletion = false + ) { + scenarioReceiver(triggerMessage) } -) +} suspend fun BehaviourContext.onChannelEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onChatEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatStartedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatEndedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatParticipantsInvitedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMessageAutoDeleteTimerChangedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onCommonEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onGroupEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onSupergroupEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onChannelChatCreated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onDeleteChatPhoto( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onGroupChatCreated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onLeftChatMember( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onNewChatMembers( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onNewChatPhoto( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onNewChatTitle( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onPinnedMessage( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onProximityAlertTriggered( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onSupergroupChatCreated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt index 2cb5ec3ca9..79db28675a 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt @@ -1,9 +1,10 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling -import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow -import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.optionallyWrapWithLaunch +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserInlineQueryMarkerFactory +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.asInlineQueryUpdate import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.types.InlineQueries.query.* @@ -11,7 +12,7 @@ import dev.inmo.tgbotapi.types.InlineQueries.query.* internal suspend inline fun BehaviourContext.onInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (T) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver ) = flowsUpdatesFilter.expectFlow(bot) { it.asInlineQueryUpdate() ?.data ?.let { query -> @@ -21,42 +22,42 @@ internal suspend inline fun BehaviourContext.onInlineQ null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions( +}.subscribeSafelyWithoutExceptionsAsync( scope, - optionallyWrapWithLaunch(performInParallel) { triggerQuery -> - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == triggerQuery.from.id.chatId } - } else { - null - }, - stopOnCompletion = false - ) { - scenarioReceiver(triggerQuery) - } + markerFactory::invoke +) { triggerQuery -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerQuery.from.id.chatId } + } else { + null + }, + stopOnCompletion = false + ) { + scenarioReceiver(triggerQuery) } -) +} suspend fun BehaviourContext.onAnyInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (InlineQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onBaseInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (BaseInlineQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onLocationInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (LocationInlineQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt index b52da85431..dfc1e53bac 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt @@ -2,10 +2,11 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling -import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow -import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.optionallyWrapWithLaunch +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMediaGroupMarkerFactory +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.asSentMediaGroupUpdate import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat @@ -19,7 +20,7 @@ import dev.inmo.tgbotapi.utils.PreviewFeature internal suspend inline fun BehaviourContext.buildMediaGroupTrigger( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (List>) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = flowsUpdatesFilter.expectFlow(bot) { update -> update.asSentMediaGroupUpdate() ?.data ?.let { mediaGroup -> @@ -29,61 +30,61 @@ internal suspend inline fun BehaviourContext.bui null } } ?: emptyList() -}.subscribeSafelyWithoutExceptions( +}.subscribeSafelyWithoutExceptionsAsync( scope, - optionallyWrapWithLaunch(performInParallel) { mediaGroup -> - val mediaGroupChat = mediaGroup.chat!! - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == mediaGroupChat.id.chatId } - } else null, - stopOnCompletion = false - ) { - scenarioReceiver(mediaGroup) - } + markerFactory::invoke +) { mediaGroup -> + val mediaGroupChat = mediaGroup.chat!! + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == mediaGroupChat.id.chatId } + } else null, + stopOnCompletion = false + ) { + scenarioReceiver(mediaGroup) } -) +} suspend fun BehaviourContext.onMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onPlaylist( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onDocumentsGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVisualGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVisualMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = onVisualGallery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onVisualGallery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onPhotoGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVideoGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt index 3aaf4f7f0a..30e35a4196 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt @@ -1,9 +1,10 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling -import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow -import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.optionallyWrapWithLaunch +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate import dev.inmo.tgbotapi.extensions.utils.asPassportMessage import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat @@ -13,7 +14,7 @@ import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportEle internal suspend inline fun BehaviourContext.onPassportMessageWith( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (PassportMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByChatMessageMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver ) = flowsUpdatesFilter.expectFlow(bot) { it.asMessageUpdate() ?.data ?.asPassportMessage() ?.let { message -> @@ -23,29 +24,29 @@ internal suspend inline fun BehaviourCont null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions( +}.subscribeSafelyWithoutExceptionsAsync( scope, - optionallyWrapWithLaunch(performInParallel) { triggerMessage -> - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } - } else null, - stopOnCompletion = false - ) { - scenarioReceiver(triggerMessage) - } + markerFactory::invoke +) { triggerMessage -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } + } else null, + stopOnCompletion = false + ) { + scenarioReceiver(triggerMessage) } -) +} suspend fun BehaviourContext.onPassportMessage( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (PassportMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onPassportMessageWith( includeFilterByChatInBehaviourSubContext, additionalFilter, - performInParallel, + markerFactory, scenarioReceiver ) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/CallbackQueryMarkerFactories.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/CallbackQueryMarkerFactories.kt new file mode 100644 index 0000000000..64041bb198 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/CallbackQueryMarkerFactories.kt @@ -0,0 +1,17 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories + +import dev.inmo.tgbotapi.types.CallbackQuery.CallbackQuery + +object ByUserCallbackQueryMarkerFactory : MarkerFactory { + override suspend fun invoke(data: CallbackQuery) = data.user +} + +object ByIdCallbackQueryMarkerFactory : MarkerFactory { + override suspend fun invoke(data: CallbackQuery) = data.id +} + +object ByChatInstanceCallbackQueryMarkerFactory : MarkerFactory { + override suspend fun invoke(data: CallbackQuery) = data.chatInstance +} + + diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/ChatMemberUpdatedMarkerFactories.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/ChatMemberUpdatedMarkerFactories.kt new file mode 100644 index 0000000000..c861c5cf17 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/ChatMemberUpdatedMarkerFactories.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories + +import dev.inmo.tgbotapi.types.ChatMemberUpdated + +object ByChatChatMemberUpdatedMarkerFactory : MarkerFactory { + override suspend fun invoke(data: ChatMemberUpdated) = data.chat +} diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/InlineQueryMarkerFactories.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/InlineQueryMarkerFactories.kt new file mode 100644 index 0000000000..6c99d26029 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/InlineQueryMarkerFactories.kt @@ -0,0 +1,11 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories + +import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery + +object ByUserInlineQueryMarkerFactory : MarkerFactory { + override suspend fun invoke(data: InlineQuery) = data.from +} + +object ByIdInlineQueryMarkerFactory : MarkerFactory { + override suspend fun invoke(data: InlineQuery) = data.id +} diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MarkerFactory.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MarkerFactory.kt new file mode 100644 index 0000000000..2392d89d15 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MarkerFactory.kt @@ -0,0 +1,5 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories + +fun interface MarkerFactory { + suspend operator fun invoke(data: T): M +} diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MediaGroupMarkerFactories.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MediaGroupMarkerFactories.kt new file mode 100644 index 0000000000..233d3f3a3b --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MediaGroupMarkerFactories.kt @@ -0,0 +1,8 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories + +import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat +import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage + +object ByChatMediaGroupMarkerFactory : MarkerFactory>, Any> { + override suspend fun invoke(data: List>) = data.chat ?: error("Data must not be empty") +} diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MessageMarkerFactories.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MessageMarkerFactories.kt new file mode 100644 index 0000000000..1b98924dc9 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MessageMarkerFactories.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories + +import dev.inmo.tgbotapi.types.message.abstracts.Message + +object ByChatMessageMarkerFactory : MarkerFactory { + override suspend fun invoke(data: Message) = data.chat +}