1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-30 22:18:43 +00:00

fixes in events builder behaviours

This commit is contained in:
InsanusMokrassar 2021-03-09 22:14:16 +06:00
parent f93d9938de
commit a19b3d26df
2 changed files with 3 additions and 4 deletions

View File

@ -3,8 +3,7 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
import dev.inmo.tgbotapi.extensions.utils.asChatEventMessage import dev.inmo.tgbotapi.extensions.utils.*
import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate
import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.message.ChatEvents.* import dev.inmo.tgbotapi.types.message.ChatEvents.*
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
@ -24,7 +23,7 @@ private suspend fun <O> BehaviourContext.waitEventMessages(
count, count,
errorFactory errorFactory
) { ) {
it.asMessageUpdate() ?.data ?.asChatEventMessage() ?.mapper().let(::listOfNotNull) it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.mapper().let(::listOfNotNull)
}.toList().toList() }.toList().toList()

View File

@ -16,7 +16,7 @@ internal suspend inline fun <reified T : ChatEvent> BehaviourContext.onEvent(
noinline additionalFilter: (suspend (ChatEventMessage<T>) -> Boolean)? = null, noinline additionalFilter: (suspend (ChatEventMessage<T>) -> Boolean)? = null,
noinline scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ChatEventMessage<T>> noinline scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ChatEventMessage<T>>
) = flowsUpdatesFilter.expectFlow(bot) { ) = flowsUpdatesFilter.expectFlow(bot) {
it.asMessageUpdate() ?.data ?.asChatEventMessage() ?.let { message -> it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.let { message ->
if (message.chatEvent is T) { if (message.chatEvent is T) {
val adaptedMessage = message as ChatEventMessage<T> val adaptedMessage = message as ChatEventMessage<T>
if (additionalFilter == null || additionalFilter(adaptedMessage)) adaptedMessage else null if (additionalFilter == null || additionalFilter(adaptedMessage)) adaptedMessage else null