diff --git a/CHANGELOG.md b/CHANGELOG.md index 833bb37b17..aef340cdc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * `Version`: * `Serialization`: `1.2.2` -> `1.3.0` * `MicroUtils`: `0.5.28` -> `0.7.0` + * `Klock`: `2.4.3` -> `2.4.5` * `Core`: * `PayInlineKeyboardButton#pay` now is deprecated * `RowBuilder` and `MatrixBuilder` now are open and available for extending @@ -24,6 +25,8 @@ * `waitPreCheckoutQueries`/`onPreCheckoutQuery` * `waitChosenInlineResult`/`onChosenInlineResult` * `waitPollUpdates`/`onPollUpdates` +* `Behaviour Builder FSM extension`: + * Has been created :) ## 0.35.9 diff --git a/TelegramBotAPI.drawio b/TelegramBotAPI.drawio index 0bc0fa2013..f0839eea47 100644 --- a/TelegramBotAPI.drawio +++ b/TelegramBotAPI.drawio @@ -1 +1 @@ - \ No newline at end of file +7Vptc+I2EP41TD/BgI0J+Zi33t302t5cOr3mU0fYwtZFtnyyHKC/vruy/G4TAglkchlmgrUSq9Vq93m0cgb2Vbj+IEkc/C48ygfW2FsP7OuBZU0mYwu+ULLJJPPJWSbwJfPMoFJwy/6jRjg20pR5NKkNVEJwxeK60BVRRF1VkxEpxao+bCl4fdaY+LQluHUJb0u/MU8FZhXOuJR/pMwPVLFg0xOSfLARJAHxxKqi1b4Z2FdSCJU9hesrytF5uV+y3/3a01sYJmmkdvmBMzN2qE2+OOrBWk1TSBUIX0SE35TSy1L6WYgYhk1A+J0qtTFbRVIlQBSokJteMEdu/oHGOG/cYWPk5M3rdbXzemNa7fWYJSYila6xeGqiRxHpUzPMcTIZrqbpXohLKkIK88AASTlR7KG+s8QEiF+MK30ID8aN3S7NrXkgPDVaB9aMK3QIqJ/5Sq8rkyQxiWrun/1Ice8vFV2rIeHMjwb2BYzgdKnK3p3VcBbRYWBiEfVY89E8XvdrWnSqWYpIDRO9uVrJtEuF8hdCkZiNwHQaJUxEyQiauWbw26I5G8gy03cVtz0YP7NLbwrjMfCk+I4Aghghdf7eUx0zP1KaKBwRCokSLsQ9fjHdz9AAFeDjX5RTX5IQHi8FKrr48gkDLPIQxzDurLGIY0ipNGJqo5EM/qSJ1qN+wTkoSRiVjzun4opGTuPS6wlp/HDtQmKBbvvygUrFAOIuTEfIPE9newFRmI8+J0linsEKl0U+tDCLVwFT9BZEOOUKcB/DhnF+JTi4Dq2wLYIfE04V+c0MP9uyHY2j6615bKjEyqF2VQKznaNtUAXlXHhIrueIfzz4LBHzrgaYh8DnvA2fOYgdHz6dyVt16fnJXDp9CyTf4VLHOhnJz3tJPt6NiCdTwA6nn4jreP7k88NOjF0h/QaFu5rW9iHuQxi6YfTEQqOzCBnrvlXFgZGQIeHtRX0VmmdL6l4xIAJNvCP4+oQilmgFSoeGK8KQRh71muSb1KneYzBW8U1B3wvIBuTl6q+I0icLkuD34yeix5m8x4c/O92bXmtqGNjQ/7TN/sWJ4PnZ3z46VVkvwFXnrwlYx1/FN8df3Q3//vP+Plj8MSS/XQ1n+xyzpEh1Umeu2Mfta6YKNoPnCplBq3Q5NjZV/+99qmi4e7+tcw7cKf3TCynJpjIgFixCECw0f0FBmYe2Xc9DazZu7HqmsYyBwrTd+Pb8vaguKCRVjCfHKqt76mFDqsYUKHaBGvABeMENdL/eP1Mw5xUscOhySXVMY9lLJYSk1mz8JN9prpPm7FkjvY5a5XZisnN+UkwucPiu0tONyftha06BVWztdsT8pNRovR5qPNuZG/c5xjzHBh5MjjsfDa2tfPVy3HRg3VdhmQUNyAMDh/67SBn3aheQr7EenCIm9t7mDtqXuXpZCPXwqEvBYsW4cYygSTF1GRaZ4+vbz+8XsPtQVdGuUNX07MVKMqc3797CvcwzpuDeEPSRyuwdh8vT7NKE6C0gD4RxsuDVtx6XQmXvOzhbSCIZvrS9OOCeI5OlvCnh7IAF9V16odKXmKb3MugIEzZLhyNMuY1HTjH9aJmEW00AYTvCdgrM91u6bk6YnNc5YTbvuKabd3HC7KXKl9k+r5lOUr4Ux+biKvApb1WeemreUuKc6Ci91aK3dL5uANP7Gfstn7Fb4NmRmf1n7MZbD8dq46kzeaYzNjTL/0fLrm7L/+qzb/4H \ No newline at end of file diff --git a/build.gradle b/build.gradle index 1e47f88a68..42562e8321 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,6 @@ buildscript { repositories { mavenLocal() - jcenter() mavenCentral() maven { url "https://plugins.gradle.org/m2/" } } diff --git a/docs/build.gradle b/docs/build.gradle index babb90dfde..0f06812393 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -1,7 +1,6 @@ buildscript { repositories { mavenLocal() - jcenter() mavenCentral() } @@ -20,7 +19,6 @@ plugins { repositories { mavenLocal() - jcenter() mavenCentral() } diff --git a/gradle.properties b/gradle.properties index ea3a8362c9..a9ad63c307 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,11 +8,11 @@ kotlin.incremental.js=true kotlin_version=1.5.31 kotlin_coroutines_version=1.5.2 kotlin_serialisation_runtime_version=1.3.0 -klock_version=2.4.3 +klock_version=2.4.5 uuid_version=0.3.1 ktor_version=1.6.4 -micro_utils_version=0.7.0 +micro_utils_version=0.7.1 javax_activation_version=1.1.1 diff --git a/resources/TelegramBotAPI-libraries-hierarchy.svg b/resources/TelegramBotAPI-libraries-hierarchy.svg index 774ed45810..6b39a9717b 100644 --- a/resources/TelegramBotAPI-libraries-hierarchy.svg +++ b/resources/TelegramBotAPI-libraries-hierarchy.svg @@ -1 +1,3 @@ -

tgbotapi.extensions.api

Extensions project for make requests more look like in the Telegram Bot API and give opportunity to use it's easier

tgbotapi.extensions.api...

tgbotapi.core

Root project with API. It is not recommended to use its requests directly and better to use at least tgbotapi.extensions.api

tgbotapi.core...

tgbotapi.extensions.utils

Extensions project with utils things which will make easier different operations

tgbotapi.extensions.utils...

tgbotapi.extensions.behaviour_builder

Extension project for building bot behaviour via special DSL

tgbotapi.extensions.behaviour_builder...

tgbotapi

Here included all available TelegramBotAPI libraries:

  • tgbotapi.core
  • tgbotapi.extensions.api
  • tgbotapi.extensions.utils
  • tgbotapi.extensions.behaviour_builder

tgbotapi...
Viewer does not support full SVG 1.1
+ + +

tgbotapi.extensions.api

Extensions project for make requests more look like in the Telegram Bot API and give opportunity to use it's easier

tgbotapi.extensions.api...

tgbotapi.core

Root project with API. It is not recommended to use its requests directly and better to use at least tgbotapi.extensions.api

tgbotapi.core...

tgbotapi.extensions.utils

Extensions project with utils things which will make easier different operations

tgbotapi.extensions.utils...

tgbotapi.extensions.behaviour_builder

Extension project for building bot behaviour via special DSL

tgbotapi.extensions.behaviour_builder...

tgbotapi

Here included all available TelegramBotAPI libraries:

  • tgbotapi.core
  • tgbotapi.extensions.api
  • tgbotapi.extensions.utils
  • tgbotapi.extensions.behaviour_builder
  • tgbotapi.extensions.behaviour_builder.fsm

tgbotapi...

tgbotapi.extensions.behaviour_builder.fsm

Extension project for building bot behaviour via special DSL

tgbotapi.extensions.behaviour_builder.fsm...
Viewer does not support full SVG 1.1
\ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 33e593255e..70c3b4c77a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,7 +8,6 @@ pluginManagement { } repositories { gradlePluginPortal() - jcenter() } } @@ -16,5 +15,6 @@ include ":tgbotapi.core" include ":tgbotapi.extensions.api" include ":tgbotapi.extensions.utils" include ":tgbotapi.extensions.behaviour_builder" +include ":tgbotapi.extensions.behaviour_builder.fsm" include ":tgbotapi" include ":docs" diff --git a/tgbotapi.core/README.md b/tgbotapi.core/README.md index 4f888a0d23..428c1a191a 100644 --- a/tgbotapi.core/README.md +++ b/tgbotapi.core/README.md @@ -57,7 +57,7 @@ Dependency config presented here: To use last versions you will need to add one line in repositories block of your `build.gradle`: -`jcenter()` or `mavenCentral()` +`mavenCentral()` And add next line to your dependencies block: diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt index afc186883d..b37ceacb1c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt @@ -1,11 +1,12 @@ package dev.inmo.tgbotapi.updateshandlers +import dev.inmo.micro_utils.coroutines.plus import dev.inmo.tgbotapi.types.ALL_UPDATES_LIST import dev.inmo.tgbotapi.types.update.* import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.* import dev.inmo.tgbotapi.types.update.abstracts.UnknownUpdate import dev.inmo.tgbotapi.types.update.abstracts.Update -import kotlinx.coroutines.channels.BufferOverflow +import kotlinx.coroutines.channels.* import kotlinx.coroutines.flow.* interface FlowsUpdatesFilter : UpdatesFilter { @@ -34,22 +35,61 @@ interface FlowsUpdatesFilter : UpdatesFilter { val unknownUpdatesFlow: Flow } +abstract class AbstractFlowsUpdatesFilter : FlowsUpdatesFilter { + override val allUpdatesWithoutMediaGroupsGroupingFlow: Flow + get() = allUpdatesFlow.flatMapConcat { + when (it) { + is SentMediaGroupUpdate -> it.origins.asFlow() + is EditMediaGroupUpdate -> flowOf(it.origin) + else -> flowOf(it) + } + } + + override val messagesFlow: Flow by lazy { allUpdatesFlow.filterIsInstance() } + override val messageMediaGroupsFlow: Flow by lazy { allUpdatesFlow.filterIsInstance() } + override val editedMessagesFlow: Flow by lazy { allUpdatesFlow.filterIsInstance() } + override val editedMessageMediaGroupsFlow: Flow by lazy { allUpdatesFlow.filterIsInstance() } + override val channelPostsFlow: Flow by lazy { allUpdatesFlow.filterIsInstance() } + override val channelPostMediaGroupsFlow: Flow by lazy { allUpdatesFlow.filterIsInstance() } + override val editedChannelPostsFlow: Flow by lazy { allUpdatesFlow.filterIsInstance() } + override val editedChannelPostMediaGroupsFlow: Flow by lazy { allUpdatesFlow.filterIsInstance() } + override val chosenInlineResultsFlow: Flow by lazy { allUpdatesFlow.filterIsInstance() } + override val inlineQueriesFlow: Flow by lazy { allUpdatesFlow.filterIsInstance() } + override val callbackQueriesFlow: Flow by lazy { allUpdatesFlow.filterIsInstance() } + override val shippingQueriesFlow: Flow by lazy { allUpdatesFlow.filterIsInstance() } + override val preCheckoutQueriesFlow: Flow by lazy { allUpdatesFlow.filterIsInstance() } + override val pollsFlow: Flow by lazy { allUpdatesFlow.filterIsInstance() } + override val pollAnswersFlow: Flow by lazy { allUpdatesFlow.filterIsInstance() } + override val chatMemberUpdatesFlow: Flow by lazy { allUpdatesFlow.filterIsInstance() } + override val myChatMemberUpdatesFlow: Flow by lazy { allUpdatesFlow.filterIsInstance() } + override val unknownUpdatesFlow: Flow by lazy { allUpdatesFlow.filterIsInstance() } +} + /** * Creates [DefaultFlowsUpdatesFilter] */ @Suppress("FunctionName") fun FlowsUpdatesFilter( - broadcastChannelsSize: Int = 100 -) = DefaultFlowsUpdatesFilter(broadcastChannelsSize) + broadcastChannelsSize: Int = 100, + onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND, + upstreamUpdatesFlow: Flow? = null +) = DefaultFlowsUpdatesFilter(broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow) @Suppress("unused") class DefaultFlowsUpdatesFilter( broadcastChannelsSize: Int = 100, - onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND -): FlowsUpdatesFilter { - private val updatesSharedFlow = MutableSharedFlow(extraBufferCapacity = broadcastChannelsSize, onBufferOverflow = onBufferOverflow) + onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND, + upstreamUpdatesFlow: Flow? = null +): AbstractFlowsUpdatesFilter() { + private val additionalUpdatesSharedFlow = MutableSharedFlow(0, broadcastChannelsSize, onBufferOverflow) @Suppress("MemberVisibilityCanBePrivate") - override val allUpdatesFlow: Flow = updatesSharedFlow.asSharedFlow() + override val allUpdatesFlow: Flow = (additionalUpdatesSharedFlow.asSharedFlow()).let { + if (upstreamUpdatesFlow != null) { + (it + upstreamUpdatesFlow).distinctUntilChanged { old, new -> old.updateId == new.updateId } + } else { + it + } + } @Suppress("MemberVisibilityCanBePrivate") override val allUpdatesWithoutMediaGroupsGroupingFlow: Flow = allUpdatesFlow.flatMapConcat { when (it) { @@ -59,26 +99,5 @@ class DefaultFlowsUpdatesFilter( } } - override val asUpdateReceiver: UpdateReceiver = { - updatesSharedFlow.emit(it) - } - - override val messagesFlow: Flow = allUpdatesFlow.filterIsInstance() - override val messageMediaGroupsFlow: Flow = allUpdatesFlow.filterIsInstance() - override val editedMessagesFlow: Flow = allUpdatesFlow.filterIsInstance() - override val editedMessageMediaGroupsFlow: Flow = allUpdatesFlow.filterIsInstance() - override val channelPostsFlow: Flow = allUpdatesFlow.filterIsInstance() - override val channelPostMediaGroupsFlow: Flow = allUpdatesFlow.filterIsInstance() - override val editedChannelPostsFlow: Flow = allUpdatesFlow.filterIsInstance() - override val editedChannelPostMediaGroupsFlow: Flow = allUpdatesFlow.filterIsInstance() - override val chosenInlineResultsFlow: Flow = allUpdatesFlow.filterIsInstance() - override val inlineQueriesFlow: Flow = allUpdatesFlow.filterIsInstance() - override val callbackQueriesFlow: Flow = allUpdatesFlow.filterIsInstance() - override val shippingQueriesFlow: Flow = allUpdatesFlow.filterIsInstance() - override val preCheckoutQueriesFlow: Flow = allUpdatesFlow.filterIsInstance() - override val pollsFlow: Flow = allUpdatesFlow.filterIsInstance() - override val pollAnswersFlow: Flow = allUpdatesFlow.filterIsInstance() - override val chatMemberUpdatesFlow: Flow = allUpdatesFlow.filterIsInstance() - override val myChatMemberUpdatesFlow: Flow = allUpdatesFlow.filterIsInstance() - override val unknownUpdatesFlow: Flow = allUpdatesFlow.filterIsInstance() + override val asUpdateReceiver: UpdateReceiver = additionalUpdatesSharedFlow::emit } diff --git a/tgbotapi.extensions.api/README.md b/tgbotapi.extensions.api/README.md index bbe8b0bc77..a686fbf6f4 100644 --- a/tgbotapi.extensions.api/README.md +++ b/tgbotapi.extensions.api/README.md @@ -49,7 +49,7 @@ Dependency config presented here: To use last versions you will need to add one line in repositories block of your `build.gradle`: -`jcenter()` or `mavenCentral()` +`mavenCentral()` And add next line to your dependencies block: diff --git a/tgbotapi.extensions.api/build.gradle b/tgbotapi.extensions.api/build.gradle index 8dcc226dda..54888411ac 100644 --- a/tgbotapi.extensions.api/build.gradle +++ b/tgbotapi.extensions.api/build.gradle @@ -1,7 +1,6 @@ buildscript { repositories { mavenLocal() - jcenter() mavenCentral() } @@ -23,9 +22,7 @@ apply from: "publish.gradle" repositories { mavenLocal() - jcenter() mavenCentral() - maven { url "https://kotlin.bintray.com/kotlinx" } } kotlin { diff --git a/tgbotapi.extensions.behaviour_builder.fsm/README.md b/tgbotapi.extensions.behaviour_builder.fsm/README.md new file mode 100644 index 0000000000..15817d3d3e --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder.fsm/README.md @@ -0,0 +1,3 @@ +# TelegramBotAPI Behaviour Builder FSM Extensions + +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.behaviour_builder.fsm/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.behaviour_builder.fsm) diff --git a/tgbotapi.extensions.behaviour_builder.fsm/build.gradle b/tgbotapi.extensions.behaviour_builder.fsm/build.gradle new file mode 100644 index 0000000000..9183791d96 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder.fsm/build.gradle @@ -0,0 +1,50 @@ +buildscript { + repositories { + mavenLocal() + mavenCentral() + } + + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" + } +} + +plugins { + id "org.jetbrains.kotlin.multiplatform" + id "org.jetbrains.kotlin.plugin.serialization" +} + +project.version = "$library_version" +project.group = "$library_group" + +apply from: "publish.gradle" + +repositories { + mavenLocal() + mavenCentral() +} + +kotlin { + jvm() + js(IR) { + browser() + nodejs() + } + + sourceSets { + commonMain { + dependencies { + implementation kotlin('stdlib') + api project(":tgbotapi.extensions.behaviour_builder") + api "dev.inmo:micro_utils.fsm.common:$micro_utils_version" + } + } + } +} + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } +} diff --git a/tgbotapi.extensions.behaviour_builder.fsm/mpp_publish_template.kpsb b/tgbotapi.extensions.behaviour_builder.fsm/mpp_publish_template.kpsb new file mode 100644 index 0000000000..be7b82e6ec --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder.fsm/mpp_publish_template.kpsb @@ -0,0 +1 @@ +{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"Telegram Bot Behaviour Builder FSM Extensions","description":"FSM extension for dev.inmo:tgbotapi.extensions.behaviour_builder.fsm","url":"https://insanusmokrassar.github.io/TelegramBotAPI/tgbotapi.extensions.behaviour_builder","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","includeGpgSigning":true,"developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI"},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}]}} diff --git a/tgbotapi.extensions.behaviour_builder.fsm/publish.gradle b/tgbotapi.extensions.behaviour_builder.fsm/publish.gradle new file mode 100644 index 0000000000..562185a08c --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder.fsm/publish.gradle @@ -0,0 +1,69 @@ +apply plugin: 'maven-publish' +apply plugin: 'signing' + +task javadocsJar(type: Jar) { + classifier = 'javadoc' +} + +publishing { + publications.all { + artifact javadocsJar + + pom { + description = "FSM extension for dev.inmo:tgbotapi.extensions.behaviour_builder.fsm" + name = "Telegram Bot Behaviour Builder FSM Extensions" + url = "https://insanusmokrassar.github.io/TelegramBotAPI/tgbotapi.extensions.behaviour_builder" + + scm { + developerConnection = "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git" + url = "https://github.com/insanusmokrassar/TelegramBotAPI.git" + } + + developers { + + developer { + id = "InsanusMokrassar" + name = "Ovsiannikov Aleksei" + email = "ovsyannikov.alexey95@gmail.com" + } + + } + + licenses { + + license { + name = "Apache Software License 2.0" + url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE" + } + + } + } + repositories { + if ((project.hasProperty('GITHUBPACKAGES_USER') || System.getenv('GITHUBPACKAGES_USER') != null) && (project.hasProperty('GITHUBPACKAGES_PASSWORD') || System.getenv('GITHUBPACKAGES_PASSWORD') != null)) { + maven { + name = "GithubPackages" + url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI") + credentials { + username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER') + password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD') + } + } + } + if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) { + maven { + name = "sonatype" + url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") + credentials { + username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER') + password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD') + } + } + } + } + } +} + +signing { + useGpgCmd() + sign publishing.publications +} diff --git a/tgbotapi.extensions.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSM.kt b/tgbotapi.extensions.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSM.kt new file mode 100644 index 0000000000..26fc50ea66 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSM.kt @@ -0,0 +1,100 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder + +import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions +import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +import dev.inmo.micro_utils.fsm.common.* +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.types.update.abstracts.Update +import dev.inmo.micro_utils.coroutines.accumulatorFlow +import kotlinx.coroutines.* +import kotlinx.coroutines.channels.BufferOverflow +import kotlinx.coroutines.flow.* + +private suspend fun BehaviourContextWithFSM.launchStateHandling( + state: State, + contextUpdatesFlow: Flow, + handlers: List> +): State? { + return handlers.firstOrNull { it.checkHandleable(state) } ?.run { + handleState(contextUpdatesFlow, state) + } +} + +interface BehaviourContextWithFSM : BehaviourContext, StatesMachine { + override fun copy( + bot: TelegramBot, + scope: CoroutineScope, + broadcastChannelsSize: Int, + onBufferOverflow: BufferOverflow, + upstreamUpdatesFlow: Flow?, + updatesFilter: BehaviourContextAndTypeReceiver? + ): BehaviourContextWithFSM + + companion object { + operator fun invoke( + behaviourContext: BehaviourContext, + handlers: List>, + statesManager: StatesManager + ) = DefaultBehaviourContextWithFSM(behaviourContext, statesManager, handlers) + } +} + +class DefaultBehaviourContextWithFSM( + private val behaviourContext: BehaviourContext, + private val statesManager: StatesManager, + private val handlers: List> +) : BehaviourContext by behaviourContext, BehaviourContextWithFSM { + private val updatesFlows = mutableMapOf>() + private fun getContextUpdatesFlow(context: Any) = updatesFlows.getOrPut(context) { + allUpdatesFlow.accumulatorFlow(scope) + } + override suspend fun StatesMachine.handleState(state: State): State? = launchStateHandling( + state, + allUpdatesFlow, + handlers + ) + + override fun start(scope: CoroutineScope): Job = scope.launchSafelyWithoutExceptions { + val statePerformer: suspend (State) -> Unit = { state: State -> + val newState = launchStateHandling(state, getContextUpdatesFlow(state.context), handlers) + if (newState != null) { + statesManager.update(state, newState) + } else { + statesManager.endChain(state) + } + } + statesManager.onStartChain.subscribeSafelyWithoutExceptions(this) { + launch { statePerformer(it) } + } + statesManager.onChainStateUpdated.subscribeSafelyWithoutExceptions(this) { (old, new) -> + if (old.context != new.context) { + updatesFlows.remove(old.context) + } + launch { statePerformer(new) } + } + statesManager.onEndChain.subscribeSafelyWithoutExceptions(this) { + updatesFlows.remove(it.context) + } + + statesManager.getActiveStates().forEach { + launch { statePerformer(it) } + } + } + + override suspend fun startChain(state: State) { + statesManager.startChain(state) + } + + override fun copy( + bot: TelegramBot, + scope: CoroutineScope, + broadcastChannelsSize: Int, + onBufferOverflow: BufferOverflow, + upstreamUpdatesFlow: Flow?, + updatesFilter: BehaviourContextAndTypeReceiver? + ): BehaviourContextWithFSM = BehaviourContextWithFSM( + behaviourContext.copy(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, updatesFilter), + handlers, + statesManager + ) +} diff --git a/tgbotapi.extensions.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSMBuilder.kt b/tgbotapi.extensions.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSMBuilder.kt new file mode 100644 index 0000000000..cdcd5d2e86 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSMBuilder.kt @@ -0,0 +1,107 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder + +import dev.inmo.micro_utils.fsm.common.* +import dev.inmo.micro_utils.fsm.common.managers.DefaultStatesManager +import dev.inmo.micro_utils.fsm.common.managers.InMemoryDefaultStatesManagerRepo +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling +import dev.inmo.tgbotapi.types.update.abstracts.Update +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.launch +import kotlin.reflect.KClass + +class BehaviourContextWithFSMBuilder internal constructor( + private val resultBehaviourContext: BehaviourContextWithFSM, + private val handlers: MutableList> +) : BehaviourContextWithFSM by resultBehaviourContext { + internal constructor( + baseBehaviourContext: BehaviourContext, + statesManager: StatesManager = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()), + handlers: MutableList> = mutableListOf() + ) : this(DefaultBehaviourContextWithFSM(baseBehaviourContext, statesManager, handlers), handlers) + + /** + * Add NON STRICT [handler] to list of available in future [BehaviourContextWithFSM]. Non strict means that + * for input [State] will be used [KClass.isInstance] and any inheritor of [kClass] will pass this requirement + * + * @see BehaviourWithFSMStateHandlerHolder + * @see onStateOrSubstate + */ + fun add(kClass: KClass, handler: BehaviourWithFSMStateHandler) { + handlers.add(BehaviourWithFSMStateHandlerHolder(kClass, false, handler)) + } + + /** + * Add STRICT [handler] to list of available in future [BehaviourContextWithFSM]. Strict means that + * for input [State] will be used [State]::class == [kClass] and any [State] with exactly the same type will pass + * requirements + * + * @see BehaviourWithFSMStateHandlerHolder + * @see strictlyOn + */ + fun addStrict(kClass: KClass, handler: BehaviourWithFSMStateHandler) { + handlers.add(BehaviourWithFSMStateHandlerHolder(kClass, true, handler)) + } + + /** + * Returns completed [resultBehaviourContext], [handlers] and [statesManager] + */ + internal fun build() = resultBehaviourContext +} + +/** + * Add NON STRICT [handler] to list of available in future [BehaviourContextWithFSM]. Non strict means that + * for input [State] will be used [KClass.isInstance] and any inheritor of [kClass] will pass this requirement + * + * @see BehaviourWithFSMStateHandlerHolder + * @see BehaviourContextWithFSMBuilder.add + */ +inline fun BehaviourContextWithFSMBuilder.onStateOrSubstate(handler: BehaviourWithFSMStateHandler) { + add(I::class, handler) +} + +/** + * Add STRICT [handler] to list of available in future [BehaviourContextWithFSM]. Strict means that + * for input [State] will be used [State]::class == [kClass] and any [State] with exactly the same type will pass + * requirements + * + * @see BehaviourWithFSMStateHandlerHolder + * @see BehaviourContextWithFSMBuilder.addStrict + */ +inline fun BehaviourContextWithFSMBuilder.strictlyOn(handler: BehaviourWithFSMStateHandler) { + addStrict(I::class, handler) +} + +/** + * Use this factory to create and organize behaviour of your bot with attention to FSM logic. This factory WILL NOT + * start any incoming updates handling of FSM handling, you must start it by yourself + * + * @param upstreamUpdatesFlow Will be used in [BehaviourContextWithFSMBuilder.build] to put it in new [BehaviourContextWithFSM] + * @param scope This [CoroutineScope] will be used in [BehaviourContextWithFSMBuilder.build] to put it in new [BehaviourContextWithFSM] + */ +suspend fun TelegramBot.buildBehaviourWithFSM( + upstreamUpdatesFlow: Flow? = null, + scope: CoroutineScope = defaultCoroutineScopeProvider(), + block: suspend BehaviourContextWithFSMBuilder.() -> Unit +) = BehaviourContextWithFSMBuilder( + DefaultBehaviourContext(this, scope, upstreamUpdatesFlow = upstreamUpdatesFlow) +).apply { block() }.build() + +/** + * Use this factory to create and organize behaviour of your bot with attention to FSM logic. This factory will start + * listening of updates by [longPolling] + * + * @param upstreamUpdatesFlow Will be used in [BehaviourContextWithFSMBuilder.build] to put it in new [BehaviourContextWithFSM] + * @param scope This [CoroutineScope] will be used in [BehaviourContextWithFSMBuilder.build] to put it in new [BehaviourContextWithFSM] + */ +suspend fun TelegramBot.buildBehaviourWithFSMAndLongPolling( + upstreamUpdatesFlow: Flow? = null, + scope: CoroutineScope = defaultCoroutineScopeProvider(), + block: suspend BehaviourContextWithFSMBuilder.() -> Unit +) = buildBehaviourWithFSM(upstreamUpdatesFlow, scope, block).run { + this to scope.launch { + longPolling(this@run, scope = this) + start(this) + } +} diff --git a/tgbotapi.extensions.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourWithFSMStateHandler.kt b/tgbotapi.extensions.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourWithFSMStateHandler.kt new file mode 100644 index 0000000000..c2e1b6f32f --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourWithFSMStateHandler.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder + +import dev.inmo.micro_utils.fsm.common.* + +fun interface BehaviourWithFSMStateHandler { + suspend fun BehaviourContextWithFSM.handleState(state: T): State? +} diff --git a/tgbotapi.extensions.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourWithFSMStateHandlerHolder.kt b/tgbotapi.extensions.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourWithFSMStateHandlerHolder.kt new file mode 100644 index 0000000000..00a8d4a82a --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourWithFSMStateHandlerHolder.kt @@ -0,0 +1,52 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder + +import dev.inmo.micro_utils.coroutines.LinkedSupervisorScope +import dev.inmo.micro_utils.coroutines.weakLaunch +import dev.inmo.micro_utils.fsm.common.* +import dev.inmo.tgbotapi.types.update.abstracts.Update +import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.collect +import kotlin.reflect.KClass + +/** + * Special holder for [BehaviourContextWithFSM]. This holder helps [BehaviourContextWithFSM] to understand whether it + * can handle input [State] with [delegateTo] or not + * + * @param inputKlass This [KClass] will be used to compare input [State] type and declare ability of [delegateTo] to + * handle incoming [State]. See [checkHandleable] for more info + * @param strict This flag will be used in [checkHandleable] to choose strategy of checking incoming [State] + * @param delegateTo This handler will be called in case [checkHandleable] returns true with class caster incoming + * [State] in [handleState] + */ +class BehaviourWithFSMStateHandlerHolder( + private val inputKlass: KClass, + private val strict: Boolean = false, + private val delegateTo: BehaviourWithFSMStateHandler +) { + /** + * Check ability of [delegateTo] to handle this [state] + * + * @return When [state]::class exactly equals to [inputKlass] will always return true. Otherwise when [strict] + * mode is disabled, will be used [KClass.isInstance] of [inputKlass] for checking + */ + fun checkHandleable(state: State) = state::class == inputKlass || (!strict && inputKlass.isInstance(state)) + + /** + * Handling of state :) + * + * @param contextUpdatesFlow This [Flow] will be used as source of updates. By contract, this [Flow] must be common + * for all [State]s of incoming [state] [State.context] and for the whole chain inside of [BehaviourContextWithFSM] + */ + suspend fun BehaviourContextWithFSM.handleState( + contextUpdatesFlow: Flow, + state: State + ): State? { + val subscope = scope.LinkedSupervisorScope() + return with(copy(scope = subscope, upstreamUpdatesFlow = contextUpdatesFlow)) { + with(delegateTo) { + handleState(state as I) + } + } + } +} diff --git a/tgbotapi.extensions.behaviour_builder/build.gradle b/tgbotapi.extensions.behaviour_builder/build.gradle index fe275f7938..b85db355e2 100644 --- a/tgbotapi.extensions.behaviour_builder/build.gradle +++ b/tgbotapi.extensions.behaviour_builder/build.gradle @@ -1,7 +1,6 @@ buildscript { repositories { mavenLocal() - jcenter() mavenCentral() } @@ -23,9 +22,7 @@ apply from: "publish.gradle" repositories { mavenLocal() - jcenter() mavenCentral() - maven { url "https://kotlin.bintray.com/kotlinx" } } kotlin { diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt index 2fb4504b79..c81e7a5981 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt @@ -5,20 +5,25 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder import dev.inmo.micro_utils.coroutines.* import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.types.update.abstracts.Update -import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter +import dev.inmo.tgbotapi.updateshandlers.* import dev.inmo.tgbotapi.utils.RiskFeature import kotlinx.coroutines.* -import kotlinx.coroutines.flow.filter +import kotlinx.coroutines.channels.BufferOverflow +import kotlinx.coroutines.flow.* -typealias BehaviourContextReceiver = suspend BehaviourContext.() -> T -typealias BehaviourContextAndTypeReceiver = suspend BehaviourContext.(I) -> T -typealias BehaviourContextAndTwoTypesReceiver = suspend BehaviourContext.(I1, I2) -> T +typealias CustomBehaviourContextReceiver = suspend BC.() -> T +typealias BehaviourContextReceiver = CustomBehaviourContextReceiver +typealias CustomBehaviourContextAndTypeReceiver = suspend BC.(I) -> T +typealias BehaviourContextAndTypeReceiver = CustomBehaviourContextAndTypeReceiver +typealias CustomBehaviourContextAndTwoTypesReceiver = suspend BC.(I1, I2) -> T +typealias BehaviourContextAndTwoTypesReceiver = CustomBehaviourContextAndTwoTypesReceiver inline fun BehaviourContextReceiver(noinline block: BehaviourContextReceiver) = block +inline fun CustomBehaviourContextReceiver(noinline block: CustomBehaviourContextReceiver) = block inline fun BehaviourContextAndTypeReceiver(noinline block: BehaviourContextAndTypeReceiver) = block inline fun BehaviourContextAndTwoTypesReceiver(noinline block: BehaviourContextAndTwoTypesReceiver) = block -internal inline fun BehaviourContextAndTwoTypesReceiver.toOneType( +internal inline fun CustomBehaviourContextAndTwoTypesReceiver.toOneType( i1: I1, -): BehaviourContextAndTypeReceiver = { invoke(this, i1, it) } +): CustomBehaviourContextAndTypeReceiver = { invoke(this, i1, it) } /** * This class contains all necessary tools for work with bots and especially for [buildBehaviour] @@ -45,27 +50,68 @@ interface BehaviourContext : FlowsUpdatesFilter, TelegramBot, CoroutineScope { fun copy( bot: TelegramBot = this.bot, scope: CoroutineScope = this.scope, - flowsUpdatesFilter: FlowsUpdatesFilter = this.flowsUpdatesFilter + broadcastChannelsSize: Int = 100, + onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND, + upstreamUpdatesFlow: Flow? = null, + updatesFilter: BehaviourContextAndTypeReceiver? = null ): BehaviourContext + + @Deprecated("This method is not recommended to use and will be removed in near release") + fun copy( + bot: TelegramBot, + scope: CoroutineScope = this.scope, + flowsUpdatesFilter: FlowsUpdatesFilter = this.flowsUpdatesFilter + ): BehaviourContext = copy(upstreamUpdatesFlow = flowsUpdatesFilter.allUpdatesFlow) } class DefaultBehaviourContext( override val bot: TelegramBot, override val scope: CoroutineScope, - override val flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter() -) : FlowsUpdatesFilter by flowsUpdatesFilter, TelegramBot by bot, CoroutineScope by scope, BehaviourContext { + private val broadcastChannelsSize: Int = 100, + private val onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND, + private val upstreamUpdatesFlow: Flow? = null, + private val updatesFilter: BehaviourContextAndTypeReceiver? = null +) : AbstractFlowsUpdatesFilter(), TelegramBot by bot, CoroutineScope by scope, BehaviourContext { + + private val additionalUpdatesSharedFlow = MutableSharedFlow(0, broadcastChannelsSize, onBufferOverflow) + override val allUpdatesFlow: Flow = (additionalUpdatesSharedFlow.asSharedFlow()).let { + if (upstreamUpdatesFlow != null) { + (it + upstreamUpdatesFlow).distinctUntilChanged { old, new -> old.updateId == new.updateId } + } else { + it + } + }.let { + val updatesFilter = updatesFilter + if (updatesFilter != null) { + it.filter { updatesFilter(it) } + } else { + it + } + } + override val asUpdateReceiver: UpdateReceiver = additionalUpdatesSharedFlow::emit + override fun copy( bot: TelegramBot, scope: CoroutineScope, - flowsUpdatesFilter: FlowsUpdatesFilter - ): DefaultBehaviourContext = DefaultBehaviourContext(bot, scope, flowsUpdatesFilter) + broadcastChannelsSize: Int, + onBufferOverflow: BufferOverflow, + upstreamUpdatesFlow: Flow?, + updatesFilter: BehaviourContextAndTypeReceiver? + ): BehaviourContext = DefaultBehaviourContext(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, updatesFilter) } fun BehaviourContext( bot: TelegramBot, scope: CoroutineScope, flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter() -) = DefaultBehaviourContext(bot, scope, flowsUpdatesFilter) +) = DefaultBehaviourContext(bot, scope, upstreamUpdatesFlow = flowsUpdatesFilter.allUpdatesFlow) + +inline fun BehaviourContext( + bot: TelegramBot, + scope: CoroutineScope, + flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter(), + crossinline block: BehaviourContext.() -> T +) = DefaultBehaviourContext(bot, scope, upstreamUpdatesFlow = flowsUpdatesFilter.allUpdatesFlow).run(block) /** * Creates new one [BehaviourContext], adding subsequent [FlowsUpdatesFilter] in case [newFlowsUpdatesFilterSetUp] is provided and @@ -75,21 +121,19 @@ fun BehaviourContext( */ @RiskFeature("It is recommended to use doInSubContextWithUpdatesFilter instead. " + "This method is low level and should not be used in case you are not pretty sure you need it.") -suspend fun BehaviourContext.doInSubContextWithFlowsUpdatesFilterSetup( - newFlowsUpdatesFilterSetUp: BehaviourContextAndTypeReceiver?, +@Deprecated("This method is useless and will not be used in future") +suspend fun BC.doInSubContextWithFlowsUpdatesFilterSetup( + newFlowsUpdatesFilterSetUp: CustomBehaviourContextAndTypeReceiver?, stopOnCompletion: Boolean = true, - behaviourContextReceiver: BehaviourContextReceiver -): T { - return copy( - flowsUpdatesFilter = FlowsUpdatesFilter(), - scope = LinkedSupervisorScope() - ).run { + behaviourContextReceiver: CustomBehaviourContextReceiver +): T = (copy( + scope = LinkedSupervisorScope(), +) as BC).run { + withContext(coroutineContext) { newFlowsUpdatesFilterSetUp ?.let { it.apply { invoke(this@run, this@doInSubContextWithFlowsUpdatesFilterSetup.flowsUpdatesFilter) } } - withContext(coroutineContext) { - behaviourContextReceiver().also { if (stopOnCompletion) stop() } - } + behaviourContextReceiver().also { if (stopOnCompletion) stop() } } } @@ -97,25 +141,24 @@ suspend fun BehaviourContext.doInSubContextWithFlowsUpdatesFilterSetup( * Creates new one [BehaviourContext], adding subsequent [FlowsUpdatesFilter] in case [updatesFilter] is provided and * [CoroutineScope] as new [BehaviourContext.scope] */ -suspend fun BehaviourContext.doInSubContextWithUpdatesFilter( - updatesFilter: BehaviourContextAndTypeReceiver?, +suspend fun BC.doInSubContextWithUpdatesFilter( + updatesFilter: CustomBehaviourContextAndTypeReceiver?, stopOnCompletion: Boolean = true, - behaviourContextReceiver: BehaviourContextReceiver -): T = doInSubContextWithFlowsUpdatesFilterSetup( - newFlowsUpdatesFilterSetUp = updatesFilter ?.let { - { oldOne -> - weakLaunch { - oldOne.allUpdatesFlow.filter { updatesFilter(it) }.subscribeSafelyWithoutExceptions(this, block = asUpdateReceiver) - } + behaviourContextReceiver: CustomBehaviourContextReceiver +): T = copy( + scope = LinkedSupervisorScope(), + updatesFilter = updatesFilter ?.let { _ -> + { + (this as? BC) ?.run { + updatesFilter(it) + } ?: true } - } ?: { oldOne -> - weakLaunch { - oldOne.allUpdatesFlow.subscribeSafelyWithoutExceptions(this, block = asUpdateReceiver) - } - }, - stopOnCompletion, - behaviourContextReceiver -) + } +).run { + withContext(coroutineContext) { + behaviourContextReceiver().also { if (stopOnCompletion) stop() } + } +} suspend fun BehaviourContext.doInSubContext( stopOnCompletion: Boolean = true, diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/Base.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/Base.kt index 822785234a..c5f1364cbf 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/Base.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/Base.kt @@ -4,6 +4,7 @@ import dev.inmo.micro_utils.coroutines.safelyWithResult import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import dev.inmo.tgbotapi.extensions.utils.flatMap import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter @@ -38,9 +39,9 @@ suspend fun FlowsUpdatesFilter.expectFlow( cancelTrigger: suspend (Update) -> Boolean = { cancelRequestFactory(it) != null }, filter: suspend (Update) -> List ): Flow { - val flow = allUpdatesFlow.flatMapConcat { + val flow = allUpdatesFlow.map { val result = safelyWithResult { filter(it) } - (if (result.isFailure || result.getOrThrow().isEmpty()) { + if (result.isFailure || result.getOrThrow().isEmpty()) { if (cancelTrigger(it)) { cancelRequestFactory(it) ?.also { safelyWithResult { bot.execute(it) } @@ -53,8 +54,8 @@ suspend fun FlowsUpdatesFilter.expectFlow( emptyList() } else { result.getOrThrow() - }).asFlow() - } + } + }.flatMap() val result = if (count == null) { flow } else { diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt index d7abb32cee..08a60ddce1 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt @@ -14,6 +14,7 @@ import dev.inmo.tgbotapi.types.message.content.media.* import dev.inmo.tgbotapi.types.message.payments.InvoiceContent import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.SentMediaGroupUpdate import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate +import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.toList typealias CommonMessageToContentMapper = suspend CommonMessage.() -> T? @@ -25,7 +26,7 @@ private suspend fun BehaviourContext.waitCommonMessage( errorFactory: NullableRequestBuilder<*> = { null }, filter: SimpleFilter>? = null, mapper: suspend CommonMessage.() -> O? -): List = expectFlow( +): Flow = expectFlow( initRequest, count, errorFactory @@ -49,7 +50,7 @@ private suspend fun BehaviourContext.waitCommonMessage( null } } -}.toList().toList() +} internal inline fun contentConverter( noinline mapper: CommonMessageToContentMapper? = null @@ -85,7 +86,7 @@ private suspend inline fun BehaviourContext.waitCon } }, contentConverter(mapper) -) +).toList() suspend fun BehaviourContext.waitContentMessage( initRequest: Request<*>? = null, 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..9e7bdce543 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 @@ -11,11 +11,11 @@ import dev.inmo.tgbotapi.extensions.utils.asCallbackQueryUpdate import dev.inmo.tgbotapi.types.CallbackQuery.* import dev.inmo.tgbotapi.types.update.abstracts.Update -internal suspend inline fun BehaviourContext.onCallbackQuery( +internal suspend inline fun BC.onCallbackQuery( noinline initialFilter: SimpleFilter? = null, - noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, - noinline scenarioReceiver: BehaviourContextAndTypeReceiver + noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { (it.asCallbackQueryUpdate() ?.data as? T) ?.let(::listOfNotNull) } @@ -32,11 +32,11 @@ internal suspend inline fun BehaviourContext.onCallb * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onDataCallbackQuery( +suspend fun BC.onDataCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( initialFilter, subcontextUpdatesFilter, @@ -56,11 +56,11 @@ suspend fun BehaviourContext.onDataCallbackQuery( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onGameShortNameCallbackQuery( +suspend fun BC.onGameShortNameCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( initialFilter, subcontextUpdatesFilter, @@ -80,11 +80,11 @@ suspend fun BehaviourContext.onGameShortNameCallbackQuery( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onInlineMessageIdCallbackQuery( +suspend fun BC.onInlineMessageIdCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( initialFilter, subcontextUpdatesFilter, @@ -104,11 +104,11 @@ suspend fun BehaviourContext.onInlineMessageIdCallbackQuery( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onInlineMessageIdDataCallbackQuery( +suspend fun BC.onInlineMessageIdDataCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( initialFilter, subcontextUpdatesFilter, @@ -128,11 +128,11 @@ suspend fun BehaviourContext.onInlineMessageIdDataCallbackQuery( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onInlineMessageIdGameShortNameCallbackQuery( +suspend fun BC.onInlineMessageIdGameShortNameCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( initialFilter, subcontextUpdatesFilter, @@ -152,11 +152,11 @@ suspend fun BehaviourContext.onInlineMessageIdGameShortNameCallbackQuery( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onMessageCallbackQuery( +suspend fun BC.onMessageCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( initialFilter, subcontextUpdatesFilter, @@ -176,11 +176,11 @@ suspend fun BehaviourContext.onMessageCallbackQuery( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onMessageDataCallbackQuery( +suspend fun BC.onMessageDataCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( initialFilter, subcontextUpdatesFilter, @@ -200,11 +200,11 @@ suspend fun BehaviourContext.onMessageDataCallbackQuery( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onMessageGameShortNameCallbackQuery( +suspend fun BC.onMessageGameShortNameCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( initialFilter, subcontextUpdatesFilter, @@ -224,11 +224,11 @@ suspend fun BehaviourContext.onMessageGameShortNameCallbackQuery( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onUnknownCallbackQueryType( +suspend fun BC.onUnknownCallbackQueryType( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( initialFilter, subcontextUpdatesFilter, 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 f39006f3a2..9f8cfa7193 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 @@ -13,11 +13,11 @@ import dev.inmo.tgbotapi.types.update.MyChatMemberUpdatedUpdate import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate import dev.inmo.tgbotapi.types.update.abstracts.Update -internal suspend inline fun BehaviourContext.onChatMemberUpdatedInternal( +internal suspend inline fun BC.onChatMemberUpdatedInternal( noinline initialFilter: SimpleFilter? = null, - noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = ChatMemberUpdatedFilterByChat, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = ChatMemberUpdatedFilterByChat, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, - noinline scenarioReceiver: BehaviourContextAndTypeReceiver + noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { ((it as? U) ?.data) ?.let(::listOfNotNull) } @@ -35,12 +35,12 @@ internal suspend inline fun BehaviourConte * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onChatMemberUpdated( +suspend fun BC.onChatMemberUpdated( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = ChatMemberUpdatedFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = ChatMemberUpdatedFilterByChat, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver -) = onChatMemberUpdatedInternal( + scenarioReceiver: CustomBehaviourContextAndTypeReceiver +) = onChatMemberUpdatedInternal( initialFilter, subcontextUpdatesFilter, markerFactory, @@ -59,12 +59,12 @@ suspend fun BehaviourContext.onChatMemberUpdated( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onCommonChatMemberUpdated( +suspend fun BC.onCommonChatMemberUpdated( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = ChatMemberUpdatedFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = ChatMemberUpdatedFilterByChat, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver -) = onChatMemberUpdatedInternal( + scenarioReceiver: CustomBehaviourContextAndTypeReceiver +) = onChatMemberUpdatedInternal( initialFilter, subcontextUpdatesFilter, markerFactory, @@ -83,12 +83,12 @@ suspend fun BehaviourContext.onCommonChatMemberUpdated( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onMyChatMemberUpdated( +suspend fun BC.onMyChatMemberUpdated( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = ChatMemberUpdatedFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = ChatMemberUpdatedFilterByChat, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver -) = onChatMemberUpdatedInternal( + scenarioReceiver: CustomBehaviourContextAndTypeReceiver +) = onChatMemberUpdatedInternal( 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 index 5102f9c356..c2689cec06 100644 --- 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 @@ -11,11 +11,11 @@ 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( +internal suspend inline fun BC.onChosenInlineResultBase( noinline initialFilter: SimpleFilter? = null, - noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserIdChosenInlineResultMarkerFactory, - noinline scenarioReceiver: BehaviourContextAndTypeReceiver + noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { (it.asChosenInlineResultUpdate() ?.data as? T) ?.let(::listOfNotNull) } @@ -32,11 +32,11 @@ internal suspend inline fun BehaviourContext.on * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onChosenInlineResult( +suspend fun BC.onChosenInlineResult( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserIdChosenInlineResultMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onChosenInlineResultBase( initialFilter, subcontextUpdatesFilter, @@ -56,11 +56,11 @@ suspend fun BehaviourContext.onChosenInlineResult( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onLocationChosenInlineResult( +suspend fun BC.onLocationChosenInlineResult( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserIdChosenInlineResultMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onChosenInlineResultBase( initialFilter, subcontextUpdatesFilter, @@ -80,11 +80,11 @@ suspend fun BehaviourContext.onLocationChosenInlineResult( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onBaseChosenInlineResult( +suspend fun BC.onBaseChosenInlineResult( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserIdChosenInlineResultMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onChosenInlineResultBase( initialFilter, subcontextUpdatesFilter, 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 5273249781..ad04efa0f2 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 @@ -16,13 +16,13 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update import kotlinx.coroutines.Job -suspend fun BehaviourContext.command( +suspend fun BC.command( commandRegex: Regex, requireOnlyCommandInMessage: Boolean = true, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ): Job = onText( CommonMessageFilter { message -> val content = message.content @@ -43,39 +43,39 @@ suspend fun BehaviourContext.command( scenarioReceiver ) -suspend fun BehaviourContext.command( +suspend fun BC.command( command: String, requireOnlyCommandInMessage: Boolean = true, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = command(command.toRegex(), requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) -suspend inline fun BehaviourContext.onCommand( +suspend inline fun BC.onCommand( commandRegex: Regex, requireOnlyCommandInMessage: Boolean = true, noinline initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - noinline scenarioReceiver: BehaviourContextAndTypeReceiver> + noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ): Job = command(commandRegex, requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) -suspend inline fun BehaviourContext.onCommand( +suspend inline fun BC.onCommand( command: String, requireOnlyCommandInMessage: Boolean = true, noinline initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - noinline scenarioReceiver: BehaviourContextAndTypeReceiver> + noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ): Job = onCommand(command.toRegex(), requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) -suspend fun BehaviourContext.commandWithArgs( +suspend fun BC.commandWithArgs( commandRegex: Regex, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTwoTypesReceiver, Array> + scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver, Array> ) = command( commandRegex, requireOnlyCommandInMessage = false, @@ -90,12 +90,12 @@ suspend fun BehaviourContext.commandWithArgs( scenarioReceiver(it, args) } -suspend fun BehaviourContext.commandWithArgs( +suspend fun BC.commandWithArgs( command: String, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTwoTypesReceiver, Array> + scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver, Array> ) = commandWithArgs( command.toRegex(), initialFilter = initialFilter, @@ -104,18 +104,18 @@ suspend fun BehaviourContext.commandWithArgs( scenarioReceiver = scenarioReceiver ) -suspend inline fun BehaviourContext.onCommandWithArgs( +suspend inline fun BC.onCommandWithArgs( commandRegex: Regex, noinline initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - noinline scenarioReceiver: BehaviourContextAndTwoTypesReceiver, Array> + noinline scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver, Array> ): Job = commandWithArgs(commandRegex, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) -suspend inline fun BehaviourContext.onCommandWithArgs( +suspend inline fun BC.onCommandWithArgs( command: String, noinline initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - noinline scenarioReceiver: BehaviourContextAndTwoTypesReceiver, Array> + noinline scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver, Array> ): Job = onCommandWithArgs(command.toRegex(), initialFilter, subcontextUpdatesFilter, 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 028a97d102..21a867bc4b 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 @@ -22,11 +22,11 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update typealias CommonMessageFilter = SimpleFilter> inline fun CommonMessageFilter(noinline block: CommonMessageFilter) = block -internal suspend inline fun BehaviourContext.onContent( +internal suspend inline fun BC.onContent( noinline initialFilter: CommonMessageFilter? = null, - noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - noinline scenarioReceiver: BehaviourContextAndTypeReceiver> + noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { when (it) { is BaseSentMessageUpdate -> it.data.whenCommonMessage(::listOfNotNull) @@ -50,11 +50,11 @@ internal suspend inline fun BehaviourContext.onCont * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onContentMessage( +suspend fun BC.onContentMessage( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -74,11 +74,11 @@ suspend fun BehaviourContext.onContentMessage( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onContact( +suspend fun BC.onContact( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -98,11 +98,11 @@ suspend fun BehaviourContext.onContact( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onDice( +suspend fun BC.onDice( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -122,11 +122,11 @@ suspend fun BehaviourContext.onDice( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onGame( +suspend fun BC.onGame( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -146,11 +146,11 @@ suspend fun BehaviourContext.onGame( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onLocation( +suspend fun BC.onLocation( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -170,11 +170,11 @@ suspend fun BehaviourContext.onLocation( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onLiveLocation( +suspend fun BC.onLiveLocation( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -194,11 +194,11 @@ suspend fun BehaviourContext.onLiveLocation( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onStaticLocation( +suspend fun BC.onStaticLocation( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -218,11 +218,11 @@ suspend fun BehaviourContext.onStaticLocation( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onPoll( +suspend fun BC.onPoll( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -242,11 +242,11 @@ suspend fun BehaviourContext.onPoll( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onText( +suspend fun BC.onText( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -266,11 +266,11 @@ suspend fun BehaviourContext.onText( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onVenue( +suspend fun BC.onVenue( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -290,11 +290,11 @@ suspend fun BehaviourContext.onVenue( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onAudioMediaGroup( +suspend fun BC.onAudioMediaGroup( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -314,11 +314,11 @@ suspend fun BehaviourContext.onAudioMediaGroup( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onDocumentMediaGroupContent( +suspend fun BC.onDocumentMediaGroupContent( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -338,11 +338,11 @@ suspend fun BehaviourContext.onDocumentMediaGroupContent( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onMediaCollection( +suspend fun BC.onMediaCollection( initialFilter: CommonMessageFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver>, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update> = MessageFilterByChat, markerFactory: MarkerFactory>, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver>> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -362,11 +362,11 @@ suspend fun BehaviourContext.onMediaCollection( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onMedia( +suspend fun BC.onMedia( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -386,11 +386,11 @@ suspend fun BehaviourContext.onMedia( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onAnimation( +suspend fun BC.onAnimation( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -410,11 +410,11 @@ suspend fun BehaviourContext.onAnimation( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onAudio( +suspend fun BC.onAudio( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -434,11 +434,11 @@ suspend fun BehaviourContext.onAudio( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onDocument( +suspend fun BC.onDocument( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -458,11 +458,11 @@ suspend fun BehaviourContext.onDocument( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onPhoto( +suspend fun BC.onPhoto( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -482,11 +482,11 @@ suspend fun BehaviourContext.onPhoto( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onSticker( +suspend fun BC.onSticker( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -506,11 +506,11 @@ suspend fun BehaviourContext.onSticker( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onVideo( +suspend fun BC.onVideo( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -530,11 +530,11 @@ suspend fun BehaviourContext.onVideo( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onVideoNote( +suspend fun BC.onVideoNote( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -554,11 +554,11 @@ suspend fun BehaviourContext.onVideoNote( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onVoice( +suspend fun BC.onVoice( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, @@ -578,11 +578,11 @@ suspend fun BehaviourContext.onVoice( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onInvoice( +suspend fun BC.onInvoice( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContent( initialFilter, subcontextUpdatesFilter, diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EditedContentTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EditedContentTriggers.kt index dbbb7bd43b..a78aa2ca76 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EditedContentTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EditedContentTriggers.kt @@ -33,11 +33,11 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.utils.PreviewFeature @PreviewFeature -internal suspend inline fun BehaviourContext.onEditedContent( +internal suspend inline fun BC.onEditedContent( noinline initialFilter: CommonMessageFilter? = null, - noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - noinline scenarioReceiver: BehaviourContextAndTypeReceiver> + noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { when (it) { is BaseEditMessageUpdate -> (it.asEditMessageUpdate() ?.data ?.withContent()) @@ -58,11 +58,11 @@ internal suspend inline fun BehaviourContext.onEdit * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedContentMessage( +suspend fun BC.onEditedContentMessage( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -82,11 +82,11 @@ suspend fun BehaviourContext.onEditedContentMessage( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedContact( +suspend fun BC.onEditedContact( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -106,11 +106,11 @@ suspend fun BehaviourContext.onEditedContact( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedDice( +suspend fun BC.onEditedDice( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -130,11 +130,11 @@ suspend fun BehaviourContext.onEditedDice( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedGame( +suspend fun BC.onEditedGame( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -154,11 +154,11 @@ suspend fun BehaviourContext.onEditedGame( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedLocation( +suspend fun BC.onEditedLocation( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -167,11 +167,11 @@ suspend fun BehaviourContext.onEditedLocation( ) @Deprecated("Potentially, this trigger will never be used. Use `onPollUpdated` instead") -suspend fun BehaviourContext.onEditedPoll( +suspend fun BC.onEditedPoll( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -191,11 +191,11 @@ suspend fun BehaviourContext.onEditedPoll( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedText( +suspend fun BC.onEditedText( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -215,11 +215,11 @@ suspend fun BehaviourContext.onEditedText( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedVenue( +suspend fun BC.onEditedVenue( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -239,11 +239,11 @@ suspend fun BehaviourContext.onEditedVenue( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedAudioMediaGroup( +suspend fun BC.onEditedAudioMediaGroup( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -263,11 +263,11 @@ suspend fun BehaviourContext.onEditedAudioMediaGroup( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedDocumentMediaGroupContent( +suspend fun BC.onEditedDocumentMediaGroupContent( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -287,11 +287,11 @@ suspend fun BehaviourContext.onEditedDocumentMediaGroupContent( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedMediaCollection( +suspend fun BC.onEditedMediaCollection( initialFilter: CommonMessageFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver>, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update> = MessageFilterByChat, markerFactory: MarkerFactory>, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver>> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -311,11 +311,11 @@ suspend fun BehaviourContext.onEditedMediaCollection( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedMedia( +suspend fun BC.onEditedMedia( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -335,11 +335,11 @@ suspend fun BehaviourContext.onEditedMedia( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedAnimation( +suspend fun BC.onEditedAnimation( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -359,11 +359,11 @@ suspend fun BehaviourContext.onEditedAnimation( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedAudio( +suspend fun BC.onEditedAudio( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -383,11 +383,11 @@ suspend fun BehaviourContext.onEditedAudio( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedDocument( +suspend fun BC.onEditedDocument( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -407,11 +407,11 @@ suspend fun BehaviourContext.onEditedDocument( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedPhoto( +suspend fun BC.onEditedPhoto( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -431,11 +431,11 @@ suspend fun BehaviourContext.onEditedPhoto( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedSticker( +suspend fun BC.onEditedSticker( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -455,11 +455,11 @@ suspend fun BehaviourContext.onEditedSticker( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedVideo( +suspend fun BC.onEditedVideo( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -479,11 +479,11 @@ suspend fun BehaviourContext.onEditedVideo( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedVideoNote( +suspend fun BC.onEditedVideoNote( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -503,11 +503,11 @@ suspend fun BehaviourContext.onEditedVideoNote( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedVoice( +suspend fun BC.onEditedVoice( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, @@ -527,11 +527,11 @@ suspend fun BehaviourContext.onEditedVoice( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onEditedInvoice( +suspend fun BC.onEditedInvoice( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( initialFilter, subcontextUpdatesFilter, 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 00d4f6e447..415e2e4f11 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 @@ -16,11 +16,11 @@ import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent import dev.inmo.tgbotapi.types.update.abstracts.Update -internal suspend inline fun BehaviourContext.onEvent( +internal suspend inline fun BC.onEvent( noinline initialFilter: SimpleFilter>? = null, - noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - noinline scenarioReceiver: BehaviourContextAndTypeReceiver> + noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { (it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.takeIf { it.chatEvent is T } as? ChatEventMessage) ?.let(::listOfNotNull) } @@ -37,11 +37,11 @@ internal suspend inline fun BehaviourContext.onEvent( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onChannelEvent( +suspend fun BC.onChannelEvent( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -56,11 +56,11 @@ suspend fun BehaviourContext.onChannelEvent( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onPrivateEvent( +suspend fun BC.onPrivateEvent( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -75,11 +75,11 @@ suspend fun BehaviourContext.onPrivateEvent( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onChatEvent( +suspend fun BC.onChatEvent( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -94,11 +94,11 @@ suspend fun BehaviourContext.onChatEvent( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onVoiceChatEvent( +suspend fun BC.onVoiceChatEvent( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -113,11 +113,11 @@ suspend fun BehaviourContext.onVoiceChatEvent( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onVoiceChatStartedEvent( +suspend fun BC.onVoiceChatStartedEvent( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -132,11 +132,11 @@ suspend fun BehaviourContext.onVoiceChatStartedEvent( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onVoiceChatEndedEvent( +suspend fun BC.onVoiceChatEndedEvent( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -151,11 +151,11 @@ suspend fun BehaviourContext.onVoiceChatEndedEvent( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onVoiceChatParticipantsInvitedEvent( +suspend fun BC.onVoiceChatParticipantsInvitedEvent( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -170,11 +170,11 @@ suspend fun BehaviourContext.onVoiceChatParticipantsInvitedEvent( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onMessageAutoDeleteTimerChangedEvent( +suspend fun BC.onMessageAutoDeleteTimerChangedEvent( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -189,11 +189,11 @@ suspend fun BehaviourContext.onMessageAutoDeleteTimerChangedEvent( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onPublicChatEvent( +suspend fun BC.onPublicChatEvent( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -208,11 +208,11 @@ suspend fun BehaviourContext.onPublicChatEvent( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onCommonEvent( +suspend fun BC.onCommonEvent( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -227,11 +227,11 @@ suspend fun BehaviourContext.onCommonEvent( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onGroupEvent( +suspend fun BC.onGroupEvent( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -246,11 +246,11 @@ suspend fun BehaviourContext.onGroupEvent( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onSupergroupEvent( +suspend fun BC.onSupergroupEvent( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -265,11 +265,11 @@ suspend fun BehaviourContext.onSupergroupEvent( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onChannelChatCreated( +suspend fun BC.onChannelChatCreated( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -284,11 +284,11 @@ suspend fun BehaviourContext.onChannelChatCreated( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onDeleteChatPhoto( +suspend fun BC.onDeleteChatPhoto( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -303,11 +303,11 @@ suspend fun BehaviourContext.onDeleteChatPhoto( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onGroupChatCreated( +suspend fun BC.onGroupChatCreated( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -322,11 +322,11 @@ suspend fun BehaviourContext.onGroupChatCreated( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onLeftChatMember( +suspend fun BC.onLeftChatMember( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -341,11 +341,11 @@ suspend fun BehaviourContext.onLeftChatMember( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onNewChatMembers( +suspend fun BC.onNewChatMembers( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -360,11 +360,11 @@ suspend fun BehaviourContext.onNewChatMembers( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onNewChatPhoto( +suspend fun BC.onNewChatPhoto( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -379,11 +379,11 @@ suspend fun BehaviourContext.onNewChatPhoto( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onNewChatTitle( +suspend fun BC.onNewChatTitle( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -398,11 +398,11 @@ suspend fun BehaviourContext.onNewChatTitle( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onPinnedMessage( +suspend fun BC.onPinnedMessage( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -417,11 +417,11 @@ suspend fun BehaviourContext.onPinnedMessage( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onProximityAlertTriggered( +suspend fun BC.onProximityAlertTriggered( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -436,11 +436,11 @@ suspend fun BehaviourContext.onProximityAlertTriggered( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onSupergroupChatCreated( +suspend fun BC.onSupergroupChatCreated( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -455,9 +455,9 @@ suspend fun BehaviourContext.onSupergroupChatCreated( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onSuccessfulPayment( +suspend fun BC.onSuccessfulPayment( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, 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 be677995c9..fec661e30e 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 @@ -9,11 +9,11 @@ import dev.inmo.tgbotapi.extensions.utils.asInlineQueryUpdate import dev.inmo.tgbotapi.types.InlineQueries.query.* import dev.inmo.tgbotapi.types.update.abstracts.Update -internal suspend inline fun BehaviourContext.onInlineQuery( +internal suspend inline fun BC.onInlineQuery( noinline initialFilter: SimpleFilter? = null, - noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = InlineQueryFilterByUser, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = InlineQueryFilterByUser, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, - noinline scenarioReceiver: BehaviourContextAndTypeReceiver + noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { (it.asInlineQueryUpdate() ?.data as? T) ?.let(::listOfNotNull) } @@ -30,11 +30,11 @@ internal suspend inline fun BehaviourContext.onInlineQ * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onAnyInlineQuery( +suspend fun BC.onAnyInlineQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = InlineQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = InlineQueryFilterByUser, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onInlineQuery(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) @@ -50,11 +50,11 @@ suspend fun BehaviourContext.onAnyInlineQuery( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onBaseInlineQuery( +suspend fun BC.onBaseInlineQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = InlineQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = InlineQueryFilterByUser, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onInlineQuery(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) @@ -70,9 +70,9 @@ suspend fun BehaviourContext.onBaseInlineQuery( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onLocationInlineQuery( +suspend fun BC.onLocationInlineQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = InlineQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = InlineQueryFilterByUser, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onInlineQuery(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MainTrigger.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MainTrigger.kt index 8556adc051..fc561aa605 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MainTrigger.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MainTrigger.kt @@ -7,14 +7,11 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.types.update.abstracts.Update -internal const val OldAPITriggersDeprecationText = "This signature of method has been deprecated. Use signature with the" + - " same name and subcontextUpdatesFilter/initialFilter instead" - -internal suspend inline fun BehaviourContext.on( +internal suspend inline fun BC.on( markerFactory: MarkerFactory, noinline initialFilter: SimpleFilter? = null, - noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, - noinline scenarioReceiver: BehaviourContextAndTypeReceiver, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver, noinline updateToData: (Update) -> List? ) = flowsUpdatesFilter.expectFlow(bot) { updateToData(it) ?.mapNotNull { data -> 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 7ba44da28f..a308ecf3c0 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 @@ -16,11 +16,11 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.utils.PreviewFeature @PreviewFeature -internal suspend inline fun BehaviourContext.buildMediaGroupTrigger( +internal suspend inline fun BC.buildMediaGroupTrigger( noinline initialFilter: SimpleFilter>>? = null, - noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, - noinline scenarioReceiver: BehaviourContextAndTypeReceiver>> + noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { (it.asSentMediaGroupUpdate() ?.data ?.takeIf { it.all { it is T } } as? List>) ?.let(::listOfNotNull) } @@ -37,11 +37,11 @@ internal suspend inline fun BehaviourContext.bui * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onMediaGroup( +suspend fun BC.onMediaGroup( initialFilter: SimpleFilter>>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver>> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -56,11 +56,11 @@ suspend fun BehaviourContext.onMediaGroup( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onPlaylist( +suspend fun BC.onPlaylist( initialFilter: SimpleFilter>>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver>> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -75,11 +75,11 @@ suspend fun BehaviourContext.onPlaylist( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onDocumentsGroup( +suspend fun BC.onDocumentsGroup( initialFilter: SimpleFilter>>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver>> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -94,11 +94,11 @@ suspend fun BehaviourContext.onDocumentsGroup( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onVisualGallery( +suspend fun BC.onVisualGallery( initialFilter: SimpleFilter>>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver>> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -113,11 +113,11 @@ suspend fun BehaviourContext.onVisualGallery( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onVisualMediaGroup( +suspend fun BC.onVisualMediaGroup( initialFilter: SimpleFilter>>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver>> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> ) = onVisualGallery(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -132,11 +132,11 @@ suspend fun BehaviourContext.onVisualMediaGroup( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onPhotoGallery( +suspend fun BC.onPhotoGallery( initialFilter: SimpleFilter>>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver>> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -151,9 +151,9 @@ suspend fun BehaviourContext.onPhotoGallery( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onVideoGallery( +suspend fun BC.onVideoGallery( initialFilter: SimpleFilter>>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver>> + scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, 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 84f1c177ec..e85c8bfe47 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 @@ -11,11 +11,11 @@ import dev.inmo.tgbotapi.types.message.PassportMessage import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElement import dev.inmo.tgbotapi.types.update.abstracts.Update -internal suspend inline fun BehaviourContext.onPassportMessageWith( +internal suspend inline fun BC.onPassportMessageWith( noinline initialFilter: SimpleFilter? = null, - noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, - noinline scenarioReceiver: BehaviourContextAndTypeReceiver + noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { (it.asMessageUpdate() ?.data ?.asPassportMessage() ?.takeIf { it.passportData.data.any { it is T } }) ?.let(::listOfNotNull) } @@ -33,12 +33,12 @@ internal suspend inline fun BehaviourCont * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onPassportMessage( +suspend fun BC.onPassportMessage( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver -) = onPassportMessageWith( + scenarioReceiver: CustomBehaviourContextAndTypeReceiver +) = onPassportMessageWith( initialFilter, subcontextUpdatesFilter, markerFactory, 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 index c8bfa9d6b3..15ebf39209 100644 --- 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 @@ -10,11 +10,11 @@ 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( +internal suspend inline fun BC.onPollAnswered( noinline initialFilter: SimpleFilter? = null, - noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByIdPollAnswerMarkerFactory, - noinline scenarioReceiver: BehaviourContextAndTypeReceiver + noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { (it.asPollAnswerUpdate() ?.data) ?.let(::listOfNotNull) } @@ -31,11 +31,11 @@ internal suspend inline fun BehaviourContext.onPollAnswered( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onPollAnswer( +suspend fun BC.onPollAnswer( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByIdPollAnswerMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onPollAnswered( initialFilter, subcontextUpdatesFilter, 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 index 570d05d175..92d0d652fa 100644 --- 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 @@ -9,11 +9,11 @@ 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.onPollUpdatedBase( +internal suspend inline fun BC.onPollUpdatedBase( noinline initialFilter: SimpleFilter? = null, - noinline subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByIdPollMarkerFactory, - noinline scenarioReceiver: BehaviourContextAndTypeReceiver + noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { (it.asPollUpdate() ?.data as? T) ?.let(::listOfNotNull) } @@ -30,11 +30,11 @@ internal suspend inline fun BehaviourContext.onPollUpdatedBas * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onPollUpdates( +suspend fun BC.onPollUpdates( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByIdPollMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onPollUpdatedBase( initialFilter, subcontextUpdatesFilter, @@ -54,11 +54,11 @@ suspend fun BehaviourContext.onPollUpdates( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onRegularPollUpdates( +suspend fun BC.onRegularPollUpdates( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByIdPollMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onPollUpdatedBase( initialFilter, subcontextUpdatesFilter, @@ -78,11 +78,11 @@ suspend fun BehaviourContext.onRegularPollUpdates( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onQuizPollUpdates( +suspend fun BC.onQuizPollUpdates( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByIdPollMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onPollUpdatedBase( initialFilter, subcontextUpdatesFilter, 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 index e0a6be1a2f..bcd7b220c5 100644 --- 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 @@ -26,11 +26,11 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onPreCheckoutQuery( +suspend fun BC.onPreCheckoutQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = PreCheckoutQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = PreCheckoutQueryFilterByUser, markerFactory: MarkerFactory = ByUserPreCheckoutQueryMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = 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 index 559be79250..4fcbeab37e 100644 --- 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 @@ -25,11 +25,11 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onShippingQuery( +suspend fun BC.onShippingQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver? = ShippingQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = ShippingQueryFilterByUser, markerFactory: MarkerFactory = ByUserShippingQueryMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver + scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { (it.asShippingQueryUpdate() ?.data) ?.let(::listOfNotNull) } diff --git a/tgbotapi.extensions.utils/README.md b/tgbotapi.extensions.utils/README.md index 3fef81edfe..d611fd6336 100644 --- a/tgbotapi.extensions.utils/README.md +++ b/tgbotapi.extensions.utils/README.md @@ -49,7 +49,7 @@ Dependency config presented here: To use last versions you will need to add one line in repositories block of your `build.gradle`: -`jcenter()` or `mavenCentral()` +`mavenCentral()` And add next line to your dependencies block: diff --git a/tgbotapi.extensions.utils/build.gradle b/tgbotapi.extensions.utils/build.gradle index 07aac2026e..eca97cef94 100644 --- a/tgbotapi.extensions.utils/build.gradle +++ b/tgbotapi.extensions.utils/build.gradle @@ -1,7 +1,6 @@ buildscript { repositories { mavenLocal() - jcenter() mavenCentral() } @@ -23,9 +22,7 @@ apply from: "publish.gradle" repositories { mavenLocal() - jcenter() mavenCentral() - maven { url "https://kotlin.bintray.com/kotlinx" } } kotlin { diff --git a/tgbotapi/build.gradle b/tgbotapi/build.gradle index fda252a629..6efa3efad7 100644 --- a/tgbotapi/build.gradle +++ b/tgbotapi/build.gradle @@ -1,7 +1,6 @@ buildscript { repositories { mavenLocal() - jcenter() mavenCentral() } @@ -23,9 +22,7 @@ apply from: "publish.gradle" repositories { mavenLocal() - jcenter() mavenCentral() - maven { url "https://kotlin.bintray.com/kotlinx" } } kotlin { @@ -43,6 +40,7 @@ kotlin { api project(":tgbotapi.extensions.api") api project(":tgbotapi.extensions.utils") api project(":tgbotapi.extensions.behaviour_builder") + api project(":tgbotapi.extensions.behaviour_builder.fsm") } } }