mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
removing of filters for the wait triggers
This commit is contained in:
parent
95a466a08b
commit
e7aec75aca
@ -5,6 +5,8 @@
|
|||||||
* `Behaviour Builder`:
|
* `Behaviour Builder`:
|
||||||
* Mappers have been removed from waiters extensions
|
* Mappers have been removed from waiters extensions
|
||||||
* Triggers extensions now will use filtering inside of context receiver instead of passing the filters into `BehaviourContext`. That means that in the subcontext will not be used preinstalled filters for their `BehaviourContext` and filter of trigger will not be used in subcontext
|
* Triggers extensions now will use filtering inside of context receiver instead of passing the filters into `BehaviourContext`. That means that in the subcontext will not be used preinstalled filters for their `BehaviourContext` and filter of trigger will not be used in subcontext
|
||||||
|
* Waiters do not take count parameter anymore
|
||||||
|
* Waiters do not take filter parameter anymore. Use flows filters
|
||||||
* `Utils`:
|
* `Utils`:
|
||||||
* Add opportunity to get event messages with specific `ChatEvent` type using `withEvent`/`requireWithEvent` (by analog with `withEvent` and `requireWithEvent`)
|
* Add opportunity to get event messages with specific `ChatEvent` type using `withEvent`/`requireWithEvent` (by analog with `withEvent` and `requireWithEvent`)
|
||||||
|
|
||||||
|
@ -47,10 +47,26 @@ interface BehaviourContextWithFSM<T : State> : BehaviourContext, StatesMachine<T
|
|||||||
broadcastChannelsSize: Int,
|
broadcastChannelsSize: Int,
|
||||||
onBufferOverflow: BufferOverflow,
|
onBufferOverflow: BufferOverflow,
|
||||||
upstreamUpdatesFlow: Flow<Update>?,
|
upstreamUpdatesFlow: Flow<Update>?,
|
||||||
triggersHolder: TriggersHolder,
|
triggersHolder: TriggersHolder
|
||||||
updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>?
|
|
||||||
): BehaviourContextWithFSM<T>
|
): BehaviourContextWithFSM<T>
|
||||||
|
|
||||||
|
fun copy(
|
||||||
|
bot: TelegramBot = this.bot,
|
||||||
|
scope: CoroutineScope = this.scope,
|
||||||
|
broadcastChannelsSize: Int = 100,
|
||||||
|
onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND,
|
||||||
|
upstreamUpdatesFlow: Flow<Update>? = null,
|
||||||
|
triggersHolder: TriggersHolder = this.triggersHolder,
|
||||||
|
onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler()
|
||||||
|
): BehaviourContextWithFSM<T> = copy(
|
||||||
|
bot,
|
||||||
|
scope,
|
||||||
|
broadcastChannelsSize,
|
||||||
|
onBufferOverflow,
|
||||||
|
upstreamUpdatesFlow,
|
||||||
|
triggersHolder
|
||||||
|
)
|
||||||
|
|
||||||
fun copy(
|
fun copy(
|
||||||
bot: TelegramBot = this.bot,
|
bot: TelegramBot = this.bot,
|
||||||
scope: CoroutineScope = this.scope,
|
scope: CoroutineScope = this.scope,
|
||||||
@ -67,7 +83,7 @@ interface BehaviourContextWithFSM<T : State> : BehaviourContext, StatesMachine<T
|
|||||||
onBufferOverflow,
|
onBufferOverflow,
|
||||||
upstreamUpdatesFlow,
|
upstreamUpdatesFlow,
|
||||||
triggersHolder,
|
triggersHolder,
|
||||||
updatesFilter
|
onStateHandlingErrorHandler
|
||||||
)
|
)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@ -196,10 +212,9 @@ class DefaultBehaviourContextWithFSM<T : State>(
|
|||||||
broadcastChannelsSize: Int,
|
broadcastChannelsSize: Int,
|
||||||
onBufferOverflow: BufferOverflow,
|
onBufferOverflow: BufferOverflow,
|
||||||
upstreamUpdatesFlow: Flow<Update>?,
|
upstreamUpdatesFlow: Flow<Update>?,
|
||||||
triggersHolder: TriggersHolder,
|
triggersHolder: TriggersHolder
|
||||||
updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>?
|
|
||||||
): DefaultBehaviourContextWithFSM<T> = BehaviourContextWithFSM(
|
): DefaultBehaviourContextWithFSM<T> = BehaviourContextWithFSM(
|
||||||
behaviourContext.copy(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, triggersHolder, updatesFilter),
|
behaviourContext.copy(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, triggersHolder),
|
||||||
handlers,
|
handlers,
|
||||||
statesManager,
|
statesManager,
|
||||||
onStateHandlingErrorHandler
|
onStateHandlingErrorHandler
|
||||||
@ -212,10 +227,9 @@ class DefaultBehaviourContextWithFSM<T : State>(
|
|||||||
onBufferOverflow: BufferOverflow,
|
onBufferOverflow: BufferOverflow,
|
||||||
upstreamUpdatesFlow: Flow<Update>?,
|
upstreamUpdatesFlow: Flow<Update>?,
|
||||||
triggersHolder: TriggersHolder,
|
triggersHolder: TriggersHolder,
|
||||||
onStateHandlingErrorHandler: StateHandlingErrorHandler<T>,
|
onStateHandlingErrorHandler: StateHandlingErrorHandler<T>
|
||||||
updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>?
|
|
||||||
): DefaultBehaviourContextWithFSM<T> = BehaviourContextWithFSM(
|
): DefaultBehaviourContextWithFSM<T> = BehaviourContextWithFSM(
|
||||||
behaviourContext.copy(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, triggersHolder, updatesFilter),
|
behaviourContext.copy(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, triggersHolder),
|
||||||
handlers,
|
handlers,
|
||||||
statesManager,
|
statesManager,
|
||||||
onStateHandlingErrorHandler
|
onStateHandlingErrorHandler
|
||||||
|
@ -4,7 +4,7 @@ import dev.inmo.micro_utils.coroutines.safelyWithResult
|
|||||||
import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions
|
||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.utils.flatMap
|
import dev.inmo.tgbotapi.extensions.utils.flatten
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
|
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
|
||||||
@ -20,7 +20,6 @@ typealias NullableRequestBuilder<T> = suspend (Update) -> Request<T>?
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param initRequest If not null, this request will be sent by [bot] before returning value
|
* @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 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
|
* @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
|
* user that chain of scenario has been cancelled
|
||||||
@ -33,7 +32,6 @@ typealias NullableRequestBuilder<T> = suspend (Update) -> Request<T>?
|
|||||||
suspend fun <T> FlowsUpdatesFilter.expectFlow(
|
suspend fun <T> FlowsUpdatesFilter.expectFlow(
|
||||||
bot: TelegramBot,
|
bot: TelegramBot,
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
count: Int? = null,
|
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
cancelRequestFactory: NullableRequestBuilder<*> = { null },
|
cancelRequestFactory: NullableRequestBuilder<*> = { null },
|
||||||
cancelTrigger: suspend (Update) -> Boolean = { cancelRequestFactory(it) != null },
|
cancelTrigger: suspend (Update) -> Boolean = { cancelRequestFactory(it) != null },
|
||||||
@ -55,19 +53,13 @@ suspend fun <T> FlowsUpdatesFilter.expectFlow(
|
|||||||
} else {
|
} else {
|
||||||
result.getOrThrow()
|
result.getOrThrow()
|
||||||
}
|
}
|
||||||
}.flatMap()
|
}.flatten()
|
||||||
val result = if (count == null) {
|
|
||||||
flow
|
|
||||||
} else {
|
|
||||||
flow.take(count)
|
|
||||||
}
|
|
||||||
initRequest ?.also { safelyWithoutExceptions { bot.execute(initRequest) } }
|
initRequest ?.also { safelyWithoutExceptions { bot.execute(initRequest) } }
|
||||||
return result
|
return flow
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param initRequest If not null, this request will be sent by [bot] before returning value
|
* @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 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
|
* @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
|
* user that chain of scenario has been cancelled
|
||||||
@ -76,14 +68,14 @@ suspend fun <T> FlowsUpdatesFilter.expectFlow(
|
|||||||
* as is, but when it returns null, then will be called [cancelTrigger] (if it will return true - [cancelRequestFactory]
|
* 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
|
* will be called too), [errorFactory] and then will be returned null
|
||||||
*/
|
*/
|
||||||
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
suspend fun <T> BehaviourContext.expectFlow(
|
suspend fun <T> BehaviourContext.expectFlow(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
count: Int? = null,
|
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
cancelRequestFactory: NullableRequestBuilder<*> = { null },
|
cancelRequestFactory: NullableRequestBuilder<*> = { null },
|
||||||
cancelTrigger: suspend (Update) -> Boolean = { cancelRequestFactory(it) != null },
|
cancelTrigger: suspend (Update) -> Boolean = { cancelRequestFactory(it) != null },
|
||||||
filter: suspend (Update) -> List<T>
|
filter: suspend (Update) -> List<T>
|
||||||
) = flowsUpdatesFilter.expectFlow(bot, initRequest, count, errorFactory, cancelRequestFactory, cancelTrigger, filter)
|
) = flowsUpdatesFilter.expectFlow(bot, initRequest, errorFactory, cancelRequestFactory, cancelTrigger, filter)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param initRequest If not null, this request will be sent by [bot] before returning value
|
* @param initRequest If not null, this request will be sent by [bot] before returning value
|
||||||
@ -103,7 +95,7 @@ suspend fun <T> FlowsUpdatesFilter.expectOne(
|
|||||||
cancelRequestFactory: NullableRequestBuilder<*> = { null },
|
cancelRequestFactory: NullableRequestBuilder<*> = { null },
|
||||||
cancelTrigger: suspend (Update) -> Boolean = { cancelRequestFactory(it) != null },
|
cancelTrigger: suspend (Update) -> Boolean = { cancelRequestFactory(it) != null },
|
||||||
filter: suspend (Update) -> T?
|
filter: suspend (Update) -> T?
|
||||||
): T = expectFlow(bot, initRequest, 1, errorFactory, cancelRequestFactory, cancelTrigger) {
|
): T = expectFlow(bot, initRequest, errorFactory, cancelRequestFactory, cancelTrigger) {
|
||||||
listOfNotNull(filter.invoke(it))
|
listOfNotNull(filter.invoke(it))
|
||||||
}.first()
|
}.first()
|
||||||
|
|
||||||
@ -117,6 +109,7 @@ suspend fun <T> FlowsUpdatesFilter.expectOne(
|
|||||||
* as is, but when it returns null, then will be called [cancelTrigger] (if it will return true - [cancelRequestFactory]
|
* 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
|
* will be called too), [errorFactory] and then will be returned null
|
||||||
*/
|
*/
|
||||||
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
suspend fun <T> BehaviourContext.expectOne(
|
suspend fun <T> BehaviourContext.expectOne(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
@ -7,80 +7,58 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
|||||||
import dev.inmo.tgbotapi.extensions.utils.asCallbackQueryUpdate
|
import dev.inmo.tgbotapi.extensions.utils.asCallbackQueryUpdate
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.queries.callback.*
|
import dev.inmo.tgbotapi.types.queries.callback.*
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
import kotlinx.coroutines.flow.toList
|
||||||
|
|
||||||
typealias CallbackQueryMapper<T> = suspend T.() -> T?
|
typealias CallbackQueryMapper<T> = suspend T.() -> T?
|
||||||
|
|
||||||
private suspend inline fun <reified O> BehaviourContext.waitCallbackQueries(
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
count: Int = 1,
|
suspend inline fun <reified O> BehaviourContext.waitCallbackQueries(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
filter: SimpleFilter<O>? = null
|
): Flow<O> = expectFlow(
|
||||||
): List<O> = expectFlow(
|
|
||||||
initRequest,
|
initRequest,
|
||||||
count,
|
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
val data = it.asCallbackQueryUpdate() ?.data ?: return@expectFlow emptyList()
|
(it.asCallbackQueryUpdate() ?.data as O).let(::listOfNotNull)
|
||||||
if (data is O && (filter == null || filter(data))) {
|
|
||||||
listOf(data)
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
}
|
||||||
}.toList().toList()
|
|
||||||
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitDataCallbackQuery(
|
suspend fun BehaviourContext.waitDataCallbackQuery(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitCallbackQueries<DataCallbackQuery>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<DataCallbackQuery>? = null
|
|
||||||
) = waitCallbackQueries(count, initRequest, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitGameShortNameCallbackQuery(
|
suspend fun BehaviourContext.waitGameShortNameCallbackQuery(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitCallbackQueries<GameShortNameCallbackQuery>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<GameShortNameCallbackQuery>? = null
|
|
||||||
) = waitCallbackQueries(count, initRequest, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitInlineMessageIdCallbackQuery(
|
suspend fun BehaviourContext.waitInlineMessageIdCallbackQuery(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitCallbackQueries<InlineMessageIdCallbackQuery>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<InlineMessageIdCallbackQuery>? = null
|
|
||||||
) = waitCallbackQueries(count, initRequest, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitInlineMessageIdDataCallbackQuery(
|
suspend fun BehaviourContext.waitInlineMessageIdDataCallbackQuery(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitCallbackQueries<InlineMessageIdDataCallbackQuery>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<InlineMessageIdDataCallbackQuery>? = null
|
|
||||||
) = waitCallbackQueries(count, initRequest, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitInlineMessageIdGameShortNameCallbackQuery(
|
suspend fun BehaviourContext.waitInlineMessageIdGameShortNameCallbackQuery(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitCallbackQueries<InlineMessageIdGameShortNameCallbackQuery>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<InlineMessageIdGameShortNameCallbackQuery>? = null
|
|
||||||
) = waitCallbackQueries(count, initRequest, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitMessageCallbackQuery(
|
suspend fun BehaviourContext.waitMessageCallbackQuery(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitCallbackQueries<MessageCallbackQuery>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<MessageCallbackQuery>? = null
|
|
||||||
) = waitCallbackQueries(count, initRequest, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitMessageDataCallbackQuery(
|
suspend fun BehaviourContext.waitMessageDataCallbackQuery(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitCallbackQueries<MessageDataCallbackQuery>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<MessageDataCallbackQuery>? = null
|
|
||||||
) = waitCallbackQueries(count, initRequest, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitMessageGameShortNameCallbackQuery(
|
suspend fun BehaviourContext.waitMessageGameShortNameCallbackQuery(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitCallbackQueries<MessageGameShortNameCallbackQuery>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<MessageGameShortNameCallbackQuery>? = null
|
|
||||||
) = waitCallbackQueries(count, initRequest, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitUnknownCallbackQuery(
|
suspend fun BehaviourContext.waitUnknownCallbackQuery(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitCallbackQueries<UnknownCallbackQueryType>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<UnknownCallbackQueryType>? = null
|
|
||||||
) = waitCallbackQueries(count, initRequest, errorFactory, filter)
|
|
||||||
|
@ -5,37 +5,29 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
|||||||
import dev.inmo.tgbotapi.extensions.utils.asChatJoinRequestUpdate
|
import dev.inmo.tgbotapi.extensions.utils.asChatJoinRequestUpdate
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.chat.ChatJoinRequest
|
import dev.inmo.tgbotapi.types.chat.ChatJoinRequest
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
import kotlinx.coroutines.flow.toList
|
||||||
|
|
||||||
typealias ChatJoinRequestsMapper = suspend ChatJoinRequest.() -> ChatJoinRequest?
|
typealias ChatJoinRequestsMapper = suspend ChatJoinRequest.() -> ChatJoinRequest?
|
||||||
|
|
||||||
private suspend inline fun <reified O> BehaviourContext.internalWaitChatJoinRequests(
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
count: Int = 1,
|
suspend inline fun <reified O> BehaviourContext.internalWaitChatJoinRequests(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
filter: SimpleFilter<O>? = null
|
): Flow<O> = expectFlow(
|
||||||
): List<O> = expectFlow(
|
|
||||||
initRequest,
|
initRequest,
|
||||||
count,
|
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
val data = it.asChatJoinRequestUpdate() ?.data as? O ?: return@expectFlow emptyList()
|
(it.asChatJoinRequestUpdate() ?.data as? O).let(::listOfNotNull)
|
||||||
if (filter == null || filter(data)) {
|
|
||||||
listOf(data)
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
}
|
||||||
}.toList().toList()
|
|
||||||
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitChatJoinRequests(
|
suspend fun BehaviourContext.waitChatJoinRequests(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) : Flow<ChatJoinRequest> = internalWaitChatJoinRequests(
|
||||||
filter: SimpleFilter<ChatJoinRequest>? = null
|
|
||||||
) : List<ChatJoinRequest> = internalWaitChatJoinRequests(
|
|
||||||
count,
|
|
||||||
initRequest,
|
initRequest,
|
||||||
errorFactory,
|
errorFactory
|
||||||
filter
|
|
||||||
)
|
)
|
||||||
|
@ -7,45 +7,35 @@ import dev.inmo.tgbotapi.types.chat.member.ChatMemberUpdated
|
|||||||
import dev.inmo.tgbotapi.types.update.CommonChatMemberUpdatedUpdate
|
import dev.inmo.tgbotapi.types.update.CommonChatMemberUpdatedUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.MyChatMemberUpdatedUpdate
|
import dev.inmo.tgbotapi.types.update.MyChatMemberUpdatedUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
import kotlinx.coroutines.flow.toList
|
||||||
|
|
||||||
typealias ChatMemberUpdatedMapper<T> = suspend T.() -> T?
|
typealias ChatMemberUpdatedMapper<T> = suspend T.() -> T?
|
||||||
|
|
||||||
private suspend inline fun <reified T : ChatMemberUpdatedUpdate> BehaviourContext.waitChatMemberUpdatedWithFilter(
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
count: Int = 1,
|
suspend inline fun <reified O : ChatMemberUpdatedUpdate> BehaviourContext.waitChatMemberUpdatedWithFilter(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
filter: SimpleFilter<T>? = null
|
): Flow<ChatMemberUpdated> = expectFlow(
|
||||||
): List<ChatMemberUpdated> = expectFlow(
|
|
||||||
initRequest,
|
initRequest,
|
||||||
count,
|
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
val casted = (it as? T) ?: return@expectFlow emptyList()
|
(it as? O) ?.data.let(::listOfNotNull)
|
||||||
if (filter == null || filter(casted)) {
|
|
||||||
listOf(casted.data)
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
}
|
||||||
}.toList().toList()
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitChatMemberUpdated(
|
suspend fun BehaviourContext.waitChatMemberUpdated(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
) = waitChatMemberUpdatedWithFilter<ChatMemberUpdatedUpdate>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatMemberUpdatedUpdate>? = null
|
|
||||||
) = waitChatMemberUpdatedWithFilter(count, initRequest, errorFactory, filter)
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitCommonChatMemberUpdated(
|
suspend fun BehaviourContext.waitCommonChatMemberUpdated(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
) = waitChatMemberUpdatedWithFilter<CommonChatMemberUpdatedUpdate>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<CommonChatMemberUpdatedUpdate>? = null
|
|
||||||
) = waitChatMemberUpdatedWithFilter(count, initRequest, errorFactory, filter)
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitMyChatMemberUpdated(
|
suspend fun BehaviourContext.waitMyChatMemberUpdated(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitChatMemberUpdatedWithFilter<MyChatMemberUpdatedUpdate>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<MyChatMemberUpdatedUpdate>? = null
|
|
||||||
) = waitChatMemberUpdatedWithFilter(count, initRequest, errorFactory, filter)
|
|
||||||
|
@ -5,45 +5,35 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
|||||||
import dev.inmo.tgbotapi.extensions.utils.asChosenInlineResultUpdate
|
import dev.inmo.tgbotapi.extensions.utils.asChosenInlineResultUpdate
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.*
|
import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.*
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
import kotlinx.coroutines.flow.toList
|
||||||
|
|
||||||
typealias ChosenInlineResultMapper<T> = suspend T.() -> T?
|
typealias ChosenInlineResultMapper<T> = suspend T.() -> T?
|
||||||
|
|
||||||
private suspend inline fun <reified O> BehaviourContext.waitChosenInlineResults(
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
count: Int = 1,
|
suspend inline fun <reified O> BehaviourContext.waitChosenInlineResults(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
filter: SimpleFilter<O>? = null
|
): Flow<O> = expectFlow(
|
||||||
): List<O> = expectFlow(
|
|
||||||
initRequest,
|
initRequest,
|
||||||
count,
|
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
val data = it.asChosenInlineResultUpdate() ?.data as? O ?: return@expectFlow emptyList()
|
(it.asChosenInlineResultUpdate() ?.data as? O).let(::listOfNotNull)
|
||||||
if (filter == null || filter(data)) {
|
|
||||||
listOf(data)
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
}
|
||||||
}.toList().toList()
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitChosenInlineResult(
|
suspend fun BehaviourContext.waitChosenInlineResult(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitChosenInlineResults<ChosenInlineResult>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChosenInlineResult>? = null
|
|
||||||
) = waitChosenInlineResults(count, initRequest, errorFactory, filter)
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitLocationChosenInlineResult(
|
suspend fun BehaviourContext.waitLocationChosenInlineResult(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitChosenInlineResults<LocationChosenInlineResult>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<LocationChosenInlineResult>? = null
|
|
||||||
) = waitChosenInlineResults(count, initRequest, errorFactory, filter)
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitBaseChosenInlineResult(
|
suspend fun BehaviourContext.waitBaseChosenInlineResult(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitChosenInlineResults<BaseChosenInlineResult>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<BaseChosenInlineResult>? = null
|
|
||||||
) = waitChosenInlineResults(count, initRequest, errorFactory, filter)
|
|
||||||
|
@ -15,201 +15,129 @@ import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
|
|||||||
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
|
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
|
||||||
typealias CommonMessageToContentMapper<T> = suspend CommonMessage<T>.() -> T?
|
typealias CommonMessageToContentMapper<T> = suspend CommonMessage<T>.() -> T?
|
||||||
|
|
||||||
private suspend inline fun <reified O : MessageContent> BehaviourContext.waitContent(
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
count: Int = 1,
|
suspend inline fun <reified O : MessageContent> BehaviourContext.waitContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
includeMediaGroups: Boolean = true,
|
includeMediaGroups: Boolean = true,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
filter: SimpleFilter<CommonMessage<O>>? = null
|
): Flow<O> = waitContentMessage<O>(initRequest, includeMediaGroups, errorFactory).map { it.content }
|
||||||
): Flow<O> = expectFlow(
|
|
||||||
initRequest,
|
|
||||||
count,
|
|
||||||
errorFactory
|
|
||||||
) {
|
|
||||||
val messages = when (it) {
|
|
||||||
is SentMediaGroupUpdate -> {
|
|
||||||
if (includeMediaGroups) {
|
|
||||||
it.data
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is BaseSentMessageUpdate -> listOf(it.data)
|
|
||||||
else -> return@expectFlow emptyList()
|
|
||||||
}
|
|
||||||
messages.mapNotNull { message ->
|
|
||||||
val asCommonMessage = (message as CommonMessage<*>).withContent<O>() ?: return@mapNotNull null
|
|
||||||
if (filter == null || filter(asCommonMessage)) {
|
|
||||||
asCommonMessage.content
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitContent(
|
suspend fun BehaviourContext.waitContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = true
|
||||||
includeMediaGroups: Boolean = true,
|
) = waitContent<MessageContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<MessageContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitContact(
|
suspend fun BehaviourContext.waitContact(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContent<ContactContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<ContactContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitDice(
|
suspend fun BehaviourContext.waitDice(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContent<DiceContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<DiceContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitGame(
|
suspend fun BehaviourContext.waitGame(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContent<GameContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<GameContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitLocation(
|
suspend fun BehaviourContext.waitLocation(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContent<LocationContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<LocationContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitLiveLocation(
|
suspend fun BehaviourContext.waitLiveLocation(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContent<LiveLocationContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<LiveLocationContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitStaticLocation(
|
suspend fun BehaviourContext.waitStaticLocation(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContent<StaticLocationContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<StaticLocationContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitPoll(
|
suspend fun BehaviourContext.waitPoll(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContent<PollContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<PollContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitText(
|
suspend fun BehaviourContext.waitText(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContent<TextContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<TextContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitVenue(
|
suspend fun BehaviourContext.waitVenue(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContent<VenueContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<VenueContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitAudioMediaGroupContent(
|
suspend fun BehaviourContext.waitAudioMediaGroupContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = true
|
||||||
includeMediaGroups: Boolean = true,
|
) = waitContent<AudioMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<AudioMediaGroupContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitDocumentMediaGroupContent(
|
suspend fun BehaviourContext.waitDocumentMediaGroupContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = true
|
||||||
includeMediaGroups: Boolean = true,
|
) = waitContent<DocumentMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<DocumentMediaGroupContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitMedia(
|
suspend fun BehaviourContext.waitMedia(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = false
|
||||||
includeMediaGroups: Boolean = false,
|
) = waitContent<MediaContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<MediaContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitAnyMediaGroupContent(
|
suspend fun BehaviourContext.waitAnyMediaGroupContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = true
|
||||||
includeMediaGroups: Boolean = true,
|
) = waitContent<MediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<MediaGroupContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitVisualMediaGroupContent(
|
suspend fun BehaviourContext.waitVisualMediaGroupContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = true
|
||||||
includeMediaGroups: Boolean = true,
|
) = waitContent<VisualMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<VisualMediaGroupContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitTextedMediaContent(
|
suspend fun BehaviourContext.waitTextedMediaContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = true
|
||||||
includeMediaGroups: Boolean = true,
|
) = waitContent<TextedMediaContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<TextedMediaContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitAnimation(
|
suspend fun BehaviourContext.waitAnimation(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContent<AnimationContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<AnimationContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitAudio(
|
suspend fun BehaviourContext.waitAudio(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = false
|
||||||
includeMediaGroups: Boolean = false,
|
) = waitContent<AudioContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<AudioContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitDocument(
|
suspend fun BehaviourContext.waitDocument(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = false
|
||||||
includeMediaGroups: Boolean = false,
|
) = waitContent<DocumentContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<DocumentContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitPhoto(
|
suspend fun BehaviourContext.waitPhoto(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = false
|
||||||
includeMediaGroups: Boolean = false,
|
) = waitContent<PhotoContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<PhotoContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitSticker(
|
suspend fun BehaviourContext.waitSticker(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContent<StickerContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<StickerContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitVideo(
|
suspend fun BehaviourContext.waitVideo(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = false
|
||||||
includeMediaGroups: Boolean = false,
|
) = waitContent<VideoContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<VideoContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitVideoNote(
|
suspend fun BehaviourContext.waitVideoNote(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContent<VideoNoteContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<VideoNoteContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitVoice(
|
suspend fun BehaviourContext.waitVoice(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContent<VoiceContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<VoiceContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitInvoice(
|
suspend fun BehaviourContext.waitInvoice(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContent<InvoiceContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<InvoiceContent>>? = null
|
|
||||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
|
@ -16,19 +16,19 @@ import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
|
|||||||
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
|
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
typealias CommonMessageToCommonMessageMapper<T> = suspend CommonMessage<T>.() -> CommonMessage<T>?
|
typealias CommonMessageToCommonMessageMapper<T> = suspend CommonMessage<T>.() -> CommonMessage<T>?
|
||||||
|
|
||||||
internal suspend inline fun <reified O : MessageContent> BehaviourContext.waitContentMessage(
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
count: Int = 1,
|
suspend inline fun <reified O : MessageContent> BehaviourContext.waitContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
includeMediaGroups: Boolean = true,
|
includeMediaGroups: Boolean = true,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
filter: SimpleFilter<CommonMessage<O>>? = null
|
|
||||||
): Flow<CommonMessage<O>> = expectFlow(
|
): Flow<CommonMessage<O>> = expectFlow(
|
||||||
initRequest,
|
initRequest,
|
||||||
count,
|
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
val messages = when (it) {
|
val messages = when (it) {
|
||||||
@ -43,13 +43,7 @@ internal suspend inline fun <reified O : MessageContent> BehaviourContext.waitCo
|
|||||||
else -> return@expectFlow emptyList()
|
else -> return@expectFlow emptyList()
|
||||||
}
|
}
|
||||||
messages.mapNotNull { message ->
|
messages.mapNotNull { message ->
|
||||||
@Suppress("UNCHECKED_CAST")
|
(message as? CommonMessage<*>) ?.withContent<O>()
|
||||||
val asCommonMessage = (message as? CommonMessage<*>) ?.withContent<O>() ?: return@mapNotNull null
|
|
||||||
if (filter == null || filter(asCommonMessage)) {
|
|
||||||
asCommonMessage
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,161 +67,111 @@ internal inline fun <reified T : MessageContent> contentMessageConverter(
|
|||||||
suspend fun BehaviourContext.waitContentMessage(
|
suspend fun BehaviourContext.waitContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = true
|
||||||
includeMediaGroups: Boolean = true,
|
) = waitContentMessage<MessageContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<MessageContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitContactMessage(
|
suspend fun BehaviourContext.waitContactMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContentMessage<ContactContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<ContactContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitDiceMessage(
|
suspend fun BehaviourContext.waitDiceMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContentMessage<DiceContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<DiceContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitGameMessage(
|
suspend fun BehaviourContext.waitGameMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContentMessage<GameContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<GameContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitLocationMessage(
|
suspend fun BehaviourContext.waitLocationMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContentMessage<LocationContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<LocationContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitLiveLocationMessage(
|
suspend fun BehaviourContext.waitLiveLocationMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContentMessage<LiveLocationContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<LiveLocationContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitStaticLocationMessage(
|
suspend fun BehaviourContext.waitStaticLocationMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContentMessage<StaticLocationContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<StaticLocationContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitPollMessage(
|
suspend fun BehaviourContext.waitPollMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContentMessage<PollContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<PollContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitTextMessage(
|
suspend fun BehaviourContext.waitTextMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContentMessage<TextContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<TextContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitVenueMessage(
|
suspend fun BehaviourContext.waitVenueMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContentMessage<VenueContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<VenueContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitAudioMediaGroupContentMessage(
|
suspend fun BehaviourContext.waitAudioMediaGroupContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = true
|
||||||
includeMediaGroups: Boolean = true,
|
) = waitContentMessage<AudioMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<AudioMediaGroupContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitDocumentMediaGroupContentMessage(
|
suspend fun BehaviourContext.waitDocumentMediaGroupContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = true
|
||||||
includeMediaGroups: Boolean = true,
|
) = waitContentMessage<DocumentMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<DocumentMediaGroupContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitMediaMessage(
|
suspend fun BehaviourContext.waitMediaMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = false
|
||||||
includeMediaGroups: Boolean = false,
|
) = waitContentMessage<MediaContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<MediaContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitAnyMediaGroupContentMessage(
|
suspend fun BehaviourContext.waitAnyMediaGroupContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = true
|
||||||
includeMediaGroups: Boolean = true,
|
) = waitContentMessage<MediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<MediaGroupContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitVisualMediaGroupContentMessage(
|
suspend fun BehaviourContext.waitVisualMediaGroupContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = true
|
||||||
includeMediaGroups: Boolean = true,
|
) = waitContentMessage<VisualMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<VisualMediaGroupContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitTextedMediaContentMessage(
|
suspend fun BehaviourContext.waitTextedMediaContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = true
|
||||||
includeMediaGroups: Boolean = true,
|
) = waitContentMessage<TextedMediaContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<TextedMediaContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitAnimationMessage(
|
suspend fun BehaviourContext.waitAnimationMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContentMessage<AnimationContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<AnimationContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitAudioMessage(
|
suspend fun BehaviourContext.waitAudioMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = false
|
||||||
includeMediaGroups: Boolean = false,
|
) = waitContentMessage<AudioContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<AudioContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitDocumentMessage(
|
suspend fun BehaviourContext.waitDocumentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = false
|
||||||
includeMediaGroups: Boolean = false,
|
) = waitContentMessage<DocumentContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<DocumentContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitPhotoMessage(
|
suspend fun BehaviourContext.waitPhotoMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = false
|
||||||
includeMediaGroups: Boolean = false,
|
) = waitContentMessage<PhotoContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<PhotoContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitStickerMessage(
|
suspend fun BehaviourContext.waitStickerMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContentMessage<StickerContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<StickerContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitVideoMessage(
|
suspend fun BehaviourContext.waitVideoMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = false
|
||||||
includeMediaGroups: Boolean = false,
|
) = waitContentMessage<VideoContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<VideoContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitVideoNoteMessage(
|
suspend fun BehaviourContext.waitVideoNoteMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContentMessage<VideoNoteContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<VideoNoteContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitVoiceMessage(
|
suspend fun BehaviourContext.waitVoiceMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContentMessage<VoiceContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<VoiceContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitInvoiceMessage(
|
suspend fun BehaviourContext.waitInvoiceMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitContentMessage<InvoiceContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<InvoiceContent>>? = null
|
|
||||||
) = waitContentMessage(count, initRequest, false, errorFactory, filter)
|
|
||||||
|
@ -16,192 +16,127 @@ import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
|||||||
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
|
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
|
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseEditMessageUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.BaseEditMessageUpdate
|
||||||
import kotlinx.coroutines.flow.toList
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
|
import kotlinx.coroutines.flow.*
|
||||||
|
|
||||||
private suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedContent(
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
count: Int = 1,
|
suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
includeMediaGroups: Boolean = true,
|
includeMediaGroups: Boolean = true,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
filter: SimpleFilter<CommonMessage<O>>? = null
|
): Flow<O> = waitEditedContentMessage<O>(initRequest, includeMediaGroups, errorFactory).map { it.content }
|
||||||
): List<O> = expectFlow(
|
|
||||||
initRequest,
|
suspend fun BehaviourContext.waitEditedMessageContent(
|
||||||
count,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
) {
|
includeMediaGroups: Boolean = true
|
||||||
val messages = when (it) {
|
) = waitEditedContent<MessageContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
is BaseEditMessageUpdate -> {
|
|
||||||
val commonMessage = it.data.asCommonMessage() ?: return@expectFlow emptyList()
|
|
||||||
if (commonMessage !is MediaGroupMessage<*> || includeMediaGroups) {
|
|
||||||
listOf(commonMessage)
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else -> return@expectFlow emptyList()
|
|
||||||
}
|
|
||||||
messages.mapNotNull { message ->
|
|
||||||
val asCommonMessage = (message as CommonMessage<*>).withContent<O>() ?: return@mapNotNull null
|
|
||||||
if (filter == null || filter(asCommonMessage)) {
|
|
||||||
asCommonMessage.content
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.toList().toList()
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitEditedContentMessage(
|
suspend fun BehaviourContext.waitEditedContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = true
|
||||||
includeMediaGroups: Boolean = true,
|
) = waitEditedContent<MessageContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<MessageContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedContact(
|
suspend fun BehaviourContext.waitEditedContact(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEditedContent<ContactContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<ContactContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedDice(
|
suspend fun BehaviourContext.waitEditedDice(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEditedContent<DiceContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<DiceContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedGame(
|
suspend fun BehaviourContext.waitEditedGame(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEditedContent<GameContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<GameContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedLocation(
|
suspend fun BehaviourContext.waitEditedLocation(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEditedContent<LocationContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<LocationContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedLiveLocation(
|
suspend fun BehaviourContext.waitEditedLiveLocation(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEditedContent<LiveLocationContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<LiveLocationContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedStaticLocation(
|
suspend fun BehaviourContext.waitEditedStaticLocation(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEditedContent<StaticLocationContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<StaticLocationContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedText(
|
suspend fun BehaviourContext.waitEditedText(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEditedContent<TextContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<TextContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedVenue(
|
suspend fun BehaviourContext.waitEditedVenue(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEditedContent<VenueContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<VenueContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedAudioMediaGroupContent(
|
suspend fun BehaviourContext.waitEditedAudioMediaGroupContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = true
|
||||||
includeMediaGroups: Boolean = true,
|
) = waitEditedContent<AudioMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<AudioMediaGroupContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedDocumentMediaGroupContent(
|
suspend fun BehaviourContext.waitEditedDocumentMediaGroupContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = true
|
||||||
includeMediaGroups: Boolean = true,
|
) = waitEditedContent<DocumentMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<DocumentMediaGroupContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedMedia(
|
suspend fun BehaviourContext.waitEditedMedia(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = false
|
||||||
includeMediaGroups: Boolean = false,
|
) = waitEditedContent<MediaContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<MediaContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedAnyMediaGroupContent(
|
suspend fun BehaviourContext.waitEditedAnyMediaGroupContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = true
|
||||||
includeMediaGroups: Boolean = true,
|
) = waitEditedContent<MediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<MediaGroupContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedVisualMediaGroupContent(
|
suspend fun BehaviourContext.waitEditedVisualMediaGroupContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = true
|
||||||
includeMediaGroups: Boolean = true,
|
) = waitEditedContent<VisualMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<VisualMediaGroupContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedTextedMediaContent(
|
suspend fun BehaviourContext.waitEditedTextedMediaContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = true
|
||||||
includeMediaGroups: Boolean = true,
|
) = waitEditedContent<TextedMediaContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<TextedMediaContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedAnimation(
|
suspend fun BehaviourContext.waitEditedAnimation(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEditedContent<AnimationContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<AnimationContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedAudio(
|
suspend fun BehaviourContext.waitEditedAudio(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = false
|
||||||
includeMediaGroups: Boolean = false,
|
) = waitEditedContent<AudioContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<AudioContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedDocument(
|
suspend fun BehaviourContext.waitEditedDocument(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = false
|
||||||
includeMediaGroups: Boolean = false,
|
) = waitEditedContent<DocumentContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<DocumentContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedPhoto(
|
suspend fun BehaviourContext.waitEditedPhoto(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = false
|
||||||
includeMediaGroups: Boolean = false,
|
) = waitEditedContent<PhotoContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<PhotoContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedSticker(
|
suspend fun BehaviourContext.waitEditedSticker(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEditedContent<StickerContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<StickerContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedVideo(
|
suspend fun BehaviourContext.waitEditedVideo(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
count: Int = 1,
|
includeMediaGroups: Boolean = false
|
||||||
includeMediaGroups: Boolean = false,
|
) = waitEditedContent<VideoContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<VideoContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedVideoNote(
|
suspend fun BehaviourContext.waitEditedVideoNote(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEditedContent<VideoNoteContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<VideoNoteContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedVoice(
|
suspend fun BehaviourContext.waitEditedVoice(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEditedContent<VoiceContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<VoiceContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitEditedInvoice(
|
suspend fun BehaviourContext.waitEditedInvoice(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEditedContent<InvoiceContent>(initRequest, false, errorFactory)
|
||||||
filter: SimpleFilter<CommonMessage<InvoiceContent>>? = null
|
|
||||||
) = waitEditedContent(count, initRequest, false, errorFactory, filter)
|
|
||||||
|
@ -0,0 +1,156 @@
|
|||||||
|
@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.AudioMediaGroupContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
|
||||||
|
import dev.inmo.tgbotapi.types.update.abstracts.BaseEditMessageUpdate
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.toList
|
||||||
|
|
||||||
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
|
suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedContentMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
includeMediaGroups: Boolean = true,
|
||||||
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
): Flow<CommonMessage<O>> = expectFlow(
|
||||||
|
initRequest,
|
||||||
|
errorFactory
|
||||||
|
) {
|
||||||
|
val messages = when (it) {
|
||||||
|
is BaseEditMessageUpdate -> {
|
||||||
|
val commonMessage = it.data.asCommonMessage() ?: return@expectFlow emptyList()
|
||||||
|
if (commonMessage !is MediaGroupMessage<*> || includeMediaGroups) {
|
||||||
|
listOf(commonMessage)
|
||||||
|
} else {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> return@expectFlow emptyList()
|
||||||
|
}
|
||||||
|
messages.mapNotNull { message ->
|
||||||
|
(message as CommonMessage<*>).withContent<O>()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.waitEditedMessageContentMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
includeMediaGroups: Boolean = true
|
||||||
|
) = waitEditedContentMessage<MessageContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.waitEditedContactMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEditedContentMessage<ContactContent>(initRequest, false, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedDiceMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEditedContentMessage<DiceContent>(initRequest, false, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedGameMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEditedContentMessage<GameContent>(initRequest, false, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedLocationMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEditedContentMessage<LocationContent>(initRequest, false, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedLiveLocationMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEditedContentMessage<LiveLocationContent>(initRequest, false, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedStaticLocationMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEditedContentMessage<StaticLocationContent>(initRequest, false, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedTextMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEditedContentMessage<TextContent>(initRequest, false, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedVenueMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEditedContentMessage<VenueContent>(initRequest, false, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedAudioMediaGroupContentMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
includeMediaGroups: Boolean = true
|
||||||
|
) = waitEditedContentMessage<AudioMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedDocumentMediaGroupContentMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
includeMediaGroups: Boolean = true
|
||||||
|
) = waitEditedContentMessage<DocumentMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedMediaMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
includeMediaGroups: Boolean = false
|
||||||
|
) = waitEditedContentMessage<MediaContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedAnyMediaGroupContentMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
includeMediaGroups: Boolean = true
|
||||||
|
) = waitEditedContentMessage<MediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedVisualMediaGroupContentMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
includeMediaGroups: Boolean = true
|
||||||
|
) = waitEditedContentMessage<VisualMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedTextedMediaContentMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
includeMediaGroups: Boolean = true
|
||||||
|
) = waitEditedContentMessage<TextedMediaContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedAnimationMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEditedContentMessage<AnimationContent>(initRequest, false, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedAudioMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
includeMediaGroups: Boolean = false
|
||||||
|
) = waitEditedContentMessage<AudioContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedDocumentMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
includeMediaGroups: Boolean = false
|
||||||
|
) = waitEditedContentMessage<DocumentContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedPhotoMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
includeMediaGroups: Boolean = false
|
||||||
|
) = waitEditedContentMessage<PhotoContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedStickerMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEditedContentMessage<StickerContent>(initRequest, false, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedVideoMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
includeMediaGroups: Boolean = false
|
||||||
|
) = waitEditedContentMessage<VideoContent>(initRequest, includeMediaGroups, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedVideoNoteMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEditedContentMessage<VideoNoteContent>(initRequest, false, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedVoiceMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEditedContentMessage<VoiceContent>(initRequest, false, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitEditedInvoiceMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEditedContentMessage<InvoiceContent>(initRequest, false, errorFactory)
|
@ -12,212 +12,150 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
|||||||
import dev.inmo.tgbotapi.types.message.PrivateEventMessage
|
import dev.inmo.tgbotapi.types.message.PrivateEventMessage
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
|
||||||
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
|
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
import kotlinx.coroutines.flow.toList
|
||||||
|
|
||||||
typealias EventMessageToEventMapper<T> = suspend ChatEventMessage<T>.() -> T?
|
typealias EventMessageToEventMapper<T> = suspend ChatEventMessage<T>.() -> T?
|
||||||
|
|
||||||
private suspend inline fun <reified O : ChatEvent> BehaviourContext.waitEvents(
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
|
suspend inline fun <reified O : ChatEvent> BehaviourContext.waitEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
): Flow<O> = expectFlow(
|
||||||
filter: SimpleFilter<ChatEventMessage<O>>? = null
|
|
||||||
): List<O> = expectFlow(
|
|
||||||
initRequest,
|
initRequest,
|
||||||
count,
|
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
val data = it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.withEvent<O>() ?: return@expectFlow emptyList()
|
it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.withEvent<O>() ?.chatEvent.let(::listOfNotNull)
|
||||||
if (filter == null || filter(data)) {
|
|
||||||
listOf(data.chatEvent)
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
}
|
||||||
}.toList().toList()
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitChannelEvents(
|
suspend fun BehaviourContext.waitChannelEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<ChannelEvent>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<ChannelEvent>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitPrivateEvents(
|
suspend fun BehaviourContext.waitPrivateEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<PrivateEvent>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<PrivateEvent>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitChatEvents(
|
suspend fun BehaviourContext.waitChatEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<ChatEvent>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<ChatEvent>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
|
|
||||||
@Deprecated("Renamed as Video instead of Voice")
|
@Deprecated("Renamed as Video instead of Voice")
|
||||||
suspend fun BehaviourContext.waitVoiceChatEvents(
|
suspend fun BehaviourContext.waitVoiceChatEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<VideoChatEvent>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<VideoChatEvent>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
@Deprecated("Renamed as Video instead of Voice")
|
@Deprecated("Renamed as Video instead of Voice")
|
||||||
suspend fun BehaviourContext.waitVoiceChatStartedEvents(
|
suspend fun BehaviourContext.waitVoiceChatStartedEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<VideoChatStarted>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<VideoChatStarted>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
@Deprecated("Renamed as Video instead of Voice")
|
@Deprecated("Renamed as Video instead of Voice")
|
||||||
suspend fun BehaviourContext.waitVoiceChatEndedEvents(
|
suspend fun BehaviourContext.waitVoiceChatEndedEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<VideoChatEnded>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<VideoChatEnded>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
@Deprecated("Renamed as Video instead of Voice")
|
@Deprecated("Renamed as Video instead of Voice")
|
||||||
suspend fun BehaviourContext.waitVoiceChatParticipantsInvitedEvents(
|
suspend fun BehaviourContext.waitVoiceChatParticipantsInvitedEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<VideoChatParticipantsInvited>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<VideoChatParticipantsInvited>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitVideoChatEvents(
|
suspend fun BehaviourContext.waitVideoChatEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<VideoChatEvent>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<VideoChatEvent>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
suspend fun BehaviourContext.waitVideoChatStartedEvents(
|
suspend fun BehaviourContext.waitVideoChatStartedEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<VideoChatStarted>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<VideoChatStarted>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
suspend fun BehaviourContext.waitVideoChatEndedEvents(
|
suspend fun BehaviourContext.waitVideoChatEndedEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<VideoChatEnded>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<VideoChatEnded>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
suspend fun BehaviourContext.waitVideoChatParticipantsInvitedEvents(
|
suspend fun BehaviourContext.waitVideoChatParticipantsInvitedEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<VideoChatParticipantsInvited>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<VideoChatParticipantsInvited>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitMessageAutoDeleteTimerChangedEvents(
|
suspend fun BehaviourContext.waitMessageAutoDeleteTimerChangedEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<MessageAutoDeleteTimerChanged>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<MessageAutoDeleteTimerChanged>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitPublicChatEvents(
|
suspend fun BehaviourContext.waitPublicChatEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<PublicChatEvent>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<PublicChatEvent>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
suspend fun BehaviourContext.waitCommonEvents(
|
suspend fun BehaviourContext.waitCommonEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<CommonEvent>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<CommonEvent>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitGroupEvents(
|
suspend fun BehaviourContext.waitGroupEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<GroupEvent>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<GroupEvent>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
suspend fun BehaviourContext.waitSupergroupEvents(
|
suspend fun BehaviourContext.waitSupergroupEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<SupergroupEvent>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<SupergroupEvent>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitChannelChatCreatedEvents(
|
suspend fun BehaviourContext.waitChannelChatCreatedEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<ChannelChatCreated>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<ChannelChatCreated>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
suspend fun BehaviourContext.waitDeleteChatPhotoEvents(
|
suspend fun BehaviourContext.waitDeleteChatPhotoEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<DeleteChatPhoto>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<DeleteChatPhoto>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
suspend fun BehaviourContext.waitGroupChatCreatedEvents(
|
suspend fun BehaviourContext.waitGroupChatCreatedEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<GroupChatCreated>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<GroupChatCreated>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
suspend fun BehaviourContext.waitLeftChatMemberEvents(
|
suspend fun BehaviourContext.waitLeftChatMemberEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<LeftChatMember>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<LeftChatMember>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
suspend fun BehaviourContext.waitNewChatPhotoEvents(
|
suspend fun BehaviourContext.waitNewChatPhotoEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<NewChatPhoto>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<NewChatPhoto>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
suspend fun BehaviourContext.waitNewChatMembersEvents(
|
suspend fun BehaviourContext.waitNewChatMembersEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<NewChatMembers>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<NewChatMembers>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
suspend fun BehaviourContext.waitNewChatTitleEvents(
|
suspend fun BehaviourContext.waitNewChatTitleEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<NewChatTitle>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<NewChatTitle>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
suspend fun BehaviourContext.waitPinnedMessageEvents(
|
suspend fun BehaviourContext.waitPinnedMessageEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<PinnedMessage>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<PinnedMessage>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
suspend fun BehaviourContext.waitProximityAlertTriggeredEvents(
|
suspend fun BehaviourContext.waitProximityAlertTriggeredEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<ProximityAlertTriggered>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<ProximityAlertTriggered>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
suspend fun BehaviourContext.waitSupergroupChatCreatedEvents(
|
suspend fun BehaviourContext.waitSupergroupChatCreatedEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<SupergroupChatCreated>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<SupergroupChatCreated>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
suspend fun BehaviourContext.waitSuccessfulPaymentEvents(
|
suspend fun BehaviourContext.waitSuccessfulPaymentEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<SuccessfulPaymentEvent>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<SuccessfulPaymentEvent>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
suspend fun BehaviourContext.waitUserLoggedInEvents(
|
suspend fun BehaviourContext.waitUserLoggedInEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<UserLoggedIn>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<ChatEventMessage<UserLoggedIn>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter)
|
|
||||||
suspend fun BehaviourContext.waitWebAppDataEvents(
|
suspend fun BehaviourContext.waitWebAppDataEvents(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitEvents<WebAppData>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<PrivateEventMessage<WebAppData>>? = null
|
|
||||||
) = waitEvents(initRequest, errorFactory, count, filter ?.let { SimpleFilter<ChatEventMessage<WebAppData>> { it is PrivateEventMessage && filter(it) } })
|
|
||||||
|
@ -0,0 +1,159 @@
|
|||||||
|
@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.*
|
||||||
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
|
import dev.inmo.tgbotapi.types.message.ChannelEventMessage
|
||||||
|
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.PrivateEventMessage
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
|
||||||
|
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
|
import kotlinx.coroutines.flow.*
|
||||||
|
|
||||||
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
|
suspend inline fun <reified O : ChatEvent> BehaviourContext.waitEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
): Flow<ChatEventMessage<O>> = expectFlow(
|
||||||
|
initRequest,
|
||||||
|
errorFactory
|
||||||
|
) {
|
||||||
|
it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.withEvent<O>().let(::listOfNotNull)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.waitChannelEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<ChannelEvent>(initRequest, errorFactory)
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.waitPrivateEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<PrivateEvent>(initRequest, errorFactory)
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.waitChatEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<ChatEvent>(initRequest, errorFactory)
|
||||||
|
|
||||||
|
@Deprecated("Renamed as Video instead of Voice")
|
||||||
|
suspend fun BehaviourContext.waitVoiceChatEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<VideoChatEvent>(initRequest, errorFactory)
|
||||||
|
@Deprecated("Renamed as Video instead of Voice")
|
||||||
|
suspend fun BehaviourContext.waitVoiceChatStartedEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<VideoChatStarted>(initRequest, errorFactory)
|
||||||
|
@Deprecated("Renamed as Video instead of Voice")
|
||||||
|
suspend fun BehaviourContext.waitVoiceChatEndedEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<VideoChatEnded>(initRequest, errorFactory)
|
||||||
|
@Deprecated("Renamed as Video instead of Voice")
|
||||||
|
suspend fun BehaviourContext.waitVoiceChatParticipantsInvitedEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<VideoChatParticipantsInvited>(initRequest, errorFactory)
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.waitVideoChatEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<VideoChatEvent>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitVideoChatStartedEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<VideoChatStarted>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitVideoChatEndedEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<VideoChatEnded>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitVideoChatParticipantsInvitedEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<VideoChatParticipantsInvited>(initRequest, errorFactory)
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.waitMessageAutoDeleteTimerChangedEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<MessageAutoDeleteTimerChanged>(initRequest, errorFactory)
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.waitPublicChatEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<PublicChatEvent>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitCommonEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<CommonEvent>(initRequest, errorFactory)
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.waitGroupEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<GroupEvent>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitSupergroupEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<SupergroupEvent>(initRequest, errorFactory)
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.waitChannelChatCreatedEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<ChannelChatCreated>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitDeleteChatPhotoEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<DeleteChatPhoto>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitGroupChatCreatedEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<GroupChatCreated>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitLeftChatMemberEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<LeftChatMember>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitNewChatPhotoEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<NewChatPhoto>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitNewChatMembersEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<NewChatMembers>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitNewChatTitleEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<NewChatTitle>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitPinnedMessageEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<PinnedMessage>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitProximityAlertTriggeredEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<ProximityAlertTriggered>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitSupergroupChatCreatedEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<SupergroupChatCreated>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitSuccessfulPaymentEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<SuccessfulPaymentEvent>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitUserLoggedInEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<UserLoggedIn>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitWebAppDataEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<WebAppData>(initRequest, errorFactory)
|
@ -5,44 +5,34 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
|||||||
import dev.inmo.tgbotapi.extensions.utils.asInlineQueryUpdate
|
import dev.inmo.tgbotapi.extensions.utils.asInlineQueryUpdate
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.query.*
|
import dev.inmo.tgbotapi.types.InlineQueries.query.*
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
import kotlinx.coroutines.flow.toList
|
||||||
|
|
||||||
typealias InlineQueryMapper<T> = suspend T.() -> T?
|
typealias InlineQueryMapper<T> = suspend T.() -> T?
|
||||||
|
|
||||||
private suspend inline fun <reified O : InlineQuery> BehaviourContext.waitInlineQueries(
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
count: Int = 1,
|
suspend inline fun <reified O : InlineQuery> BehaviourContext.waitInlineQueries(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
filter: SimpleFilter<O>? = null
|
): Flow<O> = expectFlow(
|
||||||
): List<O> = expectFlow(
|
|
||||||
initRequest,
|
initRequest,
|
||||||
count,
|
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
val data = (it.asInlineQueryUpdate() ?.data as? O) ?: return@expectFlow emptyList()
|
(it.asInlineQueryUpdate() ?.data as? O).let(::listOfNotNull)
|
||||||
if (filter == null || filter(data)) {
|
|
||||||
listOf(data)
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
}
|
||||||
}.toList().toList()
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitAnyInlineQuery(
|
suspend fun BehaviourContext.waitAnyInlineQuery(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitInlineQueries<InlineQuery>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<InlineQuery>? = null
|
|
||||||
) = waitInlineQueries(count, initRequest, errorFactory, filter)
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitBaseInlineQuery(
|
suspend fun BehaviourContext.waitBaseInlineQuery(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitInlineQueries<BaseInlineQuery>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<BaseInlineQuery>? = null
|
|
||||||
) = waitInlineQueries(count, initRequest, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitLocationInlineQuery(
|
suspend fun BehaviourContext.waitLocationInlineQuery(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitInlineQueries<LocationInlineQuery>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<LocationInlineQuery>? = null
|
|
||||||
) = waitInlineQueries(count, initRequest, errorFactory, filter)
|
|
||||||
|
@ -11,62 +11,41 @@ import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent
|
|||||||
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
|
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
|
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
|
||||||
import kotlinx.coroutines.flow.take
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import kotlinx.coroutines.flow.toList
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
|
||||||
typealias MediaGroupFilter<T> = SimpleFilter<List<MediaGroupMessage<T>>>
|
typealias MediaGroupFilter<T> = SimpleFilter<List<MediaGroupMessage<T>>>
|
||||||
|
|
||||||
internal suspend inline fun <reified T : MediaGroupContent> BehaviourContext.buildMediaGroupWaiter(
|
|
||||||
count: Int = 1,
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
|
suspend inline fun <reified O : MediaGroupContent> BehaviourContext.buildMediaGroupWaiter(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
filter: SimpleFilter<List<MediaGroupMessage<T>>>? = null
|
): Flow<List<O>> = buildMediaGroupMessagesWaiter<O>(initRequest, errorFactory).map { it.map { it.content } }
|
||||||
) = flowsUpdatesFilter.expectFlow(bot, initRequest, count, errorFactory) { update ->
|
|
||||||
update.asSentMediaGroupUpdate() ?.data ?.let { mediaGroup ->
|
|
||||||
val mapped = mediaGroup.mapNotNull { it.withContent<T>() }
|
|
||||||
if (mediaGroup.all { message -> message.content is T } && (filter == null || filter(mapped))) {
|
|
||||||
listOf(
|
|
||||||
mediaGroup.map { it.content as T }
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
} ?: emptyList()
|
|
||||||
}.take(count).toList()
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitMediaGroup(
|
suspend fun BehaviourContext.waitMediaGroup(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = buildMediaGroupWaiter<MediaGroupContent>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<List<MediaGroupMessage<MediaGroupContent>>>? = null
|
|
||||||
) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitPlaylist(
|
suspend fun BehaviourContext.waitPlaylist(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = buildMediaGroupWaiter<AudioMediaGroupContent>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<List<MediaGroupMessage<AudioMediaGroupContent>>>? = null
|
|
||||||
) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitDocumentsGroup(
|
suspend fun BehaviourContext.waitDocumentsGroup(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = buildMediaGroupWaiter<DocumentMediaGroupContent>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<List<MediaGroupMessage<DocumentMediaGroupContent>>>? = null
|
|
||||||
) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitVisualGallery(
|
suspend fun BehaviourContext.waitVisualGallery(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = buildMediaGroupWaiter<VisualMediaGroupContent>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<List<MediaGroupMessage<VisualMediaGroupContent>>>? = null
|
|
||||||
) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitPhotoGallery(
|
suspend fun BehaviourContext.waitPhotoGallery(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = buildMediaGroupWaiter<PhotoContent>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<List<MediaGroupMessage<PhotoContent>>>? = null
|
|
||||||
) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter)
|
|
||||||
suspend fun BehaviourContext.waitVideoGallery(
|
suspend fun BehaviourContext.waitVideoGallery(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = buildMediaGroupWaiter<VideoContent>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<List<MediaGroupMessage<VideoContent>>>? = null
|
|
||||||
) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter)
|
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
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.asSentMediaGroupUpdate
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.withContent
|
||||||
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.*
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
|
suspend inline fun <reified T : MediaGroupContent> BehaviourContext.buildMediaGroupMessagesWaiter(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
): Flow<List<MediaGroupMessage<T>>> = flowsUpdatesFilter.expectFlow(bot, initRequest, errorFactory) { update ->
|
||||||
|
update.asSentMediaGroupUpdate() ?.data ?.let { mediaGroup ->
|
||||||
|
val mapped = mediaGroup.mapNotNull { it.withContent<T>() }
|
||||||
|
listOf(
|
||||||
|
mapped
|
||||||
|
)
|
||||||
|
} ?: emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.waitMediaGroupMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = buildMediaGroupMessagesWaiter<MediaGroupContent>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitPlaylistMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = buildMediaGroupMessagesWaiter<AudioMediaGroupContent>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitDocumentsGroupMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = buildMediaGroupMessagesWaiter<DocumentMediaGroupContent>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitVisualGalleryMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = buildMediaGroupMessagesWaiter<VisualMediaGroupContent>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitPhotoGalleryMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = buildMediaGroupMessagesWaiter<PhotoContent>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitVideoGalleryMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = buildMediaGroupMessagesWaiter<VideoContent>(initRequest, errorFactory)
|
@ -9,32 +9,24 @@ import dev.inmo.tgbotapi.types.message.PassportMessage
|
|||||||
import dev.inmo.tgbotapi.types.passport.PassportData
|
import dev.inmo.tgbotapi.types.passport.PassportData
|
||||||
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElement
|
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElement
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
import kotlinx.coroutines.flow.toList
|
||||||
|
|
||||||
typealias PassportMessageMapper = suspend PassportMessage.() -> PassportData
|
typealias PassportMessageMapper = suspend PassportMessage.() -> PassportData
|
||||||
|
|
||||||
@RiskFeature("Do not use this message directly, use waitPassportMessagesWith or waitAnyPassportMessages instead")
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
suspend inline fun <reified O : EncryptedPassportElement> BehaviourContext.waitPassportMessagesWith(
|
suspend inline fun <reified O : EncryptedPassportElement> BehaviourContext.waitPassportMessagesWith(
|
||||||
count: Int = 1,
|
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
filter: SimpleFilter<PassportMessage>? = null
|
): Flow<O> = expectFlow(
|
||||||
): List<O> = expectFlow(
|
|
||||||
initRequest,
|
initRequest,
|
||||||
count,
|
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
val data = it.asMessageUpdate() ?.data ?.asPassportMessage() ?: return@expectFlow emptyList()
|
it.asMessageUpdate() ?.data ?.asPassportMessage() ?.passportData ?.data ?.filterIsInstance<O>() ?: emptyList()
|
||||||
if (filter == null || filter(data)) {
|
|
||||||
data.passportData.data.filterIsInstance<O>()
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
}
|
||||||
}.toList().toList()
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitAnyPassportMessages(
|
suspend fun BehaviourContext.waitAnyPassportMessages(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitPassportMessagesWith<EncryptedPassportElement>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<PassportMessage>? = null
|
|
||||||
) = waitPassportMessagesWith<EncryptedPassportElement>(count, initRequest, errorFactory, filter)
|
|
||||||
|
@ -5,34 +5,19 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
|||||||
import dev.inmo.tgbotapi.extensions.utils.asPollAnswerUpdate
|
import dev.inmo.tgbotapi.extensions.utils.asPollAnswerUpdate
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.polls.PollAnswer
|
import dev.inmo.tgbotapi.types.polls.PollAnswer
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
import kotlinx.coroutines.flow.toList
|
||||||
|
|
||||||
typealias PollAnswerMapper = suspend PollAnswer.() -> PollAnswer?
|
typealias PollAnswerMapper = suspend PollAnswer.() -> PollAnswer?
|
||||||
|
|
||||||
private suspend inline fun <reified O : PollAnswer> BehaviourContext.waitPollAnswers(
|
|
||||||
count: Int = 1,
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
|
||||||
filter: SimpleFilter<O>? = null
|
|
||||||
): List<O> = expectFlow(
|
|
||||||
initRequest,
|
|
||||||
count,
|
|
||||||
errorFactory
|
|
||||||
) {
|
|
||||||
val data = it.asPollAnswerUpdate() ?.data as? O ?: return@expectFlow emptyList()
|
|
||||||
if (filter == null || filter(data)) {
|
|
||||||
listOf(data)
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
}.toList().toList()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This wait will be triggered only for stopped polls and polls, which are sent by the bot
|
|
||||||
*/
|
|
||||||
suspend fun BehaviourContext.waitPollAnswers(
|
suspend fun BehaviourContext.waitPollAnswers(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
): Flow<PollAnswer> = expectFlow(
|
||||||
filter: SimpleFilter<PollAnswer>? = null
|
initRequest,
|
||||||
) = waitPollAnswers(count, initRequest, errorFactory, filter)
|
errorFactory
|
||||||
|
) {
|
||||||
|
it.asPollAnswerUpdate() ?.data.let(::listOfNotNull)
|
||||||
|
}
|
||||||
|
@ -5,54 +5,44 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
|||||||
import dev.inmo.tgbotapi.extensions.utils.asPollUpdate
|
import dev.inmo.tgbotapi.extensions.utils.asPollUpdate
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.polls.*
|
import dev.inmo.tgbotapi.types.polls.*
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
import kotlinx.coroutines.flow.toList
|
||||||
|
|
||||||
typealias PollMapper<T> = suspend T.() -> T?
|
typealias PollMapper<T> = suspend T.() -> T?
|
||||||
|
|
||||||
private suspend inline fun <reified O> BehaviourContext.waitPolls(
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
count: Int = 1,
|
suspend inline fun <reified O : Poll> BehaviourContext.waitPolls(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
filter: SimpleFilter<O>? = null
|
): Flow<O> = expectFlow(
|
||||||
): List<O> = expectFlow(
|
|
||||||
initRequest,
|
initRequest,
|
||||||
count,
|
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
val data = it.asPollUpdate() ?.data as? O ?: return@expectFlow emptyList()
|
(it.asPollUpdate() ?.data as? O).let(::listOfNotNull)
|
||||||
if (filter == null || filter(data)) {
|
|
||||||
listOf(data)
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
}
|
||||||
}.toList().toList()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This wait will be triggered only for stopped polls and polls, which are sent by the bot
|
* This wait will be triggered only for stopped polls and polls, which are sent by the bot
|
||||||
*/
|
*/
|
||||||
suspend fun BehaviourContext.waitPollUpdates(
|
suspend fun BehaviourContext.waitPollUpdates(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitPolls<Poll>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<Poll>? = null
|
|
||||||
) = waitPolls(count, initRequest, errorFactory, filter)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This wait will be triggered only for stopped polls and polls, which are sent by the bot
|
* This wait will be triggered only for stopped polls and polls, which are sent by the bot
|
||||||
*/
|
*/
|
||||||
suspend fun BehaviourContext.waitQuizPollUpdates(
|
suspend fun BehaviourContext.waitQuizPollUpdates(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitPolls<QuizPoll>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<QuizPoll>? = null
|
|
||||||
) = waitPolls(count, initRequest, errorFactory, filter)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This wait will be triggered only for stopped polls and polls, which are sent by the bot
|
* This wait will be triggered only for stopped polls and polls, which are sent by the bot
|
||||||
*/
|
*/
|
||||||
suspend fun BehaviourContext.waitRegularPollUpdates(
|
suspend fun BehaviourContext.waitRegularPollUpdates(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
) = waitPolls<RegularPoll>(initRequest, errorFactory)
|
||||||
filter: SimpleFilter<RegularPoll>? = null
|
|
||||||
) = waitPolls(count, initRequest, errorFactory, filter)
|
|
||||||
|
@ -5,37 +5,19 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
|||||||
import dev.inmo.tgbotapi.extensions.utils.asPreCheckoutQueryUpdate
|
import dev.inmo.tgbotapi.extensions.utils.asPreCheckoutQueryUpdate
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
|
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
import kotlinx.coroutines.flow.toList
|
||||||
|
|
||||||
typealias PreCheckoutQueryMapper = suspend PreCheckoutQuery.() -> PreCheckoutQuery?
|
typealias PreCheckoutQueryMapper = suspend PreCheckoutQuery.() -> PreCheckoutQuery?
|
||||||
|
|
||||||
private suspend inline fun <reified O : PreCheckoutQuery> BehaviourContext.waitPreCheckoutQueries(
|
|
||||||
count: Int = 1,
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
|
||||||
filter: SimpleFilter<O>? = null
|
|
||||||
): List<O> = expectFlow(
|
|
||||||
initRequest,
|
|
||||||
count,
|
|
||||||
errorFactory
|
|
||||||
) {
|
|
||||||
val data = it.asPreCheckoutQueryUpdate() ?.data as? O ?: return@expectFlow emptyList()
|
|
||||||
if (filter == null || filter(data)) {
|
|
||||||
listOf(data)
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
}.toList().toList()
|
|
||||||
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitPreCheckoutQueries(
|
suspend fun BehaviourContext.waitPreCheckoutQueries(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
): Flow<PreCheckoutQuery> = expectFlow(
|
||||||
filter: SimpleFilter<PreCheckoutQuery>? = null
|
|
||||||
) : List<PreCheckoutQuery> = waitPreCheckoutQueries(
|
|
||||||
count,
|
|
||||||
initRequest,
|
initRequest,
|
||||||
errorFactory,
|
errorFactory
|
||||||
filter
|
) {
|
||||||
)
|
it.asPreCheckoutQueryUpdate() ?.data.let(::listOfNotNull)
|
||||||
|
}
|
||||||
|
@ -5,37 +5,17 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
|||||||
import dev.inmo.tgbotapi.extensions.utils.asShippingQueryUpdate
|
import dev.inmo.tgbotapi.extensions.utils.asShippingQueryUpdate
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
import kotlinx.coroutines.flow.toList
|
||||||
|
|
||||||
typealias ShippingQueryMapper = suspend ShippingQuery.() -> ShippingQuery?
|
typealias ShippingQueryMapper = suspend ShippingQuery.() -> ShippingQuery?
|
||||||
|
|
||||||
private suspend inline fun <reified O : ShippingQuery> BehaviourContext.waitShippingQueries(
|
|
||||||
count: Int = 1,
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
|
||||||
filter: SimpleFilter<O>? = null
|
|
||||||
): List<O> = expectFlow(
|
|
||||||
initRequest,
|
|
||||||
count,
|
|
||||||
errorFactory
|
|
||||||
) {
|
|
||||||
val data = it.asShippingQueryUpdate() ?.data as? O ?: return@expectFlow emptyList()
|
|
||||||
if (filter == null || filter(data)) {
|
|
||||||
listOf(data)
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
}.toList().toList()
|
|
||||||
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitShippingQueries(
|
suspend fun BehaviourContext.waitShippingQueries(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
count: Int = 1,
|
): Flow<ShippingQuery> = expectFlow(
|
||||||
filter: SimpleFilter<ShippingQuery>? = null
|
|
||||||
) : List<ShippingQuery> = waitShippingQueries(
|
|
||||||
count,
|
|
||||||
initRequest,
|
initRequest,
|
||||||
errorFactory,
|
errorFactory
|
||||||
filter
|
) {
|
||||||
)
|
(it.asShippingQueryUpdate() ?.data).let(::listOfNotNull)
|
||||||
|
}
|
||||||
|
@ -3,9 +3,12 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.utils
|
|||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTypeReceiver
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTypeReceiver
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitEditedLocation
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitEditedLocation
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitEditedLocationMessage
|
||||||
import dev.inmo.tgbotapi.types.location.*
|
import dev.inmo.tgbotapi.types.location.*
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.LiveLocationContent
|
import dev.inmo.tgbotapi.types.message.content.LiveLocationContent
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this extension when you want to follow [LiveLocation] until it will became [StaticLocation]. This method
|
* Use this extension when you want to follow [LiveLocation] until it will became [StaticLocation]. This method
|
||||||
@ -20,11 +23,7 @@ suspend fun BehaviourContext.followLocation(
|
|||||||
onLocation(message.content.location)
|
onLocation(message.content.location)
|
||||||
|
|
||||||
while (currentLocation !is StaticLocation) {
|
while (currentLocation !is StaticLocation) {
|
||||||
currentLocation = waitEditedLocation(
|
currentLocation = waitEditedLocationMessage().filter { it.messageId == message.messageId && it.chat.id == message.chat.id }.first().content.location
|
||||||
filter = {
|
|
||||||
it.messageId == message.messageId && it.chat.id == message.chat.id
|
|
||||||
}
|
|
||||||
).first().location
|
|
||||||
onLocation(currentLocation)
|
onLocation(currentLocation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ fun <T> aggregateFlows(
|
|||||||
return sharedFlow
|
return sharedFlow
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> Flow<Iterable<T>>.flatMap(): Flow<T> = flow {
|
fun <T> Flow<Iterable<T>>.flatten(): Flow<T> = flow {
|
||||||
collect {
|
collect {
|
||||||
it.forEach {
|
it.forEach {
|
||||||
emit(it)
|
emit(it)
|
||||||
@ -30,6 +30,9 @@ fun <T> Flow<Iterable<T>>.flatMap(): Flow<T> = flow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Renamed", ReplaceWith("flatten", "dev.inmo.tgbotapi.extensions.utils.flatten"))
|
||||||
|
fun <T> Flow<Iterable<T>>.flatMap(): Flow<T> = flatten()
|
||||||
|
|
||||||
fun <T, R> Flow<T>.flatMap(mapper: (T) -> Iterable<R>): Flow<R> = flow {
|
fun <T, R> Flow<T>.flatMap(mapper: (T) -> Iterable<R>): Flow<R> = flow {
|
||||||
collect {
|
collect {
|
||||||
mapper(it).forEach {
|
mapper(it).forEach {
|
||||||
|
@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.extensions.utils.shortcuts
|
|||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.aggregateFlows
|
import dev.inmo.tgbotapi.extensions.utils.aggregateFlows
|
||||||
import dev.inmo.tgbotapi.extensions.utils.flatMap
|
import dev.inmo.tgbotapi.extensions.utils.flatMap
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.flatten
|
||||||
import dev.inmo.tgbotapi.extensions.utils.updates.asContentMessagesFlow
|
import dev.inmo.tgbotapi.extensions.utils.updates.asContentMessagesFlow
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||||
@ -111,7 +112,7 @@ fun FlowsUpdatesFilter.audioMessagesWithMediaGroups(
|
|||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = merge(
|
) = merge(
|
||||||
filterContentMessages<AudioContent>(scopeToIncludeChannels),
|
filterContentMessages<AudioContent>(scopeToIncludeChannels),
|
||||||
mediaGroupAudioMessages(scopeToIncludeChannels).flatMap()
|
mediaGroupAudioMessages(scopeToIncludeChannels).flatten()
|
||||||
)
|
)
|
||||||
|
|
||||||
fun Flow<BaseSentMessageUpdate>.contactMessages() = filterContentMessages<ContactContent>()
|
fun Flow<BaseSentMessageUpdate>.contactMessages() = filterContentMessages<ContactContent>()
|
||||||
@ -132,7 +133,7 @@ fun FlowsUpdatesFilter.documentMessagesWithMediaGroups(
|
|||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = merge(
|
) = merge(
|
||||||
filterContentMessages<DocumentContent>(scopeToIncludeChannels),
|
filterContentMessages<DocumentContent>(scopeToIncludeChannels),
|
||||||
mediaGroupDocumentMessages(scopeToIncludeChannels).flatMap()
|
mediaGroupDocumentMessages(scopeToIncludeChannels).flatten()
|
||||||
)
|
)
|
||||||
|
|
||||||
fun Flow<BaseSentMessageUpdate>.gameMessages() = filterContentMessages<GameContent>()
|
fun Flow<BaseSentMessageUpdate>.gameMessages() = filterContentMessages<GameContent>()
|
||||||
@ -159,7 +160,7 @@ fun FlowsUpdatesFilter.photoMessagesWithMediaGroups(
|
|||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = merge(
|
) = merge(
|
||||||
filterContentMessages<PhotoContent>(scopeToIncludeChannels),
|
filterContentMessages<PhotoContent>(scopeToIncludeChannels),
|
||||||
mediaGroupPhotosMessages(scopeToIncludeChannels).flatMap()
|
mediaGroupPhotosMessages(scopeToIncludeChannels).flatten()
|
||||||
)
|
)
|
||||||
/**
|
/**
|
||||||
* Shortcut for [photoMessages]
|
* Shortcut for [photoMessages]
|
||||||
@ -200,7 +201,7 @@ fun FlowsUpdatesFilter.videoMessagesWithMediaGroups(
|
|||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = merge(
|
) = merge(
|
||||||
filterContentMessages<VideoContent>(scopeToIncludeChannels),
|
filterContentMessages<VideoContent>(scopeToIncludeChannels),
|
||||||
mediaGroupVideosMessages(scopeToIncludeChannels).flatMap()
|
mediaGroupVideosMessages(scopeToIncludeChannels).flatten()
|
||||||
)
|
)
|
||||||
|
|
||||||
fun Flow<BaseSentMessageUpdate>.videoNoteMessages() = filterContentMessages<VideoNoteContent>()
|
fun Flow<BaseSentMessageUpdate>.videoNoteMessages() = filterContentMessages<VideoNoteContent>()
|
||||||
|
Loading…
Reference in New Issue
Block a user