mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-02 14:49:47 +00:00
packages update
This commit is contained in:
73
tgbotapi.behaviour_builder/README.md
Normal file
73
tgbotapi.behaviour_builder/README.md
Normal file
@@ -0,0 +1,73 @@
|
||||
# TelegramBotAPI Behaviour Builder Extensions
|
||||
|
||||
[](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.behaviour_builder)
|
||||
|
||||
- [TelegramBotAPI Behaviour Builder Extensions](#telegrambotapi-behaviour-builder-extensions)
|
||||
* [What is it?](#what-is-it)
|
||||
* [Triggers](#triggers)
|
||||
* [Waiters](#waiters)
|
||||
|
||||
<small><i><a href='http://ecotrust-canada.github.io/markdown-toc/'>Table of contents generated with markdown-toc</a></i></small>
|
||||
|
||||
## What is it?
|
||||
|
||||
This extension was created to make it more simple to build bot steps handling. Usually, you must use something like:
|
||||
|
||||
```kotlin
|
||||
val bot = telegramBot(TOKEN)
|
||||
bot.startGettingFlowsUpdatesByLongPolling {
|
||||
messagesFlow.subscribeSafelyWithoutExceptions {
|
||||
// ...
|
||||
}
|
||||
// here I already tired to write this example 😫
|
||||
}
|
||||
```
|
||||
|
||||
This library offer other way to do a lot of routine in more simple way:
|
||||
|
||||
```kotlin
|
||||
telegramBotWithBehaviour(token) {
|
||||
onCommand("start".regex) {
|
||||
execute(SendTextMessage(it.chat.id, "This bot can ...")) // replaceable with reply(it, "This bot can ...") when you are using `tgbotapi.extensions.api`
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Triggers
|
||||
|
||||
In terminology of this project the `Triggers` are things which have no initial message, may have own filter for incoming
|
||||
messages and filter messages for context which will be used in subcontext. Full syntax with `onText` as an example:
|
||||
|
||||
```kotlin
|
||||
telegramBotWithBehaviour(TOKEN) {
|
||||
onText(
|
||||
includeFilterByChatInBehaviourSubContext = true, // if false - last lambda will receive all messages instead of filtered by chat messages
|
||||
additionalFilter = { message: CommonMessage<TextContent> ->
|
||||
// here you may check incoming message for any requirements before it will be passed to the main lambda
|
||||
}
|
||||
) { message: CommonMessage<TextContent> -> // this here is `BehaviourContext`
|
||||
// here put your actions and additional waiters
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Waiters
|
||||
|
||||
Waiters targeted to get some content "here and now", they must be used inside some trigger main lambda:
|
||||
|
||||
```kotlin
|
||||
telegramBotWithBehaviour(TOKEN) {
|
||||
onCommand("start") { message: CommonMessage<TextContent> ->
|
||||
val userPhotos = waitPhoto(
|
||||
SendTextMessage(it.chat.id, "Ok, send me some photo, please"), // init request, can be any `Request` object
|
||||
{ update: Update -> // That is update which is NOT passed requirements. In current context we expect some photo, but received something else
|
||||
SendTextMessage(it.chat.id, "Excuse me, but I can accept only photos") // it could be null
|
||||
},
|
||||
2, // some count of photos
|
||||
includeMediaGroups = true, // if false, messages related to some media group will be skipped and recognized as incorrect
|
||||
) { message: CommonMessate<PhotoContent> -> // this method is optional and you can use it in case you want to add some additional requirements checks
|
||||
message.content // return null if message didn't passed requirements
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
49
tgbotapi.behaviour_builder/build.gradle
Normal file
49
tgbotapi.behaviour_builder/build.gradle
Normal file
@@ -0,0 +1,49 @@
|
||||
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.utils")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(8)
|
||||
}
|
||||
}
|
1
tgbotapi.behaviour_builder/mpp_publish_template.kpsb
Normal file
1
tgbotapi.behaviour_builder/mpp_publish_template.kpsb
Normal file
@@ -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 API Steps Extensions","description":"This extensions project contains tools for simple interaction with chats","url":"https://insanusmokrassar.github.io/TelegramBotAPI/tgbotapi.extensions.steps","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/"}]}}
|
69
tgbotapi.behaviour_builder/publish.gradle
Normal file
69
tgbotapi.behaviour_builder/publish.gradle
Normal file
@@ -0,0 +1,69 @@
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'signing'
|
||||
|
||||
task javadocsJar(type: Jar) {
|
||||
classifier = 'javadoc'
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications.all {
|
||||
artifact javadocsJar
|
||||
|
||||
pom {
|
||||
description = "This extensions project contains tools for simple interaction with chats"
|
||||
name = "Telegram Bot API Steps Extensions"
|
||||
url = "https://insanusmokrassar.github.io/TelegramBotAPI/tgbotapi.extensions.steps"
|
||||
|
||||
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
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.ContextSafelyExceptionHandler
|
||||
import dev.inmo.micro_utils.coroutines.ExceptionHandler
|
||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling
|
||||
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling
|
||||
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
|
||||
import dev.inmo.tgbotapi.utils.PreviewFeature
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.plus
|
||||
|
||||
/**
|
||||
* This function is used in [buildBehaviour] extensions to provide default [CoroutineScope] and allow to avoid all
|
||||
* unnecessary parameters except of block
|
||||
*/
|
||||
expect var defaultCoroutineScopeProvider: () -> CoroutineScope
|
||||
|
||||
/**
|
||||
* Use this method in case you wish to make some additional actions with [flowUpdatesFilter].
|
||||
*
|
||||
* **WARNING** This method WILL NOT launch any listening of updates. Use something like
|
||||
* [startGettingOfUpdatesByLongPolling] or tools for work with webhooks
|
||||
*
|
||||
* @see [BehaviourContext]
|
||||
* @see startGettingOfUpdatesByLongPolling
|
||||
*/
|
||||
@PreviewFeature
|
||||
suspend fun TelegramBot.buildBehaviour(
|
||||
flowUpdatesFilter: FlowsUpdatesFilter,
|
||||
scope: CoroutineScope = defaultCoroutineScopeProvider(),
|
||||
defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
|
||||
block: BehaviourContextReceiver<Unit>
|
||||
) {
|
||||
BehaviourContext(
|
||||
this,
|
||||
scope.let {
|
||||
if (defaultExceptionsHandler == null) {
|
||||
it
|
||||
} else {
|
||||
it + ContextSafelyExceptionHandler(defaultExceptionsHandler)
|
||||
}
|
||||
},
|
||||
flowUpdatesFilter
|
||||
).block()
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to build bot behaviour and run it via long polling. In case you wish to get [FlowsUpdatesFilter] for
|
||||
* additional manipulations, you must provide external [FlowsUpdatesFilter] in other [buildBehaviour] function.
|
||||
*
|
||||
* @see buildBehaviour
|
||||
* @see BehaviourContext
|
||||
* @see startGettingOfUpdatesByLongPolling
|
||||
*/
|
||||
@PreviewFeature
|
||||
suspend fun TelegramBot.buildBehaviour(
|
||||
scope: CoroutineScope = defaultCoroutineScopeProvider(),
|
||||
defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
|
||||
block: BehaviourContextReceiver<Unit>
|
||||
) = FlowsUpdatesFilter().let {
|
||||
buildBehaviour(
|
||||
it,
|
||||
scope,
|
||||
defaultExceptionsHandler,
|
||||
block
|
||||
)
|
||||
longPolling(
|
||||
it,
|
||||
scope = scope
|
||||
)
|
||||
}
|
@@ -0,0 +1,176 @@
|
||||
@file:Suppress("NOTHING_TO_INLINE")
|
||||
|
||||
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.*
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.BufferOverflow
|
||||
import kotlinx.coroutines.flow.*
|
||||
|
||||
typealias CustomBehaviourContextReceiver<BC, T> = suspend BC.() -> T
|
||||
typealias BehaviourContextReceiver<T> = CustomBehaviourContextReceiver<BehaviourContext, T>
|
||||
typealias CustomBehaviourContextAndTypeReceiver<BC, T, I> = suspend BC.(I) -> T
|
||||
typealias BehaviourContextAndTypeReceiver<T, I> = CustomBehaviourContextAndTypeReceiver<BehaviourContext, T, I>
|
||||
typealias CustomBehaviourContextAndTwoTypesReceiver<BC, T, I1, I2> = suspend BC.(I1, I2) -> T
|
||||
typealias BehaviourContextAndTwoTypesReceiver<T, I1, I2> = CustomBehaviourContextAndTwoTypesReceiver<BehaviourContext, T, I1, I2>
|
||||
inline fun <T> BehaviourContextReceiver(noinline block: BehaviourContextReceiver<T>) = block
|
||||
inline fun <BC, T> CustomBehaviourContextReceiver(noinline block: CustomBehaviourContextReceiver<BC, T>) = block
|
||||
inline fun <T, I> BehaviourContextAndTypeReceiver(noinline block: BehaviourContextAndTypeReceiver<T, I>) = block
|
||||
inline fun <T, I1, I2> BehaviourContextAndTwoTypesReceiver(noinline block: BehaviourContextAndTwoTypesReceiver<T, I1, I2>) = block
|
||||
internal inline fun <BC, T, I1, I2> CustomBehaviourContextAndTwoTypesReceiver<BC, T, I1, I2>.toOneType(
|
||||
i1: I1,
|
||||
): CustomBehaviourContextAndTypeReceiver<BC, T, I2> = { invoke(this, i1, it) }
|
||||
|
||||
/**
|
||||
* This class contains all necessary tools for work with bots and especially for [buildBehaviour]
|
||||
*
|
||||
* @see DefaultBehaviourContext
|
||||
*/
|
||||
interface BehaviourContext : FlowsUpdatesFilter, TelegramBot, CoroutineScope {
|
||||
val bot: TelegramBot
|
||||
get() = this
|
||||
|
||||
/**
|
||||
* Will be used for creating of some subscriptions inside of methods, updates listening and different other things
|
||||
* in context of working with [CoroutineScope] and coroutines.
|
||||
*/
|
||||
val scope: CoroutineScope
|
||||
get() = this
|
||||
|
||||
/**
|
||||
* This parameter will be used to subscribe on different types of update
|
||||
*/
|
||||
val flowsUpdatesFilter: FlowsUpdatesFilter
|
||||
get() = this
|
||||
|
||||
fun copy(
|
||||
bot: TelegramBot = this.bot,
|
||||
scope: CoroutineScope = this.scope,
|
||||
broadcastChannelsSize: Int = 100,
|
||||
onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND,
|
||||
upstreamUpdatesFlow: Flow<Update>? = null,
|
||||
updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>? = 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,
|
||||
broadcastChannelsSize: Int = 100,
|
||||
onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND,
|
||||
private val upstreamUpdatesFlow: Flow<Update>? = null,
|
||||
private val updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>? = null
|
||||
) : AbstractFlowsUpdatesFilter(), TelegramBot by bot, CoroutineScope by scope, BehaviourContext {
|
||||
|
||||
private val additionalUpdatesSharedFlow = MutableSharedFlow<Update>(0, broadcastChannelsSize, onBufferOverflow)
|
||||
override val allUpdatesFlow: Flow<Update> = (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<Update> = additionalUpdatesSharedFlow::emit
|
||||
|
||||
override fun copy(
|
||||
bot: TelegramBot,
|
||||
scope: CoroutineScope,
|
||||
broadcastChannelsSize: Int,
|
||||
onBufferOverflow: BufferOverflow,
|
||||
upstreamUpdatesFlow: Flow<Update>?,
|
||||
updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>?
|
||||
): BehaviourContext = DefaultBehaviourContext(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, updatesFilter)
|
||||
}
|
||||
|
||||
fun BehaviourContext(
|
||||
bot: TelegramBot,
|
||||
scope: CoroutineScope,
|
||||
flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter()
|
||||
) = DefaultBehaviourContext(bot, scope, upstreamUpdatesFlow = flowsUpdatesFilter.allUpdatesFlow)
|
||||
|
||||
inline fun <T> 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
|
||||
* [CoroutineScope] as new [BehaviourContext.scope]. You must do all subscription/running of longPolling manually.
|
||||
*
|
||||
* @param newFlowsUpdatesFilterSetUp As a parameter receives [FlowsUpdatesFilter] from old [this] [BehaviourContext.flowsUpdatesFilter]
|
||||
*/
|
||||
@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.")
|
||||
@Deprecated("This method is useless and will not be used in future")
|
||||
suspend fun <T, BC : BehaviourContext> BC.doInSubContextWithFlowsUpdatesFilterSetup(
|
||||
newFlowsUpdatesFilterSetUp: CustomBehaviourContextAndTypeReceiver<BC, Unit, FlowsUpdatesFilter>?,
|
||||
stopOnCompletion: Boolean = true,
|
||||
behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>
|
||||
): T = (copy(
|
||||
scope = LinkedSupervisorScope(),
|
||||
) as BC).run {
|
||||
withContext(coroutineContext) {
|
||||
newFlowsUpdatesFilterSetUp ?.let {
|
||||
it.apply { invoke(this@run, this@doInSubContextWithFlowsUpdatesFilterSetup.flowsUpdatesFilter) }
|
||||
}
|
||||
behaviourContextReceiver().also { if (stopOnCompletion) stop() }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new one [BehaviourContext], adding subsequent [FlowsUpdatesFilter] in case [updatesFilter] is provided and
|
||||
* [CoroutineScope] as new [BehaviourContext.scope]
|
||||
*/
|
||||
suspend fun <T, BC : BehaviourContext> BC.doInSubContextWithUpdatesFilter(
|
||||
updatesFilter: CustomBehaviourContextAndTypeReceiver<BC, Boolean, Update>?,
|
||||
stopOnCompletion: Boolean = true,
|
||||
updatesUpstreamFlow: Flow<Update> = allUpdatesFlow,
|
||||
scope: CoroutineScope = LinkedSupervisorScope(),
|
||||
behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>
|
||||
): T = copy(
|
||||
scope = scope,
|
||||
updatesFilter = updatesFilter ?.let { _ ->
|
||||
{
|
||||
(this as? BC) ?.run {
|
||||
updatesFilter(it)
|
||||
} ?: true
|
||||
}
|
||||
},
|
||||
upstreamUpdatesFlow = updatesUpstreamFlow
|
||||
).run {
|
||||
withContext(coroutineContext) {
|
||||
behaviourContextReceiver().also { if (stopOnCompletion) stop() }
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun <T> BehaviourContext.doInSubContext(
|
||||
stopOnCompletion: Boolean = true,
|
||||
updatesUpstreamFlow: Flow<Update> = allUpdatesFlow,
|
||||
scope: CoroutineScope = LinkedSupervisorScope(),
|
||||
behaviourContextReceiver: BehaviourContextReceiver<T>
|
||||
) = doInSubContextWithUpdatesFilter(updatesFilter = null, stopOnCompletion, updatesUpstreamFlow, scope, behaviourContextReceiver)
|
||||
|
||||
/**
|
||||
* This method will cancel ALL subsequent contexts, expectations and waiters
|
||||
*/
|
||||
fun BehaviourContext.stop() = scope.cancel()
|
@@ -0,0 +1,80 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.ExceptionHandler
|
||||
import dev.inmo.tgbotapi.bot.Ktor.KtorRequestsExecutorBuilder
|
||||
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
|
||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling
|
||||
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
|
||||
import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl
|
||||
import kotlinx.coroutines.*
|
||||
import kotlin.coroutines.coroutineContext
|
||||
|
||||
/**
|
||||
* Create bot using [telegramBot] and start listening for updates using [buildBehaviour].
|
||||
* Use this method in case you wish to make some additional actions with [flowsUpdatesFilter].
|
||||
*
|
||||
* **WARNING** This method WILL NOT launch any listening of updates. Use something like
|
||||
* [startGettingOfUpdatesByLongPolling] or tools for work with webhooks
|
||||
*
|
||||
* @return Created bot which has been used to create [BehaviourContext] via [buildBehaviour]
|
||||
*
|
||||
* @see [BehaviourContext]
|
||||
* @see [buildBehaviour]
|
||||
* @see startGettingOfUpdatesByLongPolling
|
||||
*/
|
||||
suspend fun telegramBotWithBehaviour(
|
||||
token: String,
|
||||
flowsUpdatesFilter: FlowsUpdatesFilter,
|
||||
scope: CoroutineScope? = null,
|
||||
apiUrl: String = telegramBotAPIDefaultUrl,
|
||||
builder: KtorRequestsExecutorBuilder.() -> Unit = {},
|
||||
defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
|
||||
block: BehaviourContextReceiver<Unit>
|
||||
): TelegramBot = telegramBot(
|
||||
token,
|
||||
apiUrl,
|
||||
builder
|
||||
).apply {
|
||||
buildBehaviour(
|
||||
flowsUpdatesFilter,
|
||||
scope ?: CoroutineScope(coroutineContext),
|
||||
defaultExceptionsHandler,
|
||||
block
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create bot using [telegramBot] and start listening for updates using [buildBehaviour].
|
||||
* Use this method in case you wish to make some additional actions with [flowsUpdatesFilter].
|
||||
*
|
||||
* **WARNING** This method WILL NOT launch any listening of updates. Use something like
|
||||
* [startGettingOfUpdatesByLongPolling] or tools for work with webhooks
|
||||
*
|
||||
* @return Pair of [TelegramBot] and [Job]. This [Job] can be used to stop listening updates in your [block] you passed
|
||||
* here
|
||||
*
|
||||
* @see [BehaviourContext]
|
||||
* @see [buildBehaviour]
|
||||
* @see startGettingOfUpdatesByLongPolling
|
||||
*/
|
||||
suspend fun telegramBotWithBehaviour(
|
||||
token: String,
|
||||
scope: CoroutineScope? = null,
|
||||
apiUrl: String = telegramBotAPIDefaultUrl,
|
||||
builder: KtorRequestsExecutorBuilder.() -> Unit = {},
|
||||
defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
|
||||
block: BehaviourContextReceiver<Unit>
|
||||
): Pair<TelegramBot, Job> {
|
||||
return telegramBot(
|
||||
token,
|
||||
apiUrl,
|
||||
builder
|
||||
).let {
|
||||
it to it.buildBehaviour(
|
||||
scope ?: CoroutineScope(coroutineContext),
|
||||
defaultExceptionsHandler,
|
||||
block
|
||||
)
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.DeferredAction
|
||||
import dev.inmo.micro_utils.coroutines.invokeFirstOf
|
||||
import kotlinx.coroutines.Deferred
|
||||
import kotlinx.coroutines.async
|
||||
|
||||
suspend fun <T> BehaviourContext.parallel(
|
||||
action: BehaviourContextReceiver<T>
|
||||
) = async {
|
||||
action()
|
||||
}
|
||||
|
||||
inline infix fun <T, O> Deferred<T>.withAction(noinline callback: suspend (T) -> O) = DeferredAction(this, callback)
|
||||
|
||||
inline fun <T> Deferred<T>.asAction() = DeferredAction(this) { it }
|
||||
|
||||
suspend fun <O> BehaviourContext.oneOfActions(
|
||||
deferredActions: Iterable<DeferredAction<*, O>>
|
||||
) = deferredActions.invokeFirstOf(scope)
|
||||
|
||||
suspend fun <O> BehaviourContext.oneOfActions(
|
||||
vararg deferredActions: DeferredAction<*, O>
|
||||
) = this@oneOfActions.oneOfActions(deferredActions.toList())
|
||||
|
||||
suspend fun <O> BehaviourContext.oneOf(
|
||||
deferredActions: Iterable<Deferred<O>>
|
||||
) = oneOfActions(deferredActions.map { it.asAction() })
|
||||
|
||||
suspend fun <O> BehaviourContext.oneOf(
|
||||
vararg deferredActions: Deferred<O>
|
||||
) = oneOf(deferredActions.toList())
|
@@ -0,0 +1,126 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
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
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.flow.*
|
||||
|
||||
private val cancelledByFilterException = CancellationException("Cancelled by filter precreatedException")
|
||||
|
||||
typealias RequestBuilder<T> = suspend (Update) -> Request<T>
|
||||
typealias NullableRequestBuilder<T> = suspend (Update) -> Request<T>?
|
||||
|
||||
/**
|
||||
* @param initRequest If not null, this request will be sent by [bot] before returning value
|
||||
* @param count If set, result [Flow] will return [count] elements on each [Flow.collect]
|
||||
* @param errorFactory If set, this factory will be used to produce requests in case when user have sent incorrect data
|
||||
* @param cancelRequestFactory If set, this factory will be used to produce requests in case when it is required to say
|
||||
* user that chain of scenario has been cancelled
|
||||
* @param cancelTrigger When this trigger returns true, chain is cancelled
|
||||
* @param filter It is main param, which will be called on each update. When it return not null, result will be returned
|
||||
* as is, but when it returns null, then will be called [cancelTrigger] (if it will return true - [cancelRequestFactory]
|
||||
* will be called too), [errorFactory] and then will be returned null
|
||||
*/
|
||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||
suspend fun <T> FlowsUpdatesFilter.expectFlow(
|
||||
bot: TelegramBot,
|
||||
initRequest: Request<*>? = null,
|
||||
count: Int? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
cancelRequestFactory: NullableRequestBuilder<*> = { null },
|
||||
cancelTrigger: suspend (Update) -> Boolean = { cancelRequestFactory(it) != null },
|
||||
filter: suspend (Update) -> List<T>
|
||||
): Flow<T> {
|
||||
val flow = allUpdatesFlow.map {
|
||||
val result = safelyWithResult { filter(it) }
|
||||
if (result.isFailure || result.getOrThrow().isEmpty()) {
|
||||
if (cancelTrigger(it)) {
|
||||
cancelRequestFactory(it) ?.also {
|
||||
safelyWithResult { bot.execute(it) }
|
||||
throw cancelledByFilterException
|
||||
}
|
||||
}
|
||||
errorFactory(it) ?.also { errorRequest ->
|
||||
safelyWithoutExceptions { bot.execute(errorRequest) }
|
||||
}
|
||||
emptyList()
|
||||
} else {
|
||||
result.getOrThrow()
|
||||
}
|
||||
}.flatMap()
|
||||
val result = if (count == null) {
|
||||
flow
|
||||
} else {
|
||||
flow.take(count)
|
||||
}
|
||||
initRequest ?.also { safelyWithoutExceptions { bot.execute(initRequest) } }
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* @param initRequest If not null, this request will be sent by [bot] before returning value
|
||||
* @param count If set, result [Flow] will return [count] elements on each [Flow.collect]
|
||||
* @param errorFactory If set, this factory will be used to produce requests in case when user have sent incorrect data
|
||||
* @param cancelRequestFactory If set, this factory will be used to produce requests in case when it is required to say
|
||||
* user that chain of scenario has been cancelled
|
||||
* @param cancelTrigger When this trigger returns true, chain is cancelled
|
||||
* @param filter It is main param, which will be called on each update. When it return not null, result will be returned
|
||||
* as is, but when it returns null, then will be called [cancelTrigger] (if it will return true - [cancelRequestFactory]
|
||||
* will be called too), [errorFactory] and then will be returned null
|
||||
*/
|
||||
suspend fun <T> BehaviourContext.expectFlow(
|
||||
initRequest: Request<*>? = null,
|
||||
count: Int? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
cancelRequestFactory: NullableRequestBuilder<*> = { null },
|
||||
cancelTrigger: suspend (Update) -> Boolean = { cancelRequestFactory(it) != null },
|
||||
filter: suspend (Update) -> List<T>
|
||||
) = flowsUpdatesFilter.expectFlow(bot, initRequest, count, errorFactory, cancelRequestFactory, cancelTrigger, filter)
|
||||
|
||||
/**
|
||||
* @param initRequest If not null, this request will be sent by [bot] before returning value
|
||||
* @param errorFactory If set, this factory will be used to produce requests in case when user have sent incorrect data
|
||||
* @param cancelRequestFactory If set, this factory will be used to produce requests in case when it is required to say
|
||||
* user that chain of scenario has been cancelled
|
||||
* @param cancelTrigger When this trigger returns true, chain is cancelled
|
||||
* @param filter It is main param, which will be called on each update. When it return not null, result will be returned
|
||||
* as is, but when it returns null, then will be called [cancelTrigger] (if it will return true - [cancelRequestFactory]
|
||||
* will be called too), [errorFactory] and then will be returned null
|
||||
*/
|
||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||
suspend fun <T> FlowsUpdatesFilter.expectOne(
|
||||
bot: TelegramBot,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
cancelRequestFactory: NullableRequestBuilder<*> = { null },
|
||||
cancelTrigger: suspend (Update) -> Boolean = { cancelRequestFactory(it) != null },
|
||||
filter: suspend (Update) -> T?
|
||||
): T = expectFlow(bot, initRequest, 1, errorFactory, cancelRequestFactory, cancelTrigger) {
|
||||
listOfNotNull(filter.invoke(it))
|
||||
}.first()
|
||||
|
||||
/**
|
||||
* @param initRequest If not null, this request will be sent by [bot] before returning value
|
||||
* @param errorFactory If set, this factory will be used to produce requests in case when user have sent incorrect data
|
||||
* @param cancelRequestFactory If set, this factory will be used to produce requests in case when it is required to say
|
||||
* user that chain of scenario has been cancelled
|
||||
* @param cancelTrigger When this trigger returns true, chain is cancelled
|
||||
* @param filter It is main param, which will be called on each update. When it return not null, result will be returned
|
||||
* as is, but when it returns null, then will be called [cancelTrigger] (if it will return true - [cancelRequestFactory]
|
||||
* will be called too), [errorFactory] and then will be returned null
|
||||
*/
|
||||
suspend fun <T> BehaviourContext.expectOne(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
cancelRequestFactory: NullableRequestBuilder<*> = { null },
|
||||
cancelTrigger: suspend (Update) -> Boolean = { cancelRequestFactory(it) != null },
|
||||
filter: suspend (Update) -> T?
|
||||
) = flowsUpdatesFilter.expectOne(bot, initRequest, errorFactory, cancelRequestFactory, cancelTrigger, filter)
|
@@ -0,0 +1,124 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asCallbackQueryUpdate
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.CallbackQuery.*
|
||||
import kotlinx.coroutines.flow.toList
|
||||
|
||||
typealias CallbackQueryMapper<T> = suspend T.() -> T?
|
||||
|
||||
private suspend fun <O> BehaviourContext.waitCallbackQueries(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: SimpleFilter<CallbackQuery>? = null,
|
||||
mapper: suspend CallbackQuery.() -> O?
|
||||
): List<O> = expectFlow(
|
||||
initRequest,
|
||||
count,
|
||||
errorFactory
|
||||
) {
|
||||
val data = it.asCallbackQueryUpdate() ?.data
|
||||
if (data != null && (filter == null || filter(data))) {
|
||||
data.mapper().let(::listOfNotNull)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}.toList().toList()
|
||||
|
||||
|
||||
private suspend inline fun <reified T : CallbackQuery> BehaviourContext.waitCallbacks(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||
noinline filter: SimpleFilter<T>? = null,
|
||||
noinline mapper: CallbackQueryMapper<T>? = null
|
||||
) : List<T> = waitCallbackQueries<T>(
|
||||
count,
|
||||
initRequest,
|
||||
errorFactory,
|
||||
filter ?.let {
|
||||
{
|
||||
(it as? T) ?.let { filter(it) } == true
|
||||
}
|
||||
}
|
||||
) {
|
||||
if (this is T) {
|
||||
if (mapper == null) {
|
||||
this
|
||||
} else {
|
||||
mapper(this)
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
suspend fun BehaviourContext.waitDataCallbackQuery(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<DataCallbackQuery>? = null,
|
||||
mapper: CallbackQueryMapper<DataCallbackQuery>? = null
|
||||
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitGameShortNameCallbackQuery(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<GameShortNameCallbackQuery>? = null,
|
||||
mapper: CallbackQueryMapper<GameShortNameCallbackQuery>? = null
|
||||
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitInlineMessageIdCallbackQuery(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<InlineMessageIdCallbackQuery>? = null,
|
||||
mapper: CallbackQueryMapper<InlineMessageIdCallbackQuery>? = null
|
||||
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitInlineMessageIdDataCallbackQuery(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<InlineMessageIdDataCallbackQuery>? = null,
|
||||
mapper: CallbackQueryMapper<InlineMessageIdDataCallbackQuery>? = null
|
||||
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitInlineMessageIdGameShortNameCallbackQuery(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<InlineMessageIdGameShortNameCallbackQuery>? = null,
|
||||
mapper: CallbackQueryMapper<InlineMessageIdGameShortNameCallbackQuery>? = null
|
||||
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitMessageCallbackQuery(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<MessageCallbackQuery>? = null,
|
||||
mapper: CallbackQueryMapper<MessageCallbackQuery>? = null
|
||||
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitMessageDataCallbackQuery(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<MessageDataCallbackQuery>? = null,
|
||||
mapper: CallbackQueryMapper<MessageDataCallbackQuery>? = null
|
||||
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitMessageGameShortNameCallbackQuery(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<MessageGameShortNameCallbackQuery>? = null,
|
||||
mapper: CallbackQueryMapper<MessageGameShortNameCallbackQuery>? = null
|
||||
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitUnknownCallbackQuery(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<UnknownCallbackQueryType>? = null,
|
||||
mapper: CallbackQueryMapper<UnknownCallbackQueryType>? = null
|
||||
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)
|
@@ -0,0 +1,74 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.ChatMemberUpdated
|
||||
import dev.inmo.tgbotapi.types.update.CommonChatMemberUpdatedUpdate
|
||||
import dev.inmo.tgbotapi.types.update.MyChatMemberUpdatedUpdate
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate
|
||||
import kotlinx.coroutines.flow.toList
|
||||
|
||||
typealias ChatMemberUpdatedMapper<T> = suspend T.() -> T?
|
||||
|
||||
private suspend inline fun <reified T : ChatMemberUpdatedUpdate> BehaviourContext.waitChatMemberUpdated(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||
noinline filter: SimpleFilter<T>? = null,
|
||||
noinline mapper: ChatMemberUpdatedMapper<ChatMemberUpdated>
|
||||
): List<ChatMemberUpdated> = expectFlow(
|
||||
initRequest,
|
||||
count,
|
||||
errorFactory
|
||||
) {
|
||||
val casted = (it as? T) ?: return@expectFlow emptyList()
|
||||
if (filter == null || filter(casted)) {
|
||||
casted.data.mapper().let(::listOfNotNull)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}.toList().toList()
|
||||
|
||||
private suspend inline fun <reified T : ChatMemberUpdatedUpdate> BehaviourContext.waitChatMemberUpdatedWithFilter(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||
noinline filter: SimpleFilter<T>? = null,
|
||||
noinline mapper: ChatMemberUpdatedMapper<ChatMemberUpdated>? = null
|
||||
) : List<ChatMemberUpdated> = waitChatMemberUpdated<T>(
|
||||
count,
|
||||
initRequest,
|
||||
errorFactory,
|
||||
filter,
|
||||
) {
|
||||
if (mapper == null) {
|
||||
this
|
||||
} else {
|
||||
mapper(this)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun BehaviourContext.waitChatMemberUpdated(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatMemberUpdatedUpdate>? = null,
|
||||
mapper: ChatMemberUpdatedMapper<ChatMemberUpdated>? = null
|
||||
) = waitChatMemberUpdatedWithFilter<ChatMemberUpdatedUpdate>(count, initRequest, errorFactory, filter, mapper)
|
||||
|
||||
suspend fun BehaviourContext.waitCommonChatMemberUpdated(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonChatMemberUpdatedUpdate>? = null,
|
||||
mapper: ChatMemberUpdatedMapper<ChatMemberUpdated>? = null
|
||||
) = waitChatMemberUpdatedWithFilter<CommonChatMemberUpdatedUpdate>(count, initRequest, errorFactory, filter, mapper)
|
||||
|
||||
suspend fun BehaviourContext.waitMyChatMemberUpdated(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<MyChatMemberUpdatedUpdate>? = null,
|
||||
mapper: ChatMemberUpdatedMapper<ChatMemberUpdated>? = null
|
||||
) = waitChatMemberUpdatedWithFilter<MyChatMemberUpdatedUpdate>(count, initRequest, errorFactory, filter, mapper)
|
@@ -0,0 +1,82 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.*
|
||||
import dev.inmo.tgbotapi.types.polls.*
|
||||
import kotlinx.coroutines.flow.toList
|
||||
|
||||
typealias ChosenInlineResultMapper<T> = suspend T.() -> T?
|
||||
|
||||
private suspend fun <O> BehaviourContext.waitChosenInlineResultsUpdates(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: SimpleFilter<ChosenInlineResult>? = null,
|
||||
mapper: suspend ChosenInlineResult.() -> O?
|
||||
): List<O> = expectFlow(
|
||||
initRequest,
|
||||
count,
|
||||
errorFactory
|
||||
) {
|
||||
val data = it.asChosenInlineResultUpdate() ?.data
|
||||
if (data != null && (filter == null || filter(data))) {
|
||||
data.mapper().let(::listOfNotNull)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}.toList().toList()
|
||||
|
||||
|
||||
private suspend inline fun <reified T : ChosenInlineResult> BehaviourContext.waitChosenInlineResults(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||
noinline filter: SimpleFilter<T>? = null,
|
||||
noinline mapper: ChosenInlineResultMapper<T>? = null
|
||||
) : List<T> = this@waitChosenInlineResults.waitChosenInlineResultsUpdates<T>(
|
||||
count,
|
||||
initRequest,
|
||||
errorFactory,
|
||||
filter ?.let {
|
||||
{
|
||||
(it as? T) ?.let { filter(it) } == true
|
||||
}
|
||||
}
|
||||
) {
|
||||
if (this is T) {
|
||||
if (mapper == null) {
|
||||
this
|
||||
} else {
|
||||
mapper(this)
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun BehaviourContext.waitChosenInlineResult(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChosenInlineResult>? = null,
|
||||
mapper: ChosenInlineResultMapper<ChosenInlineResult>? = null
|
||||
) = waitChosenInlineResults(count, initRequest, errorFactory, filter, mapper)
|
||||
|
||||
suspend fun BehaviourContext.waitLocationChosenInlineResult(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<LocationChosenInlineResult>? = null,
|
||||
mapper: PollMapper<LocationChosenInlineResult>? = null
|
||||
) = waitChosenInlineResults(count, initRequest, errorFactory, filter, mapper)
|
||||
|
||||
suspend fun BehaviourContext.waitBaseChosenInlineResult(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<BaseChosenInlineResult>? = null,
|
||||
mapper: PollMapper<BaseChosenInlineResult>? = null
|
||||
) = waitChosenInlineResults(count, initRequest, errorFactory, filter, mapper)
|
@@ -0,0 +1,267 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.*
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.*
|
||||
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
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
typealias CommonMessageToContentMapper<T> = suspend CommonMessage<T>.() -> T?
|
||||
|
||||
private suspend fun <O> BehaviourContext.waitCommonMessage(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
includeMediaGroups: Boolean = true,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: SimpleFilter<CommonMessage<MessageContent>>? = null,
|
||||
mapper: suspend CommonMessage<MessageContent>.() -> O?
|
||||
): Flow<O> = expectFlow(
|
||||
initRequest,
|
||||
count,
|
||||
errorFactory
|
||||
) {
|
||||
val messages = when (it) {
|
||||
is SentMediaGroupUpdate -> {
|
||||
if (includeMediaGroups) {
|
||||
it.data.map { it as CommonMessage<MessageContent> }
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
is BaseSentMessageUpdate -> listOf(it.data)
|
||||
else -> return@expectFlow emptyList()
|
||||
}
|
||||
messages.mapNotNull { message ->
|
||||
val asCommonMessage = message as CommonMessage<MessageContent>
|
||||
if (filter == null || filter(asCommonMessage)) {
|
||||
asCommonMessage.mapper()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal inline fun <reified T : MessageContent> contentConverter(
|
||||
noinline mapper: CommonMessageToContentMapper<T>? = null
|
||||
): suspend CommonMessage<MessageContent>.() -> T? = mapper ?.let {
|
||||
{
|
||||
if (content is T) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val message = (this as CommonMessage<T>)
|
||||
safelyWithoutExceptions { mapper(message) }
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
} ?: { content as? T }
|
||||
|
||||
private suspend inline fun <reified T : MessageContent> BehaviourContext.waitContent(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
includeMediaGroups: Boolean = true,
|
||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||
noinline filter: SimpleFilter<CommonMessage<T>>? = null,
|
||||
noinline mapper: CommonMessageToContentMapper<T>? = null
|
||||
) : List<T> = waitCommonMessage<T>(
|
||||
count,
|
||||
initRequest,
|
||||
includeMediaGroups,
|
||||
errorFactory,
|
||||
filter ?.let {
|
||||
{
|
||||
it.withContent<T>() ?.let { filter(it) } == true
|
||||
}
|
||||
},
|
||||
contentConverter(mapper)
|
||||
).toList()
|
||||
|
||||
suspend fun BehaviourContext.waitContentMessage(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = true,
|
||||
filter: SimpleFilter<CommonMessage<MessageContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<MessageContent>? = null
|
||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitContact(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<ContactContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<ContactContent>? = null
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitDice(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<DiceContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<DiceContent>? = null
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitGame(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<GameContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<GameContent>? = null
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitLocation(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<LocationContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<LocationContent>? = null
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitLiveLocation(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<LiveLocationContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<LiveLocationContent>? = null
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitStaticLocation(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<StaticLocationContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<StaticLocationContent>? = null
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitPoll(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<PollContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<PollContent>? = null
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitText(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<TextContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<TextContent>? = null
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitVenue(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<VenueContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<VenueContent>? = null
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitAudioMediaGroupContent(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = true,
|
||||
filter: SimpleFilter<CommonMessage<AudioMediaGroupContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<AudioMediaGroupContent>? = null
|
||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitDocumentMediaGroupContent(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = true,
|
||||
filter: SimpleFilter<CommonMessage<DocumentMediaGroupContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<DocumentMediaGroupContent>? = null
|
||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitMedia(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = false,
|
||||
filter: SimpleFilter<CommonMessage<MediaContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<MediaContent>? = null
|
||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitAnyMediaGroupContent(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = true,
|
||||
filter: SimpleFilter<CommonMessage<MediaGroupContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<MediaGroupContent>? = null
|
||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitVisualMediaGroupContent(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = true,
|
||||
filter: SimpleFilter<CommonMessage<VisualMediaGroupContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<VisualMediaGroupContent>? = null
|
||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitAnimation(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<AnimationContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<AnimationContent>? = null
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitAudio(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = false,
|
||||
filter: SimpleFilter<CommonMessage<AudioContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<AudioContent>? = null
|
||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitDocument(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = false,
|
||||
filter: SimpleFilter<CommonMessage<DocumentContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<DocumentContent>? = null
|
||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitPhoto(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = false,
|
||||
filter: SimpleFilter<CommonMessage<PhotoContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<PhotoContent>? = null
|
||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitSticker(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<StickerContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<StickerContent>? = null
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitVideo(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = false,
|
||||
filter: SimpleFilter<CommonMessage<VideoContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<VideoContent>? = null
|
||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitVideoNote(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<VideoNoteContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<VideoNoteContent>? = null
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitVoice(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<VoiceContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<VoiceContent>? = null
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitInvoice(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<InvoiceContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<InvoiceContent>? = null
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
|
@@ -0,0 +1,250 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asCommonMessage
|
||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.*
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.content.media.*
|
||||
import dev.inmo.tgbotapi.types.message.payments.InvoiceContent
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseEditMessageUpdate
|
||||
import kotlinx.coroutines.flow.toList
|
||||
|
||||
private suspend fun <O> BehaviourContext.waitEditedCommonMessage(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
includeMediaGroups: Boolean = true,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: SimpleFilter<CommonMessage<MessageContent>>? = null,
|
||||
mapper: suspend CommonMessage<MessageContent>.() -> O?
|
||||
): List<O> = expectFlow(
|
||||
initRequest,
|
||||
count,
|
||||
errorFactory
|
||||
) {
|
||||
val messages = when (it) {
|
||||
is BaseEditMessageUpdate -> {
|
||||
val commonMessage = it.data.asCommonMessage()
|
||||
if (commonMessage !is MediaGroupMessage<*> || includeMediaGroups) {
|
||||
listOf(commonMessage)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
else -> return@expectFlow emptyList()
|
||||
}
|
||||
messages.mapNotNull { message ->
|
||||
val asCommonMessage = message as CommonMessage<MessageContent>
|
||||
if (filter == null || filter(asCommonMessage)) {
|
||||
asCommonMessage.mapper()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}.toList().toList()
|
||||
|
||||
private suspend inline fun <reified T : MessageContent> BehaviourContext.waitEditedContent(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
includeMediaGroups: Boolean = true,
|
||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||
noinline filter: SimpleFilter<CommonMessage<T>>? = null,
|
||||
noinline mapper: CommonMessageToContentMapper<T>? = null
|
||||
) : List<T> = waitEditedCommonMessage<T>(
|
||||
count,
|
||||
initRequest,
|
||||
includeMediaGroups,
|
||||
errorFactory,
|
||||
filter ?.let {
|
||||
{
|
||||
it.withContent<T>() ?.let { filter(it) } == true
|
||||
}
|
||||
},
|
||||
contentConverter(mapper)
|
||||
)
|
||||
|
||||
suspend fun BehaviourContext.waitEditedContentMessage(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = true,
|
||||
filter: SimpleFilter<CommonMessage<MessageContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<MessageContent>? = null
|
||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedContact(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<ContactContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<ContactContent>? = null
|
||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedDice(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<DiceContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<DiceContent>? = null
|
||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedGame(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<GameContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<GameContent>? = null
|
||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedLocation(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<LocationContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<LocationContent>? = null
|
||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedLiveLocation(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<LiveLocationContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<LiveLocationContent>? = null
|
||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedStaticLocation(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<StaticLocationContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<StaticLocationContent>? = null
|
||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
@Deprecated("Potentially, this trigger will never be used. Use `waitPollUpdates` instead")
|
||||
suspend fun BehaviourContext.waitEditedPoll(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<PollContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<PollContent>? = null
|
||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedText(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<TextContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<TextContent>? = null
|
||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedVenue(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<VenueContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<VenueContent>? = null
|
||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedAudioMediaGroupContent(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = true,
|
||||
filter: SimpleFilter<CommonMessage<AudioMediaGroupContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<AudioMediaGroupContent>? = null
|
||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedDocumentMediaGroupContent(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = true,
|
||||
filter: SimpleFilter<CommonMessage<DocumentMediaGroupContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<DocumentMediaGroupContent>? = null
|
||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedMedia(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = false,
|
||||
filter: SimpleFilter<CommonMessage<MediaContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<MediaContent>? = null
|
||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedAnyMediaGroupContent(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = true,
|
||||
filter: SimpleFilter<CommonMessage<MediaGroupContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<MediaGroupContent>? = null
|
||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedVisualMediaGroupContent(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = true,
|
||||
filter: SimpleFilter<CommonMessage<VisualMediaGroupContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<VisualMediaGroupContent>? = null
|
||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedAnimation(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<AnimationContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<AnimationContent>? = null
|
||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedAudio(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = false,
|
||||
filter: SimpleFilter<CommonMessage<AudioContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<AudioContent>? = null
|
||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedDocument(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = false,
|
||||
filter: SimpleFilter<CommonMessage<DocumentContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<DocumentContent>? = null
|
||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedPhoto(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = false,
|
||||
filter: SimpleFilter<CommonMessage<PhotoContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<PhotoContent>? = null
|
||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedSticker(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<StickerContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<StickerContent>? = null
|
||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedVideo(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
includeMediaGroups: Boolean = false,
|
||||
filter: SimpleFilter<CommonMessage<VideoContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<VideoContent>? = null
|
||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedVideoNote(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<VideoNoteContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<VideoNoteContent>? = null
|
||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedVoice(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<VoiceContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<VoiceContent>? = null
|
||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitEditedInvoice(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<CommonMessage<InvoiceContent>>? = null,
|
||||
mapper: CommonMessageToContentMapper<InvoiceContent>? = null
|
||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
|
@@ -0,0 +1,236 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asBaseSentMessageUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.asChatEventMessage
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
|
||||
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
|
||||
import kotlinx.coroutines.flow.toList
|
||||
|
||||
typealias EventMessageToEventMapper<T> = suspend ChatEventMessage<T>.() -> T?
|
||||
|
||||
private suspend fun <O> BehaviourContext.waitEventMessages(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<ChatEvent>>? = null,
|
||||
mapper: suspend ChatEventMessage<ChatEvent>.() -> O?
|
||||
): List<O> = expectFlow(
|
||||
initRequest,
|
||||
count,
|
||||
errorFactory
|
||||
) {
|
||||
val data = it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage()
|
||||
if (data != null && (filter == null || filter(data))) {
|
||||
data.mapper().let(::listOfNotNull)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}.toList().toList()
|
||||
|
||||
|
||||
private suspend inline fun <reified T : ChatEvent> BehaviourContext.waitEvents(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||
noinline filter: SimpleFilter<ChatEventMessage<T>>? = null,
|
||||
noinline mapper: EventMessageToEventMapper<T>? = null
|
||||
) : List<T> = waitEventMessages<T>(
|
||||
initRequest,
|
||||
errorFactory,
|
||||
count,
|
||||
filter ?.let {
|
||||
{
|
||||
(it.chatEvent as? T) ?.let { filter(it as ChatEventMessage<T>) } == true
|
||||
}
|
||||
}
|
||||
) {
|
||||
if (chatEvent is T) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val message = (this as ChatEventMessage<T>)
|
||||
if (mapper == null) {
|
||||
message.chatEvent
|
||||
} else {
|
||||
mapper(message)
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun BehaviourContext.waitChannelEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<ChannelEvent>>? = null,
|
||||
mapper: EventMessageToEventMapper<ChannelEvent>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
|
||||
suspend fun BehaviourContext.waitPrivateEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<PrivateEvent>>? = null,
|
||||
mapper: EventMessageToEventMapper<PrivateEvent>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
|
||||
suspend fun BehaviourContext.waitChatEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<ChatEvent>>? = null,
|
||||
mapper: EventMessageToEventMapper<ChatEvent>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
|
||||
suspend fun BehaviourContext.waitVoiceChatEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<VoiceChatEvent>>? = null,
|
||||
mapper: EventMessageToEventMapper<VoiceChatEvent>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitVoiceChatStartedEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<VoiceChatStarted>>? = null,
|
||||
mapper: EventMessageToEventMapper<VoiceChatStarted>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitVoiceChatEndedEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<VoiceChatEnded>>? = null,
|
||||
mapper: EventMessageToEventMapper<VoiceChatEnded>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitVoiceChatParticipantsInvitedEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<VoiceChatParticipantsInvited>>? = null,
|
||||
mapper: EventMessageToEventMapper<VoiceChatParticipantsInvited>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
|
||||
suspend fun BehaviourContext.waitMessageAutoDeleteTimerChangedEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<MessageAutoDeleteTimerChanged>>? = null,
|
||||
mapper: EventMessageToEventMapper<MessageAutoDeleteTimerChanged>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
|
||||
|
||||
suspend fun BehaviourContext.waitPublicChatEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<PublicChatEvent>>? = null,
|
||||
mapper: EventMessageToEventMapper<PublicChatEvent>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitCommonEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<CommonEvent>>? = null,
|
||||
mapper: EventMessageToEventMapper<CommonEvent>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
|
||||
suspend fun BehaviourContext.waitGroupEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<GroupEvent>>? = null,
|
||||
mapper: EventMessageToEventMapper<GroupEvent>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitSupergroupEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<SupergroupEvent>>? = null,
|
||||
mapper: EventMessageToEventMapper<SupergroupEvent>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
|
||||
suspend fun BehaviourContext.waitChannelChatCreatedEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<ChannelChatCreated>>? = null,
|
||||
mapper: EventMessageToEventMapper<ChannelChatCreated>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitDeleteChatPhotoEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<DeleteChatPhoto>>? = null,
|
||||
mapper: EventMessageToEventMapper<DeleteChatPhoto>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitGroupChatCreatedEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<GroupChatCreated>>? = null,
|
||||
mapper: EventMessageToEventMapper<GroupChatCreated>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitLeftChatMemberEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<LeftChatMember>>? = null,
|
||||
mapper: EventMessageToEventMapper<LeftChatMember>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitNewChatPhotoEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<NewChatPhoto>>? = null,
|
||||
mapper: EventMessageToEventMapper<NewChatPhoto>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitNewChatMembersEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<NewChatMembers>>? = null,
|
||||
mapper: EventMessageToEventMapper<NewChatMembers>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitNewChatTitleEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<NewChatTitle>>? = null,
|
||||
mapper: EventMessageToEventMapper<NewChatTitle>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitPinnedMessageEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<PinnedMessage>>? = null,
|
||||
mapper: EventMessageToEventMapper<PinnedMessage>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitProximityAlertTriggeredEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<ProximityAlertTriggered>>? = null,
|
||||
mapper: EventMessageToEventMapper<ProximityAlertTriggered>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitSupergroupChatCreatedEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<SupergroupChatCreated>>? = null,
|
||||
mapper: EventMessageToEventMapper<SupergroupChatCreated>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitSuccessfulPaymentEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<SuccessfulPaymentEvent>>? = null,
|
||||
mapper: EventMessageToEventMapper<SuccessfulPaymentEvent>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
@@ -0,0 +1,80 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asInlineQueryUpdate
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.query.*
|
||||
import kotlinx.coroutines.flow.toList
|
||||
|
||||
typealias InlineQueryMapper<T> = suspend T.() -> T?
|
||||
|
||||
private suspend fun <O> BehaviourContext.waitInlineQueries(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: SimpleFilter<InlineQuery>? = null,
|
||||
mapper: suspend InlineQuery.() -> O?
|
||||
): List<O> = expectFlow(
|
||||
initRequest,
|
||||
count,
|
||||
errorFactory
|
||||
) {
|
||||
val data = it.asInlineQueryUpdate() ?.data
|
||||
if (data != null && (filter == null || filter(data))) {
|
||||
data.mapper().let(::listOfNotNull)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}.toList().toList()
|
||||
|
||||
|
||||
private suspend inline fun <reified T : InlineQuery> BehaviourContext.waitInlines(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||
noinline filter: SimpleFilter<T>? = null,
|
||||
noinline mapper: InlineQueryMapper<T>? = null
|
||||
) : List<T> = waitInlineQueries<T>(
|
||||
count,
|
||||
initRequest,
|
||||
errorFactory,
|
||||
filter ?.let {
|
||||
{
|
||||
(it as? T) ?.let { casted -> filter(casted) } == true
|
||||
}
|
||||
}
|
||||
) {
|
||||
if (this is T) {
|
||||
if (mapper == null) {
|
||||
this
|
||||
} else {
|
||||
mapper(this)
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun BehaviourContext.waitAnyInlineQuery(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<InlineQuery>? = null,
|
||||
mapper: InlineQueryMapper<InlineQuery>? = null
|
||||
) = waitInlines(count, initRequest, errorFactory, filter, mapper)
|
||||
|
||||
suspend fun BehaviourContext.waitBaseInlineQuery(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<BaseInlineQuery>? = null,
|
||||
mapper: InlineQueryMapper<BaseInlineQuery>? = null
|
||||
) = waitInlines(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitLocationInlineQuery(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<LocationInlineQuery>? = null,
|
||||
mapper: InlineQueryMapper<LocationInlineQuery>? = null
|
||||
) = waitInlines(count, initRequest, errorFactory, filter, mapper)
|
@@ -0,0 +1,69 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.utils.asSentMediaGroupUpdate
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.content.media.PhotoContent
|
||||
import dev.inmo.tgbotapi.types.message.content.media.VideoContent
|
||||
import dev.inmo.tgbotapi.utils.PreviewFeature
|
||||
import kotlinx.coroutines.flow.take
|
||||
import kotlinx.coroutines.flow.toList
|
||||
|
||||
typealias MediaGroupFilter<T> = suspend List<MediaGroupMessage<T>>.() -> Boolean
|
||||
|
||||
@PreviewFeature
|
||||
internal suspend inline fun <reified T : MediaGroupContent> BehaviourContext.buildMediaGroupWaiter(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||
noinline filter: MediaGroupFilter<T>? = null
|
||||
) = flowsUpdatesFilter.expectFlow(bot, initRequest, count, errorFactory) { update ->
|
||||
update.asSentMediaGroupUpdate() ?.data ?.let { mediaGroup ->
|
||||
if (mediaGroup.all { message -> message.content is T } && (filter == null || filter(mediaGroup as List<MediaGroupMessage<T>>))) {
|
||||
listOf(
|
||||
mediaGroup.map { it.content as T }
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
} ?: emptyList()
|
||||
}.take(count).toList()
|
||||
|
||||
suspend fun BehaviourContext.waitMediaGroup(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: MediaGroupFilter<MediaGroupContent>? = null
|
||||
) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitPlaylist(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: MediaGroupFilter<AudioMediaGroupContent>? = null
|
||||
) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitDocumentsGroup(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: MediaGroupFilter<DocumentMediaGroupContent>? = null
|
||||
) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitVisualGallery(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: MediaGroupFilter<VisualMediaGroupContent>? = null
|
||||
) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitPhotoGallery(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: MediaGroupFilter<PhotoContent>? = null
|
||||
) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitVideoGallery(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: MediaGroupFilter<VideoContent>? = null
|
||||
) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter)
|
@@ -0,0 +1,65 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.asPassportMessage
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.message.PassportMessage
|
||||
import dev.inmo.tgbotapi.types.passport.PassportData
|
||||
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElement
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import kotlinx.coroutines.flow.toList
|
||||
|
||||
typealias PassportMessageMapper = suspend PassportMessage.() -> PassportData
|
||||
|
||||
@RiskFeature("Do not use this message directly, use waitPassportMessagesWith or waitAnyPassportMessages instead")
|
||||
suspend fun <O> BehaviourContext.waitPassportMessages(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<PassportMessage>? = null,
|
||||
mapper: suspend PassportMessage.() -> O?
|
||||
): List<O> = expectFlow(
|
||||
initRequest,
|
||||
count,
|
||||
errorFactory
|
||||
) {
|
||||
val data = it.asMessageUpdate() ?.data ?.asPassportMessage() ?: return@expectFlow emptyList()
|
||||
if (filter == null || filter(data)) {
|
||||
data.mapper().let(::listOfNotNull)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}.toList().toList()
|
||||
|
||||
suspend inline fun <reified T : EncryptedPassportElement> BehaviourContext.waitPassportMessagesWith(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||
noinline filter: SimpleFilter<PassportMessage>? = null,
|
||||
noinline mapper: PassportMessageMapper? = null
|
||||
) : List<PassportData> = waitPassportMessages(
|
||||
initRequest,
|
||||
errorFactory,
|
||||
count,
|
||||
filter
|
||||
) {
|
||||
if (passportData.data.any { it is T }) {
|
||||
if (mapper == null) {
|
||||
passportData
|
||||
} else {
|
||||
mapper(this)
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun BehaviourContext.waitAnyPassportMessages(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<PassportMessage>? = null,
|
||||
mapper: PassportMessageMapper? = null
|
||||
) = waitPassportMessagesWith<EncryptedPassportElement>(count, initRequest, errorFactory, filter, mapper)
|
@@ -0,0 +1,68 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.polls.*
|
||||
import kotlinx.coroutines.flow.toList
|
||||
|
||||
typealias PollAnswerMapper = suspend PollAnswer.() -> PollAnswer?
|
||||
|
||||
private suspend fun <O> BehaviourContext.waitPollsAnswers(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: SimpleFilter<PollAnswer>? = null,
|
||||
mapper: suspend PollAnswer.() -> O?
|
||||
): List<O> = expectFlow(
|
||||
initRequest,
|
||||
count,
|
||||
errorFactory
|
||||
) {
|
||||
val data = it.asPollAnswerUpdate() ?.data
|
||||
if (data != null && (filter == null || filter(data))) {
|
||||
data.mapper().let(::listOfNotNull)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}.toList().toList()
|
||||
|
||||
|
||||
private suspend inline fun BehaviourContext.waitPollAnswers(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||
noinline filter: SimpleFilter<PollAnswer>? = null,
|
||||
noinline mapper: PollAnswerMapper? = null
|
||||
) : List<PollAnswer> = this@waitPollAnswers.waitPollsAnswers<PollAnswer>(
|
||||
count,
|
||||
initRequest,
|
||||
errorFactory,
|
||||
filter ?.let {
|
||||
{
|
||||
(it as? PollAnswer) ?.let { filter(it) } == true
|
||||
}
|
||||
}
|
||||
) {
|
||||
if (this is PollAnswer) {
|
||||
if (mapper == null) {
|
||||
this
|
||||
} else {
|
||||
mapper(this)
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This wait will be triggered only for stopped polls and polls, which are sent by the bot
|
||||
*/
|
||||
suspend fun BehaviourContext.waitPollAnswers(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<PollAnswer>? = null,
|
||||
mapper: PollAnswerMapper? = null
|
||||
) = waitPollAnswers(count, initRequest, errorFactory, filter, mapper)
|
@@ -0,0 +1,90 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.polls.*
|
||||
import kotlinx.coroutines.flow.toList
|
||||
|
||||
typealias PollMapper<T> = suspend T.() -> T?
|
||||
|
||||
private suspend fun <O> BehaviourContext.waitPollsUpdates(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: SimpleFilter<Poll>? = null,
|
||||
mapper: suspend Poll.() -> O?
|
||||
): List<O> = expectFlow(
|
||||
initRequest,
|
||||
count,
|
||||
errorFactory
|
||||
) {
|
||||
val data = it.asPollUpdate() ?.data
|
||||
if (data != null && (filter == null || filter(data))) {
|
||||
data.mapper().let(::listOfNotNull)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}.toList().toList()
|
||||
|
||||
|
||||
private suspend inline fun <reified T : Poll> BehaviourContext.waitPolls(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||
noinline filter: SimpleFilter<T>? = null,
|
||||
noinline mapper: PollMapper<T>? = null
|
||||
) : List<T> = this@waitPolls.waitPollsUpdates<T>(
|
||||
count,
|
||||
initRequest,
|
||||
errorFactory,
|
||||
filter ?.let {
|
||||
{
|
||||
(it as? T) ?.let { filter(it) } == true
|
||||
}
|
||||
}
|
||||
) {
|
||||
if (this is T) {
|
||||
if (mapper == null) {
|
||||
this
|
||||
} else {
|
||||
mapper(this)
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This wait will be triggered only for stopped polls and polls, which are sent by the bot
|
||||
*/
|
||||
suspend fun BehaviourContext.waitPollUpdates(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<Poll>? = null,
|
||||
mapper: PollMapper<Poll>? = null
|
||||
) = waitPolls(count, initRequest, errorFactory, filter, mapper)
|
||||
|
||||
/**
|
||||
* This wait will be triggered only for stopped polls and polls, which are sent by the bot
|
||||
*/
|
||||
suspend fun BehaviourContext.waitQuizPollUpdates(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<QuizPoll>? = null,
|
||||
mapper: PollMapper<QuizPoll>? = null
|
||||
) = waitPolls(count, initRequest, errorFactory, filter, mapper)
|
||||
|
||||
/**
|
||||
* This wait will be triggered only for stopped polls and polls, which are sent by the bot
|
||||
*/
|
||||
suspend fun BehaviourContext.waitRegularPollUpdates(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<RegularPoll>? = null,
|
||||
mapper: PollMapper<RegularPoll>? = null
|
||||
) = waitPolls(count, initRequest, errorFactory, filter, mapper)
|
@@ -0,0 +1,51 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asPreCheckoutQueryUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.asShippingQueryUpdate
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
|
||||
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
||||
import kotlinx.coroutines.flow.toList
|
||||
|
||||
typealias PreCheckoutQueryMapper = suspend PreCheckoutQuery.() -> PreCheckoutQuery?
|
||||
|
||||
private suspend fun <O> BehaviourContext.waitPreCheckoutQueries(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: SimpleFilter<PreCheckoutQuery>? = null,
|
||||
mapper: suspend PreCheckoutQuery.() -> O?
|
||||
): List<O> = expectFlow(
|
||||
initRequest,
|
||||
count,
|
||||
errorFactory
|
||||
) {
|
||||
val data = it.asPreCheckoutQueryUpdate() ?.data
|
||||
if (data != null && (filter == null || filter(data))) {
|
||||
data.mapper().let(::listOfNotNull)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}.toList().toList()
|
||||
|
||||
|
||||
suspend fun BehaviourContext.waitPreCheckoutQueries(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<PreCheckoutQuery>? = null,
|
||||
mapper: PreCheckoutQueryMapper? = null
|
||||
) : List<PreCheckoutQuery> = waitPreCheckoutQueries(
|
||||
count,
|
||||
initRequest,
|
||||
errorFactory,
|
||||
filter
|
||||
) {
|
||||
if (mapper == null) {
|
||||
this
|
||||
} else {
|
||||
mapper(this)
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asShippingQueryUpdate
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
||||
import kotlinx.coroutines.flow.toList
|
||||
|
||||
typealias ShippingQueryMapper = suspend ShippingQuery.() -> ShippingQuery?
|
||||
|
||||
private suspend fun <O> BehaviourContext.waitShippingQueries(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: SimpleFilter<ShippingQuery>? = null,
|
||||
mapper: suspend ShippingQuery.() -> O?
|
||||
): List<O> = expectFlow(
|
||||
initRequest,
|
||||
count,
|
||||
errorFactory
|
||||
) {
|
||||
val data = it.asShippingQueryUpdate() ?.data
|
||||
if (data != null && (filter == null || filter(data))) {
|
||||
data.mapper().let(::listOfNotNull)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}.toList().toList()
|
||||
|
||||
|
||||
suspend fun BehaviourContext.waitShippingQueries(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ShippingQuery>? = null,
|
||||
mapper: ShippingQueryMapper? = null
|
||||
) : List<ShippingQuery> = waitShippingQueries(
|
||||
count,
|
||||
initRequest,
|
||||
errorFactory,
|
||||
filter
|
||||
) {
|
||||
if (mapper == null) {
|
||||
this
|
||||
} else {
|
||||
mapper(this)
|
||||
}
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.filters
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver
|
||||
import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat
|
||||
import dev.inmo.tgbotapi.types.CallbackQuery.CallbackQuery
|
||||
import dev.inmo.tgbotapi.types.ChatMemberUpdated
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
|
||||
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
/**
|
||||
* Allow only events from the same chat as base [Message]
|
||||
*/
|
||||
val MessageFilterByChat: BehaviourContextAndTwoTypesReceiver<Boolean, Message, Update> = { message, update ->
|
||||
update.sourceChat() ?.id == message.chat.id
|
||||
}
|
||||
/**
|
||||
* Allow only events from the same chat as base [List] of [Message]
|
||||
*/
|
||||
val MessagesFilterByChat: BehaviourContextAndTwoTypesReceiver<Boolean, List<Message>, Update> = { messages, update ->
|
||||
val sourceChatId = update.sourceChat() ?.id
|
||||
sourceChatId != null && messages.all { sourceChatId == it.chat.id }
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow only updates from the same user as base [CallbackQuery.user]
|
||||
*/
|
||||
val CallbackQueryFilterByUser: BehaviourContextAndTwoTypesReceiver<Boolean, CallbackQuery, Update> = { query, update ->
|
||||
update.sourceChat() ?.id == query.user.id
|
||||
}
|
||||
/**
|
||||
* Allow only updates from the same user as base [ShippingQuery.user]
|
||||
*/
|
||||
val ShippingQueryFilterByUser: BehaviourContextAndTwoTypesReceiver<Boolean, ShippingQuery, Update> = { query, update ->
|
||||
update.sourceChat() ?.id == query.user.id
|
||||
}
|
||||
/**
|
||||
* Allow only updates from the same user as base [ShippingQuery.user]
|
||||
*/
|
||||
val PreCheckoutQueryFilterByUser: BehaviourContextAndTwoTypesReceiver<Boolean, PreCheckoutQuery, Update> = { query, update ->
|
||||
update.sourceChat() ?.id == query.user.id
|
||||
}
|
||||
/**
|
||||
* Allow only updates from the same user as base [InlineQuery.from]
|
||||
*/
|
||||
val InlineQueryFilterByUser: BehaviourContextAndTwoTypesReceiver<Boolean, InlineQuery, Update> = { query, update ->
|
||||
update.sourceChat() ?.id == query.from.id
|
||||
}
|
||||
/**
|
||||
* Allow only events from the same chat as base [ChatMemberUpdated]
|
||||
*/
|
||||
val ChatMemberUpdatedFilterByChat: BehaviourContextAndTwoTypesReceiver<Boolean, ChatMemberUpdated, Update> = { updated, update ->
|
||||
update.sourceChat() ?.id == updated.chat.id
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.filters
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.CommonMessageFilter
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
/**
|
||||
* Allow only messages which are not [MediaGroupMessage]
|
||||
*/
|
||||
val MessageFilterExcludingMediaGroups: BehaviourContextAndTwoTypesReceiver<Boolean, CommonMessage<*>, Update> = { message, update ->
|
||||
update !is MediaGroupMessage<*>
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow only messages which are not [MediaGroupMessage]
|
||||
*/
|
||||
val CommonMessageFilterExcludeMediaGroups: CommonMessageFilter<*> = {
|
||||
it !is MediaGroupMessage<*>
|
||||
}
|
@@ -0,0 +1,237 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CallbackQueryFilterByUser
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserCallbackQueryMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.asCallbackQueryUpdate
|
||||
import dev.inmo.tgbotapi.types.CallbackQuery.*
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
internal suspend inline fun <BC : BehaviourContext, reified T : CallbackQuery> BC.onCallbackQuery(
|
||||
noinline initialFilter: SimpleFilter<T>? = null,
|
||||
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, T, Update>? = CallbackQueryFilterByUser,
|
||||
markerFactory: MarkerFactory<in T, Any> = ByUserCallbackQueryMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, T>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asCallbackQueryUpdate() ?.data as? T) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onDataCallbackQuery(
|
||||
initialFilter: SimpleFilter<DataCallbackQuery>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, DataCallbackQuery, Update>? = CallbackQueryFilterByUser,
|
||||
markerFactory: MarkerFactory<in DataCallbackQuery, Any> = ByUserCallbackQueryMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, DataCallbackQuery>
|
||||
) = onCallbackQuery(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onGameShortNameCallbackQuery(
|
||||
initialFilter: SimpleFilter<GameShortNameCallbackQuery>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, GameShortNameCallbackQuery, Update>? = CallbackQueryFilterByUser,
|
||||
markerFactory: MarkerFactory<in GameShortNameCallbackQuery, Any> = ByUserCallbackQueryMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, GameShortNameCallbackQuery>
|
||||
) = onCallbackQuery(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onInlineMessageIdCallbackQuery(
|
||||
initialFilter: SimpleFilter<InlineMessageIdCallbackQuery>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, InlineMessageIdCallbackQuery, Update>? = CallbackQueryFilterByUser,
|
||||
markerFactory: MarkerFactory<in InlineMessageIdCallbackQuery, Any> = ByUserCallbackQueryMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, InlineMessageIdCallbackQuery>
|
||||
) = onCallbackQuery(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onInlineMessageIdDataCallbackQuery(
|
||||
initialFilter: SimpleFilter<InlineMessageIdDataCallbackQuery>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, InlineMessageIdDataCallbackQuery, Update>? = CallbackQueryFilterByUser,
|
||||
markerFactory: MarkerFactory<in InlineMessageIdDataCallbackQuery, Any> = ByUserCallbackQueryMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, InlineMessageIdDataCallbackQuery>
|
||||
) = onCallbackQuery(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onInlineMessageIdGameShortNameCallbackQuery(
|
||||
initialFilter: SimpleFilter<InlineMessageIdGameShortNameCallbackQuery>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, InlineMessageIdGameShortNameCallbackQuery, Update>? = CallbackQueryFilterByUser,
|
||||
markerFactory: MarkerFactory<in InlineMessageIdGameShortNameCallbackQuery, Any> = ByUserCallbackQueryMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, InlineMessageIdGameShortNameCallbackQuery>
|
||||
) = onCallbackQuery(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onMessageCallbackQuery(
|
||||
initialFilter: SimpleFilter<MessageCallbackQuery>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MessageCallbackQuery, Update>? = CallbackQueryFilterByUser,
|
||||
markerFactory: MarkerFactory<in MessageCallbackQuery, Any> = ByUserCallbackQueryMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MessageCallbackQuery>
|
||||
) = onCallbackQuery(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onMessageDataCallbackQuery(
|
||||
initialFilter: SimpleFilter<MessageDataCallbackQuery>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MessageDataCallbackQuery, Update>? = CallbackQueryFilterByUser,
|
||||
markerFactory: MarkerFactory<in MessageDataCallbackQuery, Any> = ByUserCallbackQueryMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MessageDataCallbackQuery>
|
||||
) = onCallbackQuery(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onMessageGameShortNameCallbackQuery(
|
||||
initialFilter: SimpleFilter<MessageGameShortNameCallbackQuery>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MessageGameShortNameCallbackQuery, Update>? = CallbackQueryFilterByUser,
|
||||
markerFactory: MarkerFactory<in MessageGameShortNameCallbackQuery, Any> = ByUserCallbackQueryMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MessageGameShortNameCallbackQuery>
|
||||
) = onCallbackQuery(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onUnknownCallbackQueryType(
|
||||
initialFilter: SimpleFilter<UnknownCallbackQueryType>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, UnknownCallbackQueryType, Update>? = CallbackQueryFilterByUser,
|
||||
markerFactory: MarkerFactory<in UnknownCallbackQueryType, Any> = ByUserCallbackQueryMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, UnknownCallbackQueryType>
|
||||
) = onCallbackQuery(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
@@ -0,0 +1,96 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.ChatMemberUpdatedFilterByChat
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatChatMemberUpdatedMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.types.ChatMemberUpdated
|
||||
import dev.inmo.tgbotapi.types.update.CommonChatMemberUpdatedUpdate
|
||||
import dev.inmo.tgbotapi.types.update.MyChatMemberUpdatedUpdate
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
internal suspend inline fun <BC : BehaviourContext, reified U : ChatMemberUpdatedUpdate> BC.onChatMemberUpdatedInternal(
|
||||
noinline initialFilter: SimpleFilter<ChatMemberUpdated>? = null,
|
||||
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatMemberUpdated, Update>? = ChatMemberUpdatedFilterByChat,
|
||||
markerFactory: MarkerFactory<ChatMemberUpdated, Any> = ByChatChatMemberUpdatedMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatMemberUpdated>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
((it as? U) ?.data) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onChatMemberUpdated(
|
||||
initialFilter: SimpleFilter<ChatMemberUpdated>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatMemberUpdated, Update>? = ChatMemberUpdatedFilterByChat,
|
||||
markerFactory: MarkerFactory<ChatMemberUpdated, Any> = ByChatChatMemberUpdatedMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatMemberUpdated>
|
||||
) = onChatMemberUpdatedInternal<BC, ChatMemberUpdatedUpdate>(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onCommonChatMemberUpdated(
|
||||
initialFilter: SimpleFilter<ChatMemberUpdated>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatMemberUpdated, Update>? = ChatMemberUpdatedFilterByChat,
|
||||
markerFactory: MarkerFactory<ChatMemberUpdated, Any> = ByChatChatMemberUpdatedMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatMemberUpdated>
|
||||
) = onChatMemberUpdatedInternal<BC, CommonChatMemberUpdatedUpdate>(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onMyChatMemberUpdated(
|
||||
initialFilter: SimpleFilter<ChatMemberUpdated>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatMemberUpdated, Update>? = ChatMemberUpdatedFilterByChat,
|
||||
markerFactory: MarkerFactory<ChatMemberUpdated, Any> = ByChatChatMemberUpdatedMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatMemberUpdated>
|
||||
) = onChatMemberUpdatedInternal<BC, MyChatMemberUpdatedUpdate>(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
@@ -0,0 +1,93 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.*
|
||||
import dev.inmo.tgbotapi.extensions.utils.asChosenInlineResultUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.asPollUpdate
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.*
|
||||
import dev.inmo.tgbotapi.types.polls.*
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
internal suspend inline fun <BC : BehaviourContext, reified T : ChosenInlineResult> BC.onChosenInlineResultBase(
|
||||
noinline initialFilter: SimpleFilter<T>? = null,
|
||||
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, T, Update>? = null,
|
||||
markerFactory: MarkerFactory<in T, Any> = ByUserIdChosenInlineResultMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, T>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asChosenInlineResultUpdate() ?.data as? T) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onChosenInlineResult(
|
||||
initialFilter: SimpleFilter<ChosenInlineResult>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChosenInlineResult, Update>? = null,
|
||||
markerFactory: MarkerFactory<in ChosenInlineResult, Any> = ByUserIdChosenInlineResultMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChosenInlineResult>
|
||||
) = onChosenInlineResultBase(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onLocationChosenInlineResult(
|
||||
initialFilter: SimpleFilter<LocationChosenInlineResult>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, LocationChosenInlineResult, Update>? = null,
|
||||
markerFactory: MarkerFactory<in LocationChosenInlineResult, Any> = ByUserIdChosenInlineResultMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, LocationChosenInlineResult>
|
||||
) = onChosenInlineResultBase(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onBaseChosenInlineResult(
|
||||
initialFilter: SimpleFilter<BaseChosenInlineResult>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, BaseChosenInlineResult, Update>? = null,
|
||||
markerFactory: MarkerFactory<in BaseChosenInlineResult, Any> = ByUserIdChosenInlineResultMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, BaseChosenInlineResult>
|
||||
) = onChosenInlineResultBase(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
@@ -0,0 +1,121 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CommonMessageFilterExcludeMediaGroups
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times
|
||||
import dev.inmo.tgbotapi.extensions.utils.asBotCommandTextSource
|
||||
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithParams
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
import kotlinx.coroutines.Job
|
||||
|
||||
|
||||
suspend fun <BC : BehaviourContext> BC.command(
|
||||
commandRegex: Regex,
|
||||
requireOnlyCommandInMessage: Boolean = true,
|
||||
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<TextContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<TextContent>>
|
||||
): Job = onText(
|
||||
CommonMessageFilter<TextContent> { message ->
|
||||
val content = message.content
|
||||
val textSources = content.textSources
|
||||
val sizeRequirement = if (requireOnlyCommandInMessage) {
|
||||
textSources.size == 1
|
||||
} else {
|
||||
true
|
||||
}
|
||||
sizeRequirement && textSources.any {
|
||||
commandRegex.matches(it.asBotCommandTextSource() ?.command ?: return@any false)
|
||||
}
|
||||
}.let {
|
||||
initialFilter ?.times(it) ?: it
|
||||
},
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
suspend fun <BC : BehaviourContext> BC.command(
|
||||
command: String,
|
||||
requireOnlyCommandInMessage: Boolean = true,
|
||||
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<TextContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<TextContent>>
|
||||
) = command(command.toRegex(), requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
suspend inline fun <BC : BehaviourContext> BC.onCommand(
|
||||
commandRegex: Regex,
|
||||
requireOnlyCommandInMessage: Boolean = true,
|
||||
noinline initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<TextContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = ByChatMessageMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<TextContent>>
|
||||
): Job = command(commandRegex, requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
suspend inline fun <BC : BehaviourContext> BC.onCommand(
|
||||
command: String,
|
||||
requireOnlyCommandInMessage: Boolean = true,
|
||||
noinline initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<TextContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = ByChatMessageMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<TextContent>>
|
||||
): Job = onCommand(command.toRegex(), requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
suspend fun <BC : BehaviourContext> BC.commandWithArgs(
|
||||
commandRegex: Regex,
|
||||
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<TextContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, CommonMessage<TextContent>, Array<String>>
|
||||
) = command(
|
||||
commandRegex,
|
||||
requireOnlyCommandInMessage = false,
|
||||
initialFilter = initialFilter,
|
||||
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
||||
markerFactory = markerFactory
|
||||
) {
|
||||
val args = it.parseCommandsWithParams().let { commandsWithArgs ->
|
||||
val key = commandsWithArgs.keys.firstOrNull { it.matches(commandRegex) } ?: return@let null
|
||||
commandsWithArgs[key]
|
||||
} ?: emptyArray()
|
||||
scenarioReceiver(it, args)
|
||||
}
|
||||
|
||||
suspend fun <BC : BehaviourContext> BC.commandWithArgs(
|
||||
command: String,
|
||||
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<TextContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, CommonMessage<TextContent>, Array<String>>
|
||||
) = commandWithArgs(
|
||||
command.toRegex(),
|
||||
initialFilter = initialFilter,
|
||||
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
||||
markerFactory = markerFactory,
|
||||
scenarioReceiver = scenarioReceiver
|
||||
)
|
||||
|
||||
suspend inline fun <BC : BehaviourContext> BC.onCommandWithArgs(
|
||||
commandRegex: Regex,
|
||||
noinline initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<TextContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = ByChatMessageMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, CommonMessage<TextContent>, Array<String>>
|
||||
): Job = commandWithArgs(commandRegex, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
suspend inline fun <BC : BehaviourContext> BC.onCommandWithArgs(
|
||||
command: String,
|
||||
noinline initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<TextContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = ByChatMessageMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, CommonMessage<TextContent>, Array<String>>
|
||||
): Job = onCommandWithArgs(command.toRegex(), initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
@@ -0,0 +1,591 @@
|
||||
@file:Suppress("unused", "UNCHECKED_CAST")
|
||||
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CommonMessageFilterExcludeMediaGroups
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.whenCommonMessage
|
||||
import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.*
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.*
|
||||
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 dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
typealias CommonMessageFilter<T> = SimpleFilter<CommonMessage<T>>
|
||||
inline fun <T : MessageContent> CommonMessageFilter(noinline block: CommonMessageFilter<T>) = block
|
||||
|
||||
internal suspend inline fun <BC : BehaviourContext, reified T : MessageContent> BC.onContent(
|
||||
noinline initialFilter: CommonMessageFilter<T>? = null,
|
||||
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<T>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<T>, Any> = ByChatMessageMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<T>>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
when (it) {
|
||||
is BaseSentMessageUpdate -> it.data.whenCommonMessage(::listOfNotNull)
|
||||
is SentMediaGroupUpdate -> it.data
|
||||
else -> null
|
||||
} ?.mapNotNull { message ->
|
||||
if (message.content is T) message as CommonMessage<T> else null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onContentMessage(
|
||||
initialFilter: CommonMessageFilter<MessageContent>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<MessageContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<MessageContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<MessageContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onContact(
|
||||
initialFilter: CommonMessageFilter<ContactContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<ContactContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<ContactContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<ContactContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onDice(
|
||||
initialFilter: CommonMessageFilter<DiceContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<DiceContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<DiceContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<DiceContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onGame(
|
||||
initialFilter: CommonMessageFilter<GameContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<GameContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<GameContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<GameContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onLocation(
|
||||
initialFilter: CommonMessageFilter<LocationContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<LocationContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<LocationContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<LocationContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onLiveLocation(
|
||||
initialFilter: CommonMessageFilter<LiveLocationContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<LiveLocationContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<LiveLocationContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<LiveLocationContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onStaticLocation(
|
||||
initialFilter: CommonMessageFilter<StaticLocationContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<StaticLocationContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<StaticLocationContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<StaticLocationContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onPoll(
|
||||
initialFilter: CommonMessageFilter<PollContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<PollContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<PollContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<PollContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onText(
|
||||
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<TextContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<TextContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onVenue(
|
||||
initialFilter: CommonMessageFilter<VenueContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<VenueContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<VenueContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<VenueContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onAudioMediaGroup(
|
||||
initialFilter: CommonMessageFilter<AudioMediaGroupContent>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<AudioMediaGroupContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<AudioMediaGroupContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<AudioMediaGroupContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onDocumentMediaGroupContent(
|
||||
initialFilter: CommonMessageFilter<DocumentMediaGroupContent>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<DocumentMediaGroupContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<DocumentMediaGroupContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<DocumentMediaGroupContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onMediaCollection(
|
||||
initialFilter: CommonMessageFilter<MediaCollectionContent<TelegramMediaFile>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<MediaCollectionContent<TelegramMediaFile>>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<MediaCollectionContent<TelegramMediaFile>>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<MediaCollectionContent<TelegramMediaFile>>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onMedia(
|
||||
initialFilter: CommonMessageFilter<MediaContent>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<MediaContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<MediaContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<MediaContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onAnimation(
|
||||
initialFilter: CommonMessageFilter<AnimationContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<AnimationContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<AnimationContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<AnimationContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onAudio(
|
||||
initialFilter: CommonMessageFilter<AudioContent>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<AudioContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<AudioContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<AudioContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onDocument(
|
||||
initialFilter: CommonMessageFilter<DocumentContent>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<DocumentContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<DocumentContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<DocumentContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onPhoto(
|
||||
initialFilter: CommonMessageFilter<PhotoContent>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<PhotoContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<PhotoContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<PhotoContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onSticker(
|
||||
initialFilter: CommonMessageFilter<StickerContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<StickerContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<StickerContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<StickerContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onVideo(
|
||||
initialFilter: CommonMessageFilter<VideoContent>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<VideoContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<VideoContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<VideoContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onVideoNote(
|
||||
initialFilter: CommonMessageFilter<VideoNoteContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<VideoNoteContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<VideoNoteContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<VideoNoteContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onVoice(
|
||||
initialFilter: CommonMessageFilter<VoiceContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<VoiceContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<VoiceContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<VoiceContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onInvoice(
|
||||
initialFilter: CommonMessageFilter<InvoiceContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<InvoiceContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<InvoiceContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<InvoiceContent>>
|
||||
) = onContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
@@ -0,0 +1,540 @@
|
||||
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/@file:Suppress("unused", "UNCHECKED_CAST")
|
||||
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CommonMessageFilterExcludeMediaGroups
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.asEditMessageUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
||||
import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.*
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.content.media.*
|
||||
import dev.inmo.tgbotapi.types.message.payments.InvoiceContent
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseEditMessageUpdate
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
import dev.inmo.tgbotapi.utils.PreviewFeature
|
||||
|
||||
@PreviewFeature
|
||||
internal suspend inline fun <BC : BehaviourContext, reified T : MessageContent> BC.onEditedContent(
|
||||
noinline initialFilter: CommonMessageFilter<T>? = null,
|
||||
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<T>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<T>, Any> = ByChatMessageMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<T>>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
when (it) {
|
||||
is BaseEditMessageUpdate -> (it.asEditMessageUpdate() ?.data ?.withContent<T>())
|
||||
else -> null
|
||||
} ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedContentMessage(
|
||||
initialFilter: CommonMessageFilter<MessageContent>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<MessageContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<MessageContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<MessageContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedContact(
|
||||
initialFilter: CommonMessageFilter<ContactContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<ContactContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<ContactContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<ContactContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedDice(
|
||||
initialFilter: CommonMessageFilter<DiceContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<DiceContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<DiceContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<DiceContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedGame(
|
||||
initialFilter: CommonMessageFilter<GameContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<GameContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<GameContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<GameContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedLocation(
|
||||
initialFilter: CommonMessageFilter<LocationContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<LocationContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<LocationContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<LocationContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
@Deprecated("Potentially, this trigger will never be used. Use `onPollUpdated` instead")
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedPoll(
|
||||
initialFilter: CommonMessageFilter<PollContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<PollContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<PollContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<PollContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedText(
|
||||
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<TextContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<TextContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedVenue(
|
||||
initialFilter: CommonMessageFilter<VenueContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<VenueContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<VenueContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<VenueContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedAudioMediaGroup(
|
||||
initialFilter: CommonMessageFilter<AudioMediaGroupContent>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<AudioMediaGroupContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<AudioMediaGroupContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<AudioMediaGroupContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedDocumentMediaGroupContent(
|
||||
initialFilter: CommonMessageFilter<DocumentMediaGroupContent>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<DocumentMediaGroupContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<DocumentMediaGroupContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<DocumentMediaGroupContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedMediaCollection(
|
||||
initialFilter: CommonMessageFilter<MediaCollectionContent<TelegramMediaFile>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<MediaCollectionContent<TelegramMediaFile>>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<MediaCollectionContent<TelegramMediaFile>>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<MediaCollectionContent<TelegramMediaFile>>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedMedia(
|
||||
initialFilter: CommonMessageFilter<MediaContent>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<MediaContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<MediaContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<MediaContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedAnimation(
|
||||
initialFilter: CommonMessageFilter<AnimationContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<AnimationContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<AnimationContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<AnimationContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedAudio(
|
||||
initialFilter: CommonMessageFilter<AudioContent>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<AudioContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<AudioContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<AudioContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedDocument(
|
||||
initialFilter: CommonMessageFilter<DocumentContent>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<DocumentContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<DocumentContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<DocumentContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedPhoto(
|
||||
initialFilter: CommonMessageFilter<PhotoContent>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<PhotoContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<PhotoContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<PhotoContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedSticker(
|
||||
initialFilter: CommonMessageFilter<StickerContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<StickerContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<StickerContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<StickerContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedVideo(
|
||||
initialFilter: CommonMessageFilter<VideoContent>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<VideoContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<VideoContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<VideoContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedVideoNote(
|
||||
initialFilter: CommonMessageFilter<VideoNoteContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<VideoNoteContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<VideoNoteContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<VideoNoteContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedVoice(
|
||||
initialFilter: CommonMessageFilter<VoiceContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<VoiceContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<VoiceContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<VoiceContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onEditedInvoice(
|
||||
initialFilter: CommonMessageFilter<InvoiceContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<InvoiceContent>, Update> = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CommonMessage<InvoiceContent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<InvoiceContent>>
|
||||
)= onEditedContent(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
@@ -0,0 +1,466 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.asBaseSentMessageUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.asChatEventMessage
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
||||
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 <BC : BehaviourContext, reified T : ChatEvent> BC.onEvent(
|
||||
noinline initialFilter: SimpleFilter<ChatEventMessage<T>>? = null,
|
||||
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<T>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<T>, Any> = ByChatMessageMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<T>>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.takeIf { it.chatEvent is T } as? ChatEventMessage<T>) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onChannelEvent(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<ChannelEvent>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<ChannelEvent>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<ChannelEvent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<ChannelEvent>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onPrivateEvent(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<PrivateEvent>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<PrivateEvent>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<PrivateEvent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<PrivateEvent>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onChatEvent(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<ChatEvent>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<ChatEvent>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<ChatEvent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<ChatEvent>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onVoiceChatEvent(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<VoiceChatEvent>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<VoiceChatEvent>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<VoiceChatEvent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<VoiceChatEvent>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onVoiceChatStartedEvent(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<VoiceChatStarted>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<VoiceChatStarted>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<VoiceChatStarted>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<VoiceChatStarted>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onVoiceChatEndedEvent(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<VoiceChatEnded>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<VoiceChatEnded>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<VoiceChatEnded>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<VoiceChatEnded>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onVoiceChatParticipantsInvitedEvent(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<VoiceChatParticipantsInvited>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<VoiceChatParticipantsInvited>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<VoiceChatParticipantsInvited>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<VoiceChatParticipantsInvited>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onMessageAutoDeleteTimerChangedEvent(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<MessageAutoDeleteTimerChanged>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<MessageAutoDeleteTimerChanged>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<MessageAutoDeleteTimerChanged>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<MessageAutoDeleteTimerChanged>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onPublicChatEvent(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<PublicChatEvent>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<PublicChatEvent>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<PublicChatEvent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<PublicChatEvent>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onCommonEvent(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<CommonEvent>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<CommonEvent>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<CommonEvent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<CommonEvent>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onGroupEvent(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<GroupEvent>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<GroupEvent>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<GroupEvent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<GroupEvent>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onSupergroupEvent(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<SupergroupEvent>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<SupergroupEvent>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<SupergroupEvent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<SupergroupEvent>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onChannelChatCreated(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<ChannelChatCreated>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<ChannelChatCreated>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<ChannelChatCreated>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<ChannelChatCreated>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onDeleteChatPhoto(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<DeleteChatPhoto>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<DeleteChatPhoto>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<DeleteChatPhoto>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<DeleteChatPhoto>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onGroupChatCreated(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<GroupChatCreated>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<GroupChatCreated>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<GroupChatCreated>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<GroupChatCreated>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onLeftChatMember(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<LeftChatMember>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<LeftChatMember>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<LeftChatMember>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<LeftChatMember>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onNewChatMembers(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<NewChatMembers>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<NewChatMembers>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<NewChatMembers>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<NewChatMembers>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onNewChatPhoto(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<NewChatPhoto>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<NewChatPhoto>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<NewChatPhoto>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<NewChatPhoto>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onNewChatTitle(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<NewChatTitle>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<NewChatTitle>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<NewChatTitle>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<NewChatTitle>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onPinnedMessage(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<PinnedMessage>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<PinnedMessage>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<PinnedMessage>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<PinnedMessage>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onProximityAlertTriggered(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<ProximityAlertTriggered>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<ProximityAlertTriggered>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<ProximityAlertTriggered>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<ProximityAlertTriggered>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onSupergroupChatCreated(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<SupergroupChatCreated>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<SupergroupChatCreated>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<SupergroupChatCreated>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<SupergroupChatCreated>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* Please, remember that [SuccessfulPaymentEvent] will be retrieved only in case you will correctly handle
|
||||
* [dev.inmo.tgbotapi.types.payments.PreCheckoutQuery] (via [onPreCheckoutQuery], for example)
|
||||
*
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onSuccessfulPayment(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<SuccessfulPaymentEvent>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<SuccessfulPaymentEvent>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<SuccessfulPaymentEvent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<SuccessfulPaymentEvent>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
@@ -0,0 +1,78 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.InlineQueryFilterByUser
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserInlineQueryMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.asInlineQueryUpdate
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.query.*
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
internal suspend inline fun <BC : BehaviourContext, reified T : InlineQuery> BC.onInlineQuery(
|
||||
noinline initialFilter: SimpleFilter<T>? = null,
|
||||
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, T, Update>? = InlineQueryFilterByUser,
|
||||
markerFactory: MarkerFactory<in T, Any> = ByUserInlineQueryMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, T>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asInlineQueryUpdate() ?.data as? T) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onAnyInlineQuery(
|
||||
initialFilter: SimpleFilter<InlineQuery>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, InlineQuery, Update>? = InlineQueryFilterByUser,
|
||||
markerFactory: MarkerFactory<in InlineQuery, Any> = ByUserInlineQueryMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, InlineQuery>
|
||||
) = onInlineQuery(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onBaseInlineQuery(
|
||||
initialFilter: SimpleFilter<BaseInlineQuery>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, BaseInlineQuery, Update>? = InlineQueryFilterByUser,
|
||||
markerFactory: MarkerFactory<in BaseInlineQuery, Any> = ByUserInlineQueryMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, BaseInlineQuery>
|
||||
) = onInlineQuery(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onLocationInlineQuery(
|
||||
initialFilter: SimpleFilter<LocationInlineQuery>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, LocationInlineQuery, Update>? = InlineQueryFilterByUser,
|
||||
markerFactory: MarkerFactory<in LocationInlineQuery, Any> = ByUserInlineQueryMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, LocationInlineQuery>
|
||||
) = onInlineQuery(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
@@ -0,0 +1,33 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow
|
||||
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 suspend inline fun <BC : BehaviourContext, reified T> BC.on(
|
||||
markerFactory: MarkerFactory<in T, Any>,
|
||||
noinline initialFilter: SimpleFilter<T>? = null,
|
||||
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, T, Update>? = null,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, T>,
|
||||
noinline updateToData: (Update) -> List<T>?
|
||||
) = flowsUpdatesFilter.expectFlow(bot) {
|
||||
updateToData(it) ?.mapNotNull { data ->
|
||||
if (initialFilter ?.invoke(data) != false) data else null
|
||||
} ?: emptyList()
|
||||
}.subscribeSafelyWithoutExceptionsAsync(
|
||||
scope,
|
||||
markerFactory::invoke
|
||||
) { triggerData ->
|
||||
val scope = LinkedSupervisorScope()
|
||||
doInSubContextWithUpdatesFilter(
|
||||
updatesFilter = subcontextUpdatesFilter ?.toOneType(triggerData),
|
||||
stopOnCompletion = false,
|
||||
updatesUpstreamFlow = allUpdatesFlow.accumulatorFlow(scope),
|
||||
scope = scope
|
||||
) {
|
||||
scenarioReceiver(triggerData)
|
||||
}
|
||||
}
|
@@ -0,0 +1,159 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessagesFilterByChat
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMediaGroupMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.asSentMediaGroupUpdate
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.content.media.PhotoContent
|
||||
import dev.inmo.tgbotapi.types.message.content.media.VideoContent
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
import dev.inmo.tgbotapi.utils.PreviewFeature
|
||||
|
||||
@PreviewFeature
|
||||
internal suspend inline fun <BC : BehaviourContext, reified T : MediaGroupContent> BC.buildMediaGroupTrigger(
|
||||
noinline initialFilter: SimpleFilter<List<MediaGroupMessage<T>>>? = null,
|
||||
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<T>>, Update>? = MessagesFilterByChat,
|
||||
markerFactory: MarkerFactory<in List<MediaGroupMessage<T>>, Any> = ByChatMediaGroupMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<T>>>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asSentMediaGroupUpdate() ?.data ?.takeIf { it.all { it is T } } as? List<MediaGroupMessage<T>>) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onMediaGroup(
|
||||
initialFilter: SimpleFilter<List<MediaGroupMessage<MediaGroupContent>>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<MediaGroupContent>>, Update>? = MessagesFilterByChat,
|
||||
markerFactory: MarkerFactory<in List<MediaGroupMessage<MediaGroupContent>>, Any> = ByChatMediaGroupMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<MediaGroupContent>>>
|
||||
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onPlaylist(
|
||||
initialFilter: SimpleFilter<List<MediaGroupMessage<AudioMediaGroupContent>>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<AudioMediaGroupContent>>, Update>? = MessagesFilterByChat,
|
||||
markerFactory: MarkerFactory<in List<MediaGroupMessage<AudioMediaGroupContent>>, Any> = ByChatMediaGroupMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<AudioMediaGroupContent>>>
|
||||
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onDocumentsGroup(
|
||||
initialFilter: SimpleFilter<List<MediaGroupMessage<DocumentMediaGroupContent>>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<DocumentMediaGroupContent>>, Update>? = MessagesFilterByChat,
|
||||
markerFactory: MarkerFactory<in List<MediaGroupMessage<DocumentMediaGroupContent>>, Any> = ByChatMediaGroupMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<DocumentMediaGroupContent>>>
|
||||
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onVisualGallery(
|
||||
initialFilter: SimpleFilter<List<MediaGroupMessage<VisualMediaGroupContent>>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<VisualMediaGroupContent>>, Update>? = MessagesFilterByChat,
|
||||
markerFactory: MarkerFactory<in List<MediaGroupMessage<VisualMediaGroupContent>>, Any> = ByChatMediaGroupMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<VisualMediaGroupContent>>>
|
||||
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onVisualMediaGroup(
|
||||
initialFilter: SimpleFilter<List<MediaGroupMessage<VisualMediaGroupContent>>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<VisualMediaGroupContent>>, Update>? = MessagesFilterByChat,
|
||||
markerFactory: MarkerFactory<in List<MediaGroupMessage<VisualMediaGroupContent>>, Any> = ByChatMediaGroupMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<VisualMediaGroupContent>>>
|
||||
) = onVisualGallery(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onPhotoGallery(
|
||||
initialFilter: SimpleFilter<List<MediaGroupMessage<PhotoContent>>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<PhotoContent>>, Update>? = MessagesFilterByChat,
|
||||
markerFactory: MarkerFactory<in List<MediaGroupMessage<PhotoContent>>, Any> = ByChatMediaGroupMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<PhotoContent>>>
|
||||
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onVideoGallery(
|
||||
initialFilter: SimpleFilter<List<MediaGroupMessage<VideoContent>>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<VideoContent>>, Update>? = MessagesFilterByChat,
|
||||
markerFactory: MarkerFactory<in List<MediaGroupMessage<VideoContent>>, Any> = ByChatMediaGroupMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<VideoContent>>>
|
||||
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
@@ -0,0 +1,47 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.asPassportMessage
|
||||
import dev.inmo.tgbotapi.types.message.PassportMessage
|
||||
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElement
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
internal suspend inline fun <BC : BehaviourContext, reified T : EncryptedPassportElement> BC.onPassportMessageWith(
|
||||
noinline initialFilter: SimpleFilter<PassportMessage>? = null,
|
||||
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, PassportMessage, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in PassportMessage, Any> = ByChatMessageMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PassportMessage>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asMessageUpdate() ?.data ?.asPassportMessage() ?.takeIf { it.passportData.data.any { it is T } }) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onPassportMessage(
|
||||
initialFilter: SimpleFilter<PassportMessage>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, PassportMessage, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in PassportMessage, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PassportMessage>
|
||||
) = onPassportMessageWith<BC, EncryptedPassportElement>(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
@@ -0,0 +1,44 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.*
|
||||
import dev.inmo.tgbotapi.extensions.utils.asPollAnswerUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.asPollUpdate
|
||||
import dev.inmo.tgbotapi.types.polls.*
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
internal suspend inline fun <BC : BehaviourContext> BC.onPollAnswered(
|
||||
noinline initialFilter: SimpleFilter<PollAnswer>? = null,
|
||||
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, PollAnswer, Update>? = null,
|
||||
markerFactory: MarkerFactory<in PollAnswer, Any> = ByIdPollAnswerMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PollAnswer>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asPollAnswerUpdate() ?.data) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onPollAnswer(
|
||||
initialFilter: SimpleFilter<PollAnswer>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, PollAnswer, Update>? = null,
|
||||
markerFactory: MarkerFactory<in PollAnswer, Any> = ByIdPollAnswerMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PollAnswer>
|
||||
) = onPollAnswered(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
@@ -0,0 +1,91 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.*
|
||||
import dev.inmo.tgbotapi.extensions.utils.asPollUpdate
|
||||
import dev.inmo.tgbotapi.types.polls.*
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
internal suspend inline fun <BC : BehaviourContext, reified T : Poll> BC.onPollUpdatedBase(
|
||||
noinline initialFilter: SimpleFilter<T>? = null,
|
||||
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, T, Update>? = null,
|
||||
markerFactory: MarkerFactory<in T, Any> = ByIdPollMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, T>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asPollUpdate() ?.data as? T) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onPollUpdates(
|
||||
initialFilter: SimpleFilter<Poll>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, Poll, Update>? = null,
|
||||
markerFactory: MarkerFactory<in Poll, Any> = ByIdPollMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, Poll>
|
||||
) = onPollUpdatedBase(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onRegularPollUpdates(
|
||||
initialFilter: SimpleFilter<RegularPoll>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, RegularPoll, Update>? = null,
|
||||
markerFactory: MarkerFactory<in RegularPoll, Any> = ByIdPollMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, RegularPoll>
|
||||
) = onPollUpdatedBase(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onQuizPollUpdates(
|
||||
initialFilter: SimpleFilter<QuizPoll>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, QuizPoll, Update>? = null,
|
||||
markerFactory: MarkerFactory<in QuizPoll, Any> = ByIdPollMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, QuizPoll>
|
||||
) = onPollUpdatedBase(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
@@ -0,0 +1,36 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.*
|
||||
import dev.inmo.tgbotapi.extensions.utils.asPreCheckoutQueryUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.asShippingQueryUpdate
|
||||
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
|
||||
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
/**
|
||||
* Please, remember that you must answer to this type of queries using something like
|
||||
* [dev.inmo.tgbotapi.extensions.api.answers.payments.answerPreCheckoutQueryOk] or
|
||||
* [dev.inmo.tgbotapi.extensions.api.answers.payments.answerPreCheckoutQueryError]
|
||||
*
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onPreCheckoutQuery(
|
||||
initialFilter: SimpleFilter<PreCheckoutQuery>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, PreCheckoutQuery, Update>? = PreCheckoutQueryFilterByUser,
|
||||
markerFactory: MarkerFactory<in PreCheckoutQuery, Any> = ByUserPreCheckoutQueryMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PreCheckoutQuery>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asPreCheckoutQueryUpdate() ?.data) ?.let(::listOfNotNull)
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CallbackQueryFilterByUser
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.ShippingQueryFilterByUser
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.*
|
||||
import dev.inmo.tgbotapi.extensions.utils.asShippingQueryUpdate
|
||||
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
/**
|
||||
* Please, remember that you must answer to this type of queries using something like
|
||||
* [dev.inmo.tgbotapi.extensions.api.answers.payments.answerShippingQueryOk] or
|
||||
* [dev.inmo.tgbotapi.extensions.api.answers.payments.answerShippingQueryError]
|
||||
*
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onShippingQuery(
|
||||
initialFilter: SimpleFilter<ShippingQuery>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ShippingQuery, Update>? = ShippingQueryFilterByUser,
|
||||
markerFactory: MarkerFactory<in ShippingQuery, Any> = ByUserShippingQueryMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ShippingQuery>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asShippingQueryUpdate() ?.data) ?.let(::listOfNotNull)
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTypeReceiver
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitEditedLocation
|
||||
import dev.inmo.tgbotapi.types.location.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.LiveLocationContent
|
||||
|
||||
/**
|
||||
* Use this extension when you want to follow [LiveLocation] until it will became [StaticLocation]. This method
|
||||
* is synchronous. You may use something like [kotlinx.coroutines.launch] or [kotlinx.coroutines.async] to run it
|
||||
* asynchronously
|
||||
*/
|
||||
suspend fun BehaviourContext.followLocation(
|
||||
message: ContentMessage<LiveLocationContent>,
|
||||
onLocation: BehaviourContextAndTypeReceiver<Unit, Location>
|
||||
) {
|
||||
var currentLocation: Location = message.content.location
|
||||
onLocation(message.content.location)
|
||||
|
||||
while (currentLocation !is StaticLocation) {
|
||||
currentLocation = waitEditedLocation(
|
||||
filter = {
|
||||
it.messageId == message.messageId && it.chat.id == message.chat.id
|
||||
}
|
||||
).first().location
|
||||
onLocation(currentLocation)
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils
|
||||
|
||||
typealias SimpleFilter<T> = suspend (T) -> Boolean
|
||||
|
||||
inline fun <T> SimpleFilter(noinline block: SimpleFilter<T>) = block
|
||||
|
||||
/**
|
||||
* Makes an AND (&&) operation between [this] and [other]
|
||||
*/
|
||||
operator fun <T> SimpleFilter<T>.times(other: SimpleFilter<T>): SimpleFilter<T> = {
|
||||
this(it) && other(it)
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an OR (||) operation between [this] and [other]
|
||||
*/
|
||||
operator fun <T> SimpleFilter<T>.plus(other: SimpleFilter<T>): SimpleFilter<T> = {
|
||||
this(it) || other(it)
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse results of [this]
|
||||
*/
|
||||
operator fun <T> SimpleFilter<T>.not(): SimpleFilter<T> = {
|
||||
!this(it)
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
/**
|
||||
* Makes an OR (||) operation between [this] and [other]
|
||||
*/
|
||||
operator fun <T> (BehaviourContextAndTwoTypesReceiver<Boolean, T, Update>).plus(
|
||||
other: BehaviourContextAndTwoTypesReceiver<Boolean, T, Update>
|
||||
) = BehaviourContextAndTwoTypesReceiver<Boolean, T, Update> { t, update ->
|
||||
this@plus(t, update) || other(t, update)
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an AND (&&) operation between [this] and [other]
|
||||
*/
|
||||
operator fun <T> (BehaviourContextAndTwoTypesReceiver<Boolean, T, Update>).times(
|
||||
other: BehaviourContextAndTwoTypesReceiver<Boolean, T, Update>
|
||||
) = BehaviourContextAndTwoTypesReceiver<Boolean, T, Update> { t, update ->
|
||||
this@times(t, update) && other(t, update)
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse results of [this]
|
||||
*/
|
||||
operator fun <T> (BehaviourContextAndTwoTypesReceiver<Boolean, T, Update>).not() = BehaviourContextAndTwoTypesReceiver<Boolean, T, Update> { t, update ->
|
||||
!this@not(t, update)
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
|
||||
|
||||
import dev.inmo.tgbotapi.types.ChatMemberUpdated
|
||||
|
||||
object ByChatChatMemberUpdatedMarkerFactory : MarkerFactory<ChatMemberUpdated, Any> {
|
||||
override suspend fun invoke(data: ChatMemberUpdated) = data.chat
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
|
||||
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.ChosenInlineResult
|
||||
|
||||
|
||||
object ByUserIdChosenInlineResultMarkerFactory : MarkerFactory<ChosenInlineResult, Any> {
|
||||
override suspend fun invoke(data: ChosenInlineResult) = data.user.id
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
|
||||
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery
|
||||
|
||||
object ByUserInlineQueryMarkerFactory : MarkerFactory<InlineQuery, Any> {
|
||||
override suspend fun invoke(data: InlineQuery) = data.from
|
||||
}
|
||||
|
||||
object ByIdInlineQueryMarkerFactory : MarkerFactory<InlineQuery, Any> {
|
||||
override suspend fun invoke(data: InlineQuery) = data.id
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
|
||||
|
||||
fun interface MarkerFactory<T, M> {
|
||||
suspend operator fun invoke(data: T): M
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
||||
|
||||
object ByChatMediaGroupMarkerFactory : MarkerFactory<List<MediaGroupMessage<*>>, Any> {
|
||||
override suspend fun invoke(data: List<MediaGroupMessage<*>>) = data.chat ?: error("Data must not be empty")
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
|
||||
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||
|
||||
object ByChatMessageMarkerFactory : MarkerFactory<Message, Any> {
|
||||
override suspend fun invoke(data: Message) = data.chat
|
||||
}
|
||||
|
||||
object ByUserMessageMarkerFactory : MarkerFactory<Message, Any> {
|
||||
override suspend fun invoke(data: Message) = when (data) {
|
||||
is FromUserMessage -> data.user
|
||||
is FromChannelGroupContentMessage<*> -> data.channel
|
||||
else -> data.chat // including anonymous
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
|
||||
|
||||
import dev.inmo.tgbotapi.types.polls.Poll
|
||||
import dev.inmo.tgbotapi.types.polls.PollAnswer
|
||||
|
||||
object ByIdPollMarkerFactory : MarkerFactory<Poll, Any> {
|
||||
override suspend fun invoke(data: Poll) = data.id
|
||||
}
|
||||
|
||||
object ByIdPollAnswerMarkerFactory : MarkerFactory<PollAnswer, Any> {
|
||||
override suspend fun invoke(data: PollAnswer) = data.pollId
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
|
||||
|
||||
import dev.inmo.tgbotapi.types.CallbackQuery.CallbackQuery
|
||||
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
|
||||
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
||||
|
||||
object ByUserCallbackQueryMarkerFactory : MarkerFactory<CallbackQuery, Any> {
|
||||
override suspend fun invoke(data: CallbackQuery) = data.user
|
||||
}
|
||||
|
||||
object ByUserShippingQueryMarkerFactory : MarkerFactory<ShippingQuery, Any> {
|
||||
override suspend fun invoke(data: ShippingQuery) = data.user
|
||||
}
|
||||
|
||||
object ByUserPreCheckoutQueryMarkerFactory : MarkerFactory<PreCheckoutQuery, Any> {
|
||||
override suspend fun invoke(data: PreCheckoutQuery) = data.user
|
||||
}
|
||||
|
||||
object ByIdCallbackQueryMarkerFactory : MarkerFactory<CallbackQuery, Any> {
|
||||
override suspend fun invoke(data: CallbackQuery) = data.id
|
||||
}
|
||||
|
||||
object ByChatInstanceCallbackQueryMarkerFactory : MarkerFactory<CallbackQuery, Any> {
|
||||
override suspend fun invoke(data: CallbackQuery) = data.chatInstance
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,8 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
||||
actual var defaultCoroutineScopeProvider = {
|
||||
CoroutineScope(Dispatchers.Default)
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
||||
actual var defaultCoroutineScopeProvider = {
|
||||
CoroutineScope(Dispatchers.IO)
|
||||
}
|
Reference in New Issue
Block a user