From 0cce72de8d1850ece870c521b8db7f08ddc46c0b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 3 Oct 2021 20:37:14 +0600 Subject: [PATCH] cover all updates in behaviour builder --- CHANGELOG.md | 5 + .../expectations/WaitChosenInlineResult.kt | 82 ++++++++++++++++ .../expectations/WaitEditedContent.kt | 3 + .../expectations/WaitPollAnswers.kt | 68 ++++++++++++++ .../expectations/WaitPollUpdates.kt | 90 ++++++++++++++++++ .../expectations/WaitPreCheckoutQuery.kt | 51 ++++++++++ .../expectations/WaitShippingQuery.kt | 49 ++++++++++ .../filters/MessageFilterByChat.kt | 14 +++ .../CallbackQueryTriggers.kt | 8 +- .../ChosenInlineResultTriggers.kt | 93 +++++++++++++++++++ .../triggers_handling/PollAnswersTriggers.kt | 44 +++++++++ .../triggers_handling/PollUpdatesTriggers.kt | 91 ++++++++++++++++++ .../PreCheckoutQueryTriggers.kt | 36 +++++++ .../ShippingQueryTriggers.kt | 35 +++++++ .../ChosenInlineResultsMarkerFactories.kt | 8 ++ .../marker_factories/PollMarkerFactories.kt | 12 +++ ...erFactories.kt => QueryMarkerFactories.kt} | 10 ++ 17 files changed, 695 insertions(+), 4 deletions(-) create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChosenInlineResult.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPollAnswers.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPollUpdates.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPreCheckoutQuery.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitShippingQuery.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChosenInlineResultTriggers.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PollAnswersTriggers.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PollUpdatesTriggers.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PreCheckoutQueryTriggers.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ShippingQueryTriggers.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/ChosenInlineResultsMarkerFactories.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/PollMarkerFactories.kt rename tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/{CallbackQueryMarkerFactories.kt => QueryMarkerFactories.kt} (58%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 848faa2b00..9f81ed47f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,11 @@ * Two new dsl: * `inlineKeyboard` for creating `InlineKeyboardMarkup` * `replyKeyboard` for creating `ReplyKeyboardMarkup` +* `Behaviour Builder`: + * New expecters and waiters: + * `waitShippingQueries`/`onShippingQuery` + * `waitPreCheckoutQueries`/`onPreCheckoutQuery` + * `waitChosenInlineResult`/`onChosenInlineResult` ## 0.35.9 diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChosenInlineResult.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChosenInlineResult.kt new file mode 100644 index 0000000000..3b277f24f6 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChosenInlineResult.kt @@ -0,0 +1,82 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations + +import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter +import dev.inmo.tgbotapi.extensions.utils.* +import dev.inmo.tgbotapi.requests.abstracts.Request +import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.* +import dev.inmo.tgbotapi.types.polls.* +import kotlinx.coroutines.flow.toList + +typealias ChosenInlineResultMapper = suspend T.() -> T? + +private suspend fun BehaviourContext.waitChosenInlineResultsUpdates( + count: Int = 1, + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + filter: SimpleFilter? = null, + mapper: suspend ChosenInlineResult.() -> O? +): List = expectFlow( + initRequest, + count, + errorFactory +) { + val data = it.asChosenInlineResultUpdate() ?.data + if (data != null && (filter == null || filter(data))) { + data.mapper().let(::listOfNotNull) + } else { + emptyList() + } +}.toList().toList() + + +private suspend inline fun BehaviourContext.waitChosenInlineResults( + count: Int = 1, + initRequest: Request<*>? = null, + noinline errorFactory: NullableRequestBuilder<*> = { null }, + noinline filter: SimpleFilter? = null, + noinline mapper: ChosenInlineResultMapper? = null +) : List = this@waitChosenInlineResults.waitChosenInlineResultsUpdates( + count, + initRequest, + errorFactory, + filter ?.let { + { + (it as? T) ?.let { filter(it) } == true + } + } +) { + if (this is T) { + if (mapper == null) { + this + } else { + mapper(this) + } + } else { + null + } +} + +suspend fun BehaviourContext.waitChosenInlineResult( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + count: Int = 1, + filter: SimpleFilter? = null, + mapper: ChosenInlineResultMapper? = null +) = waitChosenInlineResults(count, initRequest, errorFactory, filter, mapper) + +suspend fun BehaviourContext.waitLocationChosenInlineResult( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + count: Int = 1, + filter: SimpleFilter? = null, + mapper: PollMapper? = null +) = waitChosenInlineResults(count, initRequest, errorFactory, filter, mapper) + +suspend fun BehaviourContext.waitBaseChosenInlineResult( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + count: Int = 1, + filter: SimpleFilter? = null, + mapper: PollMapper? = null +) = waitChosenInlineResults(count, initRequest, errorFactory, filter, mapper) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEditedContent.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEditedContent.kt index e00e832c0d..fa5e162a68 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEditedContent.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEditedContent.kt @@ -119,6 +119,9 @@ suspend fun BehaviourContext.waitEditedStaticLocation( filter: SimpleFilter>? = null, mapper: CommonMessageToContentMapper? = null ) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper) +/** + * This + */ suspend fun BehaviourContext.waitEditedPoll( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPollAnswers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPollAnswers.kt new file mode 100644 index 0000000000..718bdd4c89 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPollAnswers.kt @@ -0,0 +1,68 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations + +import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter +import dev.inmo.tgbotapi.extensions.utils.* +import dev.inmo.tgbotapi.requests.abstracts.Request +import dev.inmo.tgbotapi.types.polls.* +import kotlinx.coroutines.flow.toList + +typealias PollAnswerMapper = suspend PollAnswer.() -> PollAnswer? + +private suspend fun BehaviourContext.waitPollsAnswers( + count: Int = 1, + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + filter: SimpleFilter? = null, + mapper: suspend PollAnswer.() -> O? +): List = expectFlow( + initRequest, + count, + errorFactory +) { + val data = it.asPollAnswerUpdate() ?.data + if (data != null && (filter == null || filter(data))) { + data.mapper().let(::listOfNotNull) + } else { + emptyList() + } +}.toList().toList() + + +private suspend inline fun BehaviourContext.waitPollAnswers( + count: Int = 1, + initRequest: Request<*>? = null, + noinline errorFactory: NullableRequestBuilder<*> = { null }, + noinline filter: SimpleFilter? = null, + noinline mapper: PollAnswerMapper? = null +) : List = this@waitPollAnswers.waitPollsAnswers( + count, + initRequest, + errorFactory, + filter ?.let { + { + (it as? PollAnswer) ?.let { filter(it) } == true + } + } +) { + if (this is PollAnswer) { + if (mapper == null) { + this + } else { + mapper(this) + } + } else { + null + } +} + +/** + * This wait will be triggered only for stopped polls and polls, which are sent by the bot + */ +suspend fun BehaviourContext.waitPollAnswers( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + count: Int = 1, + filter: SimpleFilter? = null, + mapper: PollAnswerMapper? = null +) = waitPollAnswers(count, initRequest, errorFactory, filter, mapper) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPollUpdates.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPollUpdates.kt new file mode 100644 index 0000000000..fd1632107c --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPollUpdates.kt @@ -0,0 +1,90 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations + +import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter +import dev.inmo.tgbotapi.extensions.utils.* +import dev.inmo.tgbotapi.requests.abstracts.Request +import dev.inmo.tgbotapi.types.polls.* +import kotlinx.coroutines.flow.toList + +typealias PollMapper = suspend T.() -> T? + +private suspend fun BehaviourContext.waitPollsUpdates( + count: Int = 1, + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + filter: SimpleFilter? = null, + mapper: suspend Poll.() -> O? +): List = expectFlow( + initRequest, + count, + errorFactory +) { + val data = it.asPollUpdate() ?.data + if (data != null && (filter == null || filter(data))) { + data.mapper().let(::listOfNotNull) + } else { + emptyList() + } +}.toList().toList() + + +private suspend inline fun BehaviourContext.waitPolls( + count: Int = 1, + initRequest: Request<*>? = null, + noinline errorFactory: NullableRequestBuilder<*> = { null }, + noinline filter: SimpleFilter? = null, + noinline mapper: PollMapper? = null +) : List = this@waitPolls.waitPollsUpdates( + count, + initRequest, + errorFactory, + filter ?.let { + { + (it as? T) ?.let { filter(it) } == true + } + } +) { + if (this is T) { + if (mapper == null) { + this + } else { + mapper(this) + } + } else { + null + } +} + +/** + * This wait will be triggered only for stopped polls and polls, which are sent by the bot + */ +suspend fun BehaviourContext.waitPollsUpdates( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + count: Int = 1, + filter: SimpleFilter? = null, + mapper: PollMapper? = null +) = waitPolls(count, initRequest, errorFactory, filter, mapper) + +/** + * This wait will be triggered only for stopped polls and polls, which are sent by the bot + */ +suspend fun BehaviourContext.waitQuizPollsUpdates( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + count: Int = 1, + filter: SimpleFilter? = null, + mapper: PollMapper? = null +) = waitPolls(count, initRequest, errorFactory, filter, mapper) + +/** + * This wait will be triggered only for stopped polls and polls, which are sent by the bot + */ +suspend fun BehaviourContext.waitRegularPollsUpdates( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + count: Int = 1, + filter: SimpleFilter? = null, + mapper: PollMapper? = null +) = waitPolls(count, initRequest, errorFactory, filter, mapper) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPreCheckoutQuery.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPreCheckoutQuery.kt new file mode 100644 index 0000000000..d2c8cf9612 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPreCheckoutQuery.kt @@ -0,0 +1,51 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations + +import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter +import dev.inmo.tgbotapi.extensions.utils.asPreCheckoutQueryUpdate +import dev.inmo.tgbotapi.extensions.utils.asShippingQueryUpdate +import dev.inmo.tgbotapi.requests.abstracts.Request +import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery +import dev.inmo.tgbotapi.types.payments.ShippingQuery +import kotlinx.coroutines.flow.toList + +typealias PreCheckoutQueryMapper = suspend PreCheckoutQuery.() -> PreCheckoutQuery? + +private suspend fun BehaviourContext.waitPreCheckoutQueries( + count: Int = 1, + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + filter: SimpleFilter? = null, + mapper: suspend PreCheckoutQuery.() -> O? +): List = expectFlow( + initRequest, + count, + errorFactory +) { + val data = it.asPreCheckoutQueryUpdate() ?.data + if (data != null && (filter == null || filter(data))) { + data.mapper().let(::listOfNotNull) + } else { + emptyList() + } +}.toList().toList() + + +suspend fun BehaviourContext.waitPreCheckoutQueries( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + count: Int = 1, + filter: SimpleFilter? = null, + mapper: PreCheckoutQueryMapper? = null +) : List = waitPreCheckoutQueries( + count, + initRequest, + errorFactory, + filter +) { + if (mapper == null) { + this + } else { + mapper(this) + } +} diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitShippingQuery.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitShippingQuery.kt new file mode 100644 index 0000000000..3ec4382a00 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitShippingQuery.kt @@ -0,0 +1,49 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations + +import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter +import dev.inmo.tgbotapi.extensions.utils.asShippingQueryUpdate +import dev.inmo.tgbotapi.requests.abstracts.Request +import dev.inmo.tgbotapi.types.payments.ShippingQuery +import kotlinx.coroutines.flow.toList + +typealias ShippingQueryMapper = suspend ShippingQuery.() -> ShippingQuery? + +private suspend fun BehaviourContext.waitShippingQueries( + count: Int = 1, + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + filter: SimpleFilter? = null, + mapper: suspend ShippingQuery.() -> O? +): List = expectFlow( + initRequest, + count, + errorFactory +) { + val data = it.asShippingQueryUpdate() ?.data + if (data != null && (filter == null || filter(data))) { + data.mapper().let(::listOfNotNull) + } else { + emptyList() + } +}.toList().toList() + + +suspend fun BehaviourContext.waitShippingQueries( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + count: Int = 1, + filter: SimpleFilter? = null, + mapper: ShippingQueryMapper? = null +) : List = waitShippingQueries( + count, + initRequest, + errorFactory, + filter +) { + if (mapper == null) { + this + } else { + mapper(this) + } +} diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterByChat.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterByChat.kt index 67c2a187d3..370db3c006 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterByChat.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterByChat.kt @@ -6,6 +6,8 @@ import dev.inmo.tgbotapi.types.CallbackQuery.CallbackQuery import dev.inmo.tgbotapi.types.ChatMemberUpdated import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery +import dev.inmo.tgbotapi.types.payments.ShippingQuery import dev.inmo.tgbotapi.types.update.abstracts.Update /** @@ -28,6 +30,18 @@ val MessagesFilterByChat: BehaviourContextAndTwoTypesReceiver = { query, update -> update.sourceChat() ?.id == query.user.id } +/** + * Allow only updates from the same user as base [ShippingQuery.user] + */ +val ShippingQueryFilterByUser: BehaviourContextAndTwoTypesReceiver = { query, update -> + update.sourceChat() ?.id == query.user.id +} +/** + * Allow only updates from the same user as base [ShippingQuery.user] + */ +val PreCheckoutQueryFilterByUser: BehaviourContextAndTwoTypesReceiver = { query, update -> + update.sourceChat() ?.id == query.user.id +} /** * Allow only updates from the same user as base [InlineQuery.from] */ 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 dd972014fd..d35f1e27da 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 @@ -37,7 +37,7 @@ suspend fun BehaviourContext.onDataCallbackQuery( subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery( +) = onPollAnswered( initialFilter, subcontextUpdatesFilter, markerFactory, @@ -61,7 +61,7 @@ suspend fun BehaviourContext.onGameShortNameCallbackQuery( subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery( +) = onPollAnswered( initialFilter, subcontextUpdatesFilter, markerFactory, @@ -85,7 +85,7 @@ suspend fun BehaviourContext.onInlineMessageIdCallbackQuery( subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery( +) = onPollAnswered( initialFilter, subcontextUpdatesFilter, markerFactory, @@ -157,7 +157,7 @@ suspend fun BehaviourContext.onMessageCallbackQuery( subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery( +) = onPollAnswered( initialFilter, subcontextUpdatesFilter, markerFactory, diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChosenInlineResultTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChosenInlineResultTriggers.kt new file mode 100644 index 0000000000..5102f9c356 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChosenInlineResultTriggers.kt @@ -0,0 +1,93 @@ +@file:Suppress("unused") + +package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling + +import dev.inmo.tgbotapi.extensions.behaviour_builder.* +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.* +import dev.inmo.tgbotapi.extensions.utils.asChosenInlineResultUpdate +import dev.inmo.tgbotapi.extensions.utils.asPollUpdate +import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.* +import dev.inmo.tgbotapi.types.polls.* +import dev.inmo.tgbotapi.types.update.abstracts.Update + +internal suspend inline fun BehaviourContext.onChosenInlineResultBase( + noinline initialFilter: SimpleFilter? = null, + noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + markerFactory: MarkerFactory = ByUserIdChosenInlineResultMarkerFactory, + noinline scenarioReceiver: BehaviourContextAndTypeReceiver +) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { + (it.asChosenInlineResultUpdate() ?.data as? T) ?.let(::listOfNotNull) +} + +/** + * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call + * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, + * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] + * to combinate several filters + * @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously + * in one "stream". Output of [markerFactory] will be used as a key for "stream" + * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that + * data + */ +suspend fun BehaviourContext.onChosenInlineResult( + initialFilter: SimpleFilter? = null, + subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + markerFactory: MarkerFactory = ByUserIdChosenInlineResultMarkerFactory, + scenarioReceiver: BehaviourContextAndTypeReceiver +) = onChosenInlineResultBase( + initialFilter, + subcontextUpdatesFilter, + markerFactory, + scenarioReceiver +) + +/** + * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call + * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, + * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] + * to combinate several filters + * @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously + * in one "stream". Output of [markerFactory] will be used as a key for "stream" + * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that + * data + */ +suspend fun BehaviourContext.onLocationChosenInlineResult( + initialFilter: SimpleFilter? = null, + subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + markerFactory: MarkerFactory = ByUserIdChosenInlineResultMarkerFactory, + scenarioReceiver: BehaviourContextAndTypeReceiver +) = onChosenInlineResultBase( + initialFilter, + subcontextUpdatesFilter, + markerFactory, + scenarioReceiver +) + +/** + * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call + * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, + * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] + * to combinate several filters + * @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously + * in one "stream". Output of [markerFactory] will be used as a key for "stream" + * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that + * data + */ +suspend fun BehaviourContext.onBaseChosenInlineResult( + initialFilter: SimpleFilter? = null, + subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + markerFactory: MarkerFactory = ByUserIdChosenInlineResultMarkerFactory, + scenarioReceiver: BehaviourContextAndTypeReceiver +) = onChosenInlineResultBase( + initialFilter, + subcontextUpdatesFilter, + markerFactory, + scenarioReceiver +) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PollAnswersTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PollAnswersTriggers.kt new file mode 100644 index 0000000000..c8bfa9d6b3 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PollAnswersTriggers.kt @@ -0,0 +1,44 @@ +@file:Suppress("unused") + +package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling + +import dev.inmo.tgbotapi.extensions.behaviour_builder.* +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.* +import dev.inmo.tgbotapi.extensions.utils.asPollAnswerUpdate +import dev.inmo.tgbotapi.extensions.utils.asPollUpdate +import dev.inmo.tgbotapi.types.polls.* +import dev.inmo.tgbotapi.types.update.abstracts.Update + +internal suspend inline fun BehaviourContext.onPollAnswered( + noinline initialFilter: SimpleFilter? = null, + noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + markerFactory: MarkerFactory = ByIdPollAnswerMarkerFactory, + noinline scenarioReceiver: BehaviourContextAndTypeReceiver +) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { + (it.asPollAnswerUpdate() ?.data) ?.let(::listOfNotNull) +} + +/** + * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call + * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, + * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] + * to combinate several filters + * @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously + * in one "stream". Output of [markerFactory] will be used as a key for "stream" + * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that + * data + */ +suspend fun BehaviourContext.onPollAnswer( + initialFilter: SimpleFilter? = null, + subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + markerFactory: MarkerFactory = ByIdPollAnswerMarkerFactory, + scenarioReceiver: BehaviourContextAndTypeReceiver +) = onPollAnswered( + initialFilter, + subcontextUpdatesFilter, + markerFactory, + scenarioReceiver +) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PollUpdatesTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PollUpdatesTriggers.kt new file mode 100644 index 0000000000..816848f547 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PollUpdatesTriggers.kt @@ -0,0 +1,91 @@ +@file:Suppress("unused") + +package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling + +import dev.inmo.tgbotapi.extensions.behaviour_builder.* +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.* +import dev.inmo.tgbotapi.extensions.utils.asPollUpdate +import dev.inmo.tgbotapi.types.polls.* +import dev.inmo.tgbotapi.types.update.abstracts.Update + +internal suspend inline fun BehaviourContext.onPollBase( + noinline initialFilter: SimpleFilter? = null, + noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + markerFactory: MarkerFactory = ByIdPollMarkerFactory, + noinline scenarioReceiver: BehaviourContextAndTypeReceiver +) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { + (it.asPollUpdate() ?.data as? T) ?.let(::listOfNotNull) +} + +/** + * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call + * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, + * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] + * to combinate several filters + * @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously + * in one "stream". Output of [markerFactory] will be used as a key for "stream" + * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that + * data + */ +suspend fun BehaviourContext.onPoll( + initialFilter: SimpleFilter? = null, + subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + markerFactory: MarkerFactory = ByIdPollMarkerFactory, + scenarioReceiver: BehaviourContextAndTypeReceiver +) = onPollBase( + initialFilter, + subcontextUpdatesFilter, + markerFactory, + scenarioReceiver +) + +/** + * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call + * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, + * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] + * to combinate several filters + * @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously + * in one "stream". Output of [markerFactory] will be used as a key for "stream" + * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that + * data + */ +suspend fun BehaviourContext.onRegularPoll( + initialFilter: SimpleFilter? = null, + subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + markerFactory: MarkerFactory = ByIdPollMarkerFactory, + scenarioReceiver: BehaviourContextAndTypeReceiver +) = onPollBase( + initialFilter, + subcontextUpdatesFilter, + markerFactory, + scenarioReceiver +) + +/** + * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call + * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, + * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] + * to combinate several filters + * @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously + * in one "stream". Output of [markerFactory] will be used as a key for "stream" + * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that + * data + */ +suspend fun BehaviourContext.onQuizPoll( + initialFilter: SimpleFilter? = null, + subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + markerFactory: MarkerFactory = ByIdPollMarkerFactory, + scenarioReceiver: BehaviourContextAndTypeReceiver +) = onPollBase( + initialFilter, + subcontextUpdatesFilter, + markerFactory, + scenarioReceiver +) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PreCheckoutQueryTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PreCheckoutQueryTriggers.kt new file mode 100644 index 0000000000..e0a6be1a2f --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PreCheckoutQueryTriggers.kt @@ -0,0 +1,36 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling + +import dev.inmo.tgbotapi.extensions.behaviour_builder.* +import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.* +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.* +import dev.inmo.tgbotapi.extensions.utils.asPreCheckoutQueryUpdate +import dev.inmo.tgbotapi.extensions.utils.asShippingQueryUpdate +import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery +import dev.inmo.tgbotapi.types.payments.ShippingQuery +import dev.inmo.tgbotapi.types.update.abstracts.Update + +/** + * Please, remember that you must answer to this type of queries using something like + * [dev.inmo.tgbotapi.extensions.api.answers.payments.answerPreCheckoutQueryOk] or + * [dev.inmo.tgbotapi.extensions.api.answers.payments.answerPreCheckoutQueryError] + * + * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call + * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, + * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] + * to combinate several filters + * @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously + * in one "stream". Output of [markerFactory] will be used as a key for "stream" + * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that + * data + */ +suspend fun BehaviourContext.onPreCheckoutQuery( + initialFilter: SimpleFilter? = null, + subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = PreCheckoutQueryFilterByUser, + markerFactory: MarkerFactory = ByUserPreCheckoutQueryMarkerFactory, + scenarioReceiver: BehaviourContextAndTypeReceiver +) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { + (it.asPreCheckoutQueryUpdate() ?.data) ?.let(::listOfNotNull) +} diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ShippingQueryTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ShippingQueryTriggers.kt new file mode 100644 index 0000000000..559be79250 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ShippingQueryTriggers.kt @@ -0,0 +1,35 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling + +import dev.inmo.tgbotapi.extensions.behaviour_builder.* +import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CallbackQueryFilterByUser +import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.ShippingQueryFilterByUser +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.* +import dev.inmo.tgbotapi.extensions.utils.asShippingQueryUpdate +import dev.inmo.tgbotapi.types.payments.ShippingQuery +import dev.inmo.tgbotapi.types.update.abstracts.Update + +/** + * Please, remember that you must answer to this type of queries using something like + * [dev.inmo.tgbotapi.extensions.api.answers.payments.answerShippingQueryOk] or + * [dev.inmo.tgbotapi.extensions.api.answers.payments.answerShippingQueryError] + * + * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call + * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, + * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] + * to combinate several filters + * @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously + * in one "stream". Output of [markerFactory] will be used as a key for "stream" + * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that + * data + */ +suspend fun BehaviourContext.onShippingQuery( + initialFilter: SimpleFilter? = null, + subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = ShippingQueryFilterByUser, + markerFactory: MarkerFactory = ByUserShippingQueryMarkerFactory, + scenarioReceiver: BehaviourContextAndTypeReceiver +) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { + (it.asShippingQueryUpdate() ?.data) ?.let(::listOfNotNull) +} diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/ChosenInlineResultsMarkerFactories.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/ChosenInlineResultsMarkerFactories.kt new file mode 100644 index 0000000000..f96c321ee7 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/ChosenInlineResultsMarkerFactories.kt @@ -0,0 +1,8 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories + +import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.ChosenInlineResult + + +object ByUserIdChosenInlineResultMarkerFactory : MarkerFactory { + override suspend fun invoke(data: ChosenInlineResult) = data.user.id +} diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/PollMarkerFactories.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/PollMarkerFactories.kt new file mode 100644 index 0000000000..d9ada9782d --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/PollMarkerFactories.kt @@ -0,0 +1,12 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories + +import dev.inmo.tgbotapi.types.polls.Poll +import dev.inmo.tgbotapi.types.polls.PollAnswer + +object ByIdPollMarkerFactory : MarkerFactory { + override suspend fun invoke(data: Poll) = data.id +} + +object ByIdPollAnswerMarkerFactory : MarkerFactory { + override suspend fun invoke(data: PollAnswer) = data.pollId +} 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/QueryMarkerFactories.kt similarity index 58% rename from tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/CallbackQueryMarkerFactories.kt rename to tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/QueryMarkerFactories.kt index 64041bb198..ccb7cd7734 100644 --- 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/QueryMarkerFactories.kt @@ -1,11 +1,21 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories import dev.inmo.tgbotapi.types.CallbackQuery.CallbackQuery +import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery +import dev.inmo.tgbotapi.types.payments.ShippingQuery object ByUserCallbackQueryMarkerFactory : MarkerFactory { override suspend fun invoke(data: CallbackQuery) = data.user } +object ByUserShippingQueryMarkerFactory : MarkerFactory { + override suspend fun invoke(data: ShippingQuery) = data.user +} + +object ByUserPreCheckoutQueryMarkerFactory : MarkerFactory { + override suspend fun invoke(data: PreCheckoutQuery) = data.user +} + object ByIdCallbackQueryMarkerFactory : MarkerFactory { override suspend fun invoke(data: CallbackQuery) = data.id }