1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-02 06:50:06 +00:00

Compare commits

..

10 Commits

161 changed files with 970 additions and 3436 deletions

View File

@ -1,5 +1,17 @@
# TelegramBotAPI changelog # TelegramBotAPI changelog
## 2.0.0
___ALL PREVIOUS DEPRECATIONS HAVE BEEN REMOVED___
* `Behaviour Builder`:
* 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
* Waiters do not take count parameter anymore
* Waiters do not take filter parameter anymore. Use flows filters
* `Utils`:
* Add opportunity to get event messages with specific `ChatEvent` type using `withEvent`/`requireWithEvent` (by analog with `withEvent` and `requireWithEvent`)
## 1.1.3 ## 1.1.3
* `Behaviour Builder with FSM`: * `Behaviour Builder with FSM`:

View File

@ -20,6 +20,6 @@ javax_activation_version=1.1.1
dokka_version=1.6.21 dokka_version=1.6.21
library_group=dev.inmo library_group=dev.inmo
library_version=1.1.3 library_version=2.0.0
github_release_plugin_version=2.3.7 github_release_plugin_version=2.3.7

View File

@ -1,92 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.edit.LiveLocation
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.chat.Chat
import dev.inmo.tgbotapi.types.location.LiveLocation
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.LocationContent
import dev.inmo.tgbotapi.extensions.api.edit.location.live.editLiveLocation
/**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that
*/
@Deprecated("Replaced", ReplaceWith("editLiveLocation", "dev.inmo.tgbotapi.extensions.api.edit.location.live.editLiveLocation"))
suspend fun TelegramBot.editLiveLocation(
chatId: ChatIdentifier,
messageId: MessageIdentifier,
latitude: Double,
longitude: Double,
horizontalAccuracy: Meters? = null,
heading: Degrees? = null,
proximityAlertRadius: Meters? = null,
replyMarkup: InlineKeyboardMarkup? = null
) = editLiveLocation(chatId, messageId, latitude, longitude, horizontalAccuracy, heading, proximityAlertRadius, replyMarkup)
/**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that
*/
@Deprecated("Replaced", ReplaceWith("editLiveLocation", "dev.inmo.tgbotapi.extensions.api.edit.location.live.editLiveLocation"))
suspend fun TelegramBot.editLiveLocation(
chat: Chat,
messageId: MessageIdentifier,
latitude: Double,
longitude: Double,
horizontalAccuracy: Meters? = null,
heading: Degrees? = null,
proximityAlertRadius: Meters? = null,
replyMarkup: InlineKeyboardMarkup? = null
) = editLiveLocation(chat, messageId, latitude, longitude, horizontalAccuracy, heading, proximityAlertRadius, replyMarkup)
/**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that
*/
@Deprecated("Replaced", ReplaceWith("editLiveLocation", "dev.inmo.tgbotapi.extensions.api.edit.location.live.editLiveLocation"))
suspend fun TelegramBot.editLiveLocation(
message: ContentMessage<LocationContent>,
latitude: Double,
longitude: Double,
horizontalAccuracy: Meters? = null,
heading: Degrees? = null,
proximityAlertRadius: Meters? = null,
replyMarkup: InlineKeyboardMarkup? = null
) = editLiveLocation(message, latitude, longitude, horizontalAccuracy, heading, proximityAlertRadius, replyMarkup)
/**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that
*/
@Deprecated("Replaced", ReplaceWith("editLiveLocation", "dev.inmo.tgbotapi.extensions.api.edit.location.live.editLiveLocation"))
suspend fun TelegramBot.editLiveLocation(
chatId: ChatIdentifier,
messageId: MessageIdentifier,
location: LiveLocation,
replyMarkup: InlineKeyboardMarkup? = null
) = editLiveLocation(chatId, messageId, location, replyMarkup)
/**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that
*/
@Deprecated("Replaced", ReplaceWith("editLiveLocation", "dev.inmo.tgbotapi.extensions.api.edit.location.live.editLiveLocation"))
suspend fun TelegramBot.editLiveLocation(
chat: Chat,
messageId: MessageIdentifier,
location: LiveLocation,
replyMarkup: InlineKeyboardMarkup? = null
) = editLiveLocation(chat, messageId, location, replyMarkup)
/**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that
*/
@Deprecated("Replaced", ReplaceWith("editLiveLocation", "dev.inmo.tgbotapi.extensions.api.edit.location.live.editLiveLocation"))
suspend fun TelegramBot.editLiveLocation(
message: ContentMessage<LocationContent>,
location: LiveLocation,
replyMarkup: InlineKeyboardMarkup? = null
) = editLiveLocation(message, location, replyMarkup)

View File

@ -1,25 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.edit.LiveLocation
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.api.edit.location.live.editLiveLocation
import dev.inmo.tgbotapi.requests.edit.location.live.EditInlineMessageLiveLocation
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.location.LiveLocation
@Deprecated("Replaced", ReplaceWith("editLiveLocation", "dev.inmo.tgbotapi.extensions.api.edit.location.live.editLiveLocation"))
suspend fun TelegramBot.editLiveLocation(
inlineMessageId: InlineMessageIdentifier,
latitude: Double,
longitude: Double,
horizontalAccuracy: Meters? = null,
heading: Degrees? = null,
proximityAlertRadius: Meters? = null,
replyMarkup: InlineKeyboardMarkup? = null
) = editLiveLocation(inlineMessageId, latitude, longitude, horizontalAccuracy, heading, proximityAlertRadius, replyMarkup)
@Deprecated("Replaced", ReplaceWith("editLiveLocation", "dev.inmo.tgbotapi.extensions.api.edit.location.live.editLiveLocation"))
suspend fun TelegramBot.editLiveLocation(
inlineMessageId: InlineMessageIdentifier,
location: LiveLocation,
replyMarkup: InlineKeyboardMarkup? = null
) = editLiveLocation(inlineMessageId, location, replyMarkup)

View File

@ -1,43 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.edit.LiveLocation
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.api.edit.location.live.stopLiveLocation
import dev.inmo.tgbotapi.requests.edit.location.live.StopChatMessageLiveLocation
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.chat.Chat
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.LocationContent
/**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that
*/
@Deprecated("Replaced", ReplaceWith("stopLiveLocation", "dev.inmo.tgbotapi.extensions.api.edit.location.live.stopLiveLocation"))
suspend fun TelegramBot.stopLiveLocation(
chatId: ChatIdentifier,
messageId: MessageIdentifier,
replyMarkup: InlineKeyboardMarkup? = null
) = stopLiveLocation(chatId, messageId, replyMarkup)
/**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that
*/
@Deprecated("Replaced", ReplaceWith("stopLiveLocation", "dev.inmo.tgbotapi.extensions.api.edit.location.live.stopLiveLocation"))
suspend fun TelegramBot.stopLiveLocation(
chat: Chat,
messageId: MessageIdentifier,
replyMarkup: InlineKeyboardMarkup? = null
) = stopLiveLocation(chat, messageId, replyMarkup)
/**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that
*/
@Deprecated("Replaced", ReplaceWith("stopLiveLocation", "dev.inmo.tgbotapi.extensions.api.edit.location.live.stopLiveLocation"))
suspend fun TelegramBot.stopLiveLocation(
message: ContentMessage<LocationContent>,
replyMarkup: InlineKeyboardMarkup? = null
) = stopLiveLocation(message, replyMarkup)

View File

@ -1,17 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.edit.LiveLocation
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.api.edit.location.live.stopLiveLocation
import dev.inmo.tgbotapi.requests.edit.location.live.StopInlineMessageLiveLocation
import dev.inmo.tgbotapi.types.InlineMessageIdentifier
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
/**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that
*/
@Deprecated("Replaced", ReplaceWith("stopLiveLocation", "dev.inmo.tgbotapi.extensions.api.edit.location.live.stopLiveLocation"))
suspend fun TelegramBot.stopLiveLocation(
inlineMessageId: InlineMessageIdentifier,
replyMarkup: InlineKeyboardMarkup? = null
) = stopLiveLocation(inlineMessageId, replyMarkup)

View File

@ -1,42 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.edit.ReplyMarkup
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.api.edit.reply_markup.editMessageReplyMarkup
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.chat.Chat
import dev.inmo.tgbotapi.types.message.abstracts.Message
/**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that
*/
@Deprecated("Replaced", ReplaceWith("editMessageReplyMarkup", "dev.inmo.tgbotapi.extensions.api.edit.reply_markup.editMessageReplyMarkup"))
suspend fun TelegramBot.editMessageReplyMarkup(
chatId: ChatIdentifier,
messageId: MessageIdentifier,
replyMarkup: InlineKeyboardMarkup? = null
) = editMessageReplyMarkup(chatId, messageId, replyMarkup)
/**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that
*/
@Deprecated("Replaced", ReplaceWith("editMessageReplyMarkup", "dev.inmo.tgbotapi.extensions.api.edit.reply_markup.editMessageReplyMarkup"))
suspend fun TelegramBot.editMessageReplyMarkup(
chat: Chat,
messageId: MessageIdentifier,
replyMarkup: InlineKeyboardMarkup? = null
) = editMessageReplyMarkup(chat, messageId, replyMarkup)
/**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that
*/
@Deprecated("Replaced", ReplaceWith("editMessageReplyMarkup", "dev.inmo.tgbotapi.extensions.api.edit.reply_markup.editMessageReplyMarkup"))
suspend fun TelegramBot.editMessageReplyMarkup(
message: Message,
replyMarkup: InlineKeyboardMarkup? = null
) = editMessageReplyMarkup(message, replyMarkup)

View File

@ -1,17 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.edit.ReplyMarkup
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.api.edit.reply_markup.editMessageReplyMarkup
import dev.inmo.tgbotapi.requests.edit.reply_markup.EditInlineMessageReplyMarkup
import dev.inmo.tgbotapi.types.InlineMessageIdentifier
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
/**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that
*/
@Deprecated("Replaced", ReplaceWith("editMessageReplyMarkup", "dev.inmo.tgbotapi.extensions.api.edit.reply_markup.editMessageReplyMarkup"))
suspend fun TelegramBot.editMessageReplyMarkup(
inlineMessageId: InlineMessageIdentifier,
replyMarkup: InlineKeyboardMarkup? = null
) = editMessageReplyMarkup(inlineMessageId, replyMarkup)

View File

@ -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

View File

@ -13,9 +13,6 @@ import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
@Deprecated("Will be removed soon")
typealias BehaviourContextWithFSMBuilder<T> = BehaviourContextWithFSM<T>
/** /**
* Creates [BehaviourContextWithFSM] via creating of [DefaultBehaviourContext] with [this] as [TelegramBot], * Creates [BehaviourContextWithFSM] via creating of [DefaultBehaviourContext] with [this] as [TelegramBot],
* [scope] as target scope for that [DefaultBehaviourContext] and [upstreamUpdatesFlow]. Pass [statesManager] * [scope] as target scope for that [DefaultBehaviourContext] and [upstreamUpdatesFlow]. Pass [statesManager]

View File

@ -1,10 +0,0 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder
import dev.inmo.micro_utils.fsm.common.utils.StateHandlingErrorHandler
@Deprecated("Has been added in microutils", ReplaceWith("StateHandlingErrorHandler", "dev.inmo.micro_utils.fsm.common.utils.StateHandlingErrorHandler"))
typealias StateHandlingErrorHandler<T> = StateHandlingErrorHandler<T>
@Deprecated("Has been added in microutils", ReplaceWith("DefaultStateHandlingErrorHandler", "dev.inmo.micro_utils.fsm.common.utils.DefaultStateHandlingErrorHandler"))
val DefaultStateHandlingErrorHandler = dev.inmo.micro_utils.fsm.common.utils.DefaultStateHandlingErrorHandler
@Deprecated("Has been added in microutils", ReplaceWith("defaultStateHandlingErrorHandler", "dev.inmo.micro_utils.fsm.common.utils.defaultStateHandlingErrorHandler"))
inline fun <T> defaultStateHandlingErrorHandler() = dev.inmo.micro_utils.fsm.common.utils.defaultStateHandlingErrorHandler<T>()

View File

@ -49,6 +49,19 @@ interface BehaviourContext : FlowsUpdatesFilter, TelegramBot, CoroutineScope {
val triggersHolder: TriggersHolder val triggersHolder: TriggersHolder
fun copy(
bot: TelegramBot = this.bot,
scope: CoroutineScope = this.scope,
broadcastChannelsSize: Int = 100,
onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND,
upstreamUpdatesFlow: Flow<Update>? = null,
triggersHolder: TriggersHolder = TriggersHolder()
): BehaviourContext
/**
* @param updatesFilter unused
*/
@Deprecated("Do not use this method")
fun copy( fun copy(
bot: TelegramBot = this.bot, bot: TelegramBot = this.bot,
scope: CoroutineScope = this.scope, scope: CoroutineScope = this.scope,
@ -57,7 +70,7 @@ interface BehaviourContext : FlowsUpdatesFilter, TelegramBot, CoroutineScope {
upstreamUpdatesFlow: Flow<Update>? = null, upstreamUpdatesFlow: Flow<Update>? = null,
triggersHolder: TriggersHolder = TriggersHolder(), triggersHolder: TriggersHolder = TriggersHolder(),
updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>? = null updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>? = null
): BehaviourContext ): BehaviourContext = copy(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, triggersHolder)
} }
class DefaultBehaviourContext( class DefaultBehaviourContext(
@ -67,20 +80,17 @@ class DefaultBehaviourContext(
onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND, onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND,
private val upstreamUpdatesFlow: Flow<Update>? = null, private val upstreamUpdatesFlow: Flow<Update>? = null,
override val triggersHolder: TriggersHolder = TriggersHolder(), override val triggersHolder: TriggersHolder = TriggersHolder(),
@Deprecated("This parameter is not used anymore")
private val updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>? = null private val updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>? = null
) : AbstractFlowsUpdatesFilter(), TelegramBot by bot, CoroutineScope by scope, BehaviourContext { ) : AbstractFlowsUpdatesFilter(), TelegramBot by bot, CoroutineScope by scope, BehaviourContext {
private val additionalUpdatesSharedFlow = MutableSharedFlow<Update>(0, broadcastChannelsSize, onBufferOverflow) private val additionalUpdatesSharedFlow = MutableSharedFlow<Update>(0, broadcastChannelsSize, onBufferOverflow)
override val allUpdatesFlow: Flow<Update> = (additionalUpdatesSharedFlow.asSharedFlow()).let { override val allUpdatesFlow: Flow<Update> = (additionalUpdatesSharedFlow.asSharedFlow()).let {
if (upstreamUpdatesFlow != null) { if (upstreamUpdatesFlow != null) {
(it + upstreamUpdatesFlow).distinctUntilChanged { old, new -> old.updateId == new.updateId } var lastHandledUpdate = -1L
} else { (it + upstreamUpdatesFlow).filter {
it (it.updateId > lastHandledUpdate).also { passed -> if (passed) { lastHandledUpdate = it.updateId } }
} }
}.let {
val updatesFilter = updatesFilter
if (updatesFilter != null) {
it.filter { updatesFilter(it) }
} else { } else {
it it
} }
@ -93,9 +103,8 @@ class DefaultBehaviourContext(
broadcastChannelsSize: Int, broadcastChannelsSize: Int,
onBufferOverflow: BufferOverflow, onBufferOverflow: BufferOverflow,
upstreamUpdatesFlow: Flow<Update>?, upstreamUpdatesFlow: Flow<Update>?,
triggersHolder: TriggersHolder, triggersHolder: TriggersHolder
updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>? ): DefaultBehaviourContext = DefaultBehaviourContext(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, triggersHolder)
): DefaultBehaviourContext = DefaultBehaviourContext(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, triggersHolder, updatesFilter)
} }
fun BehaviourContext( fun BehaviourContext(
@ -113,24 +122,34 @@ inline fun <T> BehaviourContext(
crossinline block: BehaviourContext.() -> T crossinline block: BehaviourContext.() -> T
) = DefaultBehaviourContext(bot, scope, upstreamUpdatesFlow = flowsUpdatesFilter.allUpdatesFlow, triggersHolder = triggersHolder).run(block) ) = DefaultBehaviourContext(bot, scope, upstreamUpdatesFlow = flowsUpdatesFilter.allUpdatesFlow, triggersHolder = triggersHolder).run(block)
/**
* Creates new [BehaviourContext] using its [BehaviourContext.copy] method
*
* @param updatesFilter This param will not be used anymore
*/
fun <BC : BehaviourContext> BC.createSubContext( fun <BC : BehaviourContext> BC.createSubContext(
scope: CoroutineScope = LinkedSupervisorScope(), scope: CoroutineScope = LinkedSupervisorScope(),
triggersHolder: TriggersHolder = this.triggersHolder, triggersHolder: TriggersHolder = this.triggersHolder,
updatesUpstreamFlow: Flow<Update> = allUpdatesFlow, updatesUpstreamFlow: Flow<Update> = allUpdatesFlow,
updatesFilter: CustomBehaviourContextAndTypeReceiver<BC, Boolean, Update>? = null,
) = copy( ) = copy(
scope = scope, scope = scope,
updatesFilter = updatesFilter ?.let { _ ->
{
(this as? BC) ?.run {
updatesFilter(it)
} ?: true
}
},
upstreamUpdatesFlow = updatesUpstreamFlow, upstreamUpdatesFlow = updatesUpstreamFlow,
triggersHolder = triggersHolder triggersHolder = triggersHolder
) as BC ) as BC
/**
* Creates new [BehaviourContext] using its [BehaviourContext.copy] method
*
* @param updatesFilter This param will not be used anymore
*/
@Deprecated("It is not recommended to use updates filter anymore")
fun <BC : BehaviourContext> BC.createSubContext(
scope: CoroutineScope = LinkedSupervisorScope(),
triggersHolder: TriggersHolder = this.triggersHolder,
updatesUpstreamFlow: Flow<Update> = allUpdatesFlow,
updatesFilter: CustomBehaviourContextAndTypeReceiver<BC, Boolean, Update>?,
) = createSubContext(scope, triggersHolder, updatesUpstreamFlow)
/** /**
* Launch [behaviourContextReceiver] in context of [this] as [BehaviourContext] and as [kotlin.coroutines.CoroutineContext] * Launch [behaviourContextReceiver] in context of [this] as [BehaviourContext] and as [kotlin.coroutines.CoroutineContext]
* *
@ -155,15 +174,13 @@ suspend fun <T, BC : BehaviourContext> BC.createSubContextAndDoWithUpdatesFilter
scope: CoroutineScope = LinkedSupervisorScope(), scope: CoroutineScope = LinkedSupervisorScope(),
triggersHolder: TriggersHolder = this.triggersHolder, triggersHolder: TriggersHolder = this.triggersHolder,
updatesUpstreamFlow: Flow<Update> = allUpdatesFlow, updatesUpstreamFlow: Flow<Update> = allUpdatesFlow,
updatesFilter: CustomBehaviourContextAndTypeReceiver<BC, Boolean, Update>? = null,
stopOnCompletion: Boolean = true, stopOnCompletion: Boolean = true,
behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T> behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>
): T { ): T {
return createSubContext( return createSubContext(
scope, scope,
triggersHolder, triggersHolder,
updatesUpstreamFlow, updatesUpstreamFlow
updatesFilter
).doInContext( ).doInContext(
stopOnCompletion, stopOnCompletion,
behaviourContextReceiver behaviourContextReceiver
@ -175,43 +192,22 @@ suspend fun <T, BC : BehaviourContext> BC.createSubContextAndDoWithUpdatesFilter
* using [doInContext] * using [doInContext]
* *
* @param stopOnCompletion ___TRUE BY DEFAULT___ * @param stopOnCompletion ___TRUE BY DEFAULT___
* @param updatesFilter Is not used anymore
*/ */
@Deprecated("Renamed", ReplaceWith("createSubContextAndDoWithUpdatesFilter", "dev.inmo.tgbotapi.extensions.behaviour_builder.createSubContextAndDoWithUpdatesFilter")) @Deprecated("It is not recommended to use updates filter anymore")
suspend fun <T, BC : BehaviourContext> BC.doInSubContextWithUpdatesFilter( suspend fun <T, BC : BehaviourContext> BC.createSubContextAndDoWithUpdatesFilter(
scope: CoroutineScope = LinkedSupervisorScope(),
triggersHolder: TriggersHolder = this.triggersHolder,
updatesUpstreamFlow: Flow<Update> = allUpdatesFlow,
updatesFilter: CustomBehaviourContextAndTypeReceiver<BC, Boolean, Update>?, updatesFilter: CustomBehaviourContextAndTypeReceiver<BC, Boolean, Update>?,
stopOnCompletion: Boolean = true, stopOnCompletion: Boolean = true,
updatesUpstreamFlow: Flow<Update> = allUpdatesFlow,
scope: CoroutineScope = LinkedSupervisorScope(),
triggersHolder: TriggersHolder = this.triggersHolder,
behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T> behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>
): T { ): T {
return createSubContext( return createSubContextAndDoWithUpdatesFilter(
scope, scope, triggersHolder, updatesUpstreamFlow, stopOnCompletion, behaviourContextReceiver
triggersHolder,
updatesUpstreamFlow,
updatesFilter
).doInContext(
stopOnCompletion,
behaviourContextReceiver
) )
} }
@Deprecated("Redundant", ReplaceWith("createSubContextAndDoWithUpdatesFilter", "dev.inmo.tgbotapi.extensions.behaviour_builder.createSubContextAndDoWithUpdatesFilter"))
suspend fun <T> BehaviourContext.doInSubContext(
stopOnCompletion: Boolean = true,
updatesUpstreamFlow: Flow<Update> = allUpdatesFlow,
scope: CoroutineScope = LinkedSupervisorScope(),
triggersHolder: TriggersHolder = this.triggersHolder,
behaviourContextReceiver: BehaviourContextReceiver<T>
) = createSubContextAndDoWithUpdatesFilter(
scope,
triggersHolder,
updatesUpstreamFlow,
updatesFilter = null,
stopOnCompletion,
behaviourContextReceiver
)
/** /**
* This method will cancel ALL subsequent contexts, expectations and waiters * This method will cancel ALL subsequent contexts, expectations and waiters
*/ */

View File

@ -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 },

View File

@ -7,118 +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 fun <O> BehaviourContext.waitCallbackQueries( @RiskFeature(lowLevelRiskFeatureMessage)
count: Int = 1, suspend inline fun <reified O> BehaviourContext.waitCallbackQueries(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, noinline errorFactory: NullableRequestBuilder<*> = { null }
filter: SimpleFilter<CallbackQuery>? = null, ): Flow<O> = expectFlow(
mapper: suspend CallbackQuery.() -> O?
): List<O> = expectFlow(
initRequest, initRequest,
count,
errorFactory errorFactory
) { ) {
val data = it.asCallbackQueryUpdate() ?.data (it.asCallbackQueryUpdate() ?.data as O).let(::listOfNotNull)
if (data != null && (filter == null || filter(data))) {
data.mapper().let(::listOfNotNull)
} else {
emptyList()
}
}.toList().toList()
private suspend inline fun <reified T : CallbackQuery> BehaviourContext.waitCallbacks(
count: Int = 1,
initRequest: Request<*>? = null,
noinline errorFactory: NullableRequestBuilder<*> = { null },
filter: SimpleFilter<T>? = null,
noinline mapper: CallbackQueryMapper<T>? = null
) : List<T> = waitCallbackQueries<T>(
count,
initRequest,
errorFactory,
filter ?.let {
{
(it as? T) ?.let { filter(it) } == true
}
}
) {
if (this is T) {
if (mapper == null) {
this
} else {
mapper(this)
}
} else {
null
}
} }
suspend fun BehaviourContext.waitDataCallbackQuery( 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,
mapper: CallbackQueryMapper<DataCallbackQuery>? = null
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)
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,
mapper: CallbackQueryMapper<GameShortNameCallbackQuery>? = null
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)
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,
mapper: CallbackQueryMapper<InlineMessageIdCallbackQuery>? = null
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)
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,
mapper: CallbackQueryMapper<InlineMessageIdDataCallbackQuery>? = null
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)
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,
mapper: CallbackQueryMapper<InlineMessageIdGameShortNameCallbackQuery>? = null
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)
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,
mapper: CallbackQueryMapper<MessageCallbackQuery>? = null
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)
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,
mapper: CallbackQueryMapper<MessageDataCallbackQuery>? = null
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)
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,
mapper: CallbackQueryMapper<MessageGameShortNameCallbackQuery>? = null
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)
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,
mapper: CallbackQueryMapper<UnknownCallbackQueryType>? = null
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)

View File

@ -5,45 +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 fun <O> BehaviourContext.waitChatJoinRequests( @RiskFeature(lowLevelRiskFeatureMessage)
count: Int = 1, suspend inline fun <reified O> BehaviourContext.internalWaitChatJoinRequests(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, noinline errorFactory: NullableRequestBuilder<*> = { null }
filter: SimpleFilter<ChatJoinRequest>? = null, ): Flow<O> = expectFlow(
mapper: suspend ChatJoinRequest.() -> O?
): List<O> = expectFlow(
initRequest, initRequest,
count,
errorFactory errorFactory
) { ) {
val data = it.asChatJoinRequestUpdate() ?.data (it.asChatJoinRequestUpdate() ?.data as? O).let(::listOfNotNull)
if (data != null && (filter == null || filter(data))) { }
data.mapper().let(::listOfNotNull)
} 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,
mapper: ChatJoinRequestsMapper? = null
) : List<ChatJoinRequest> = waitChatJoinRequests(
count,
initRequest, initRequest,
errorFactory, errorFactory
filter )
) {
if (mapper == null) {
this
} else {
mapper(this)
}
}

View File

@ -7,68 +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.waitChatMemberUpdated( @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(
noinline mapper: ChatMemberUpdatedMapper<ChatMemberUpdated>
): 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)) {
casted.data.mapper().let(::listOfNotNull)
} else {
emptyList()
}
}.toList().toList()
private suspend inline fun <reified T : ChatMemberUpdatedUpdate> BehaviourContext.waitChatMemberUpdatedWithFilter(
count: Int = 1,
initRequest: Request<*>? = null,
noinline errorFactory: NullableRequestBuilder<*> = { null },
filter: SimpleFilter<T>? = null,
noinline mapper: ChatMemberUpdatedMapper<ChatMemberUpdated>? = null
) : List<ChatMemberUpdated> = waitChatMemberUpdated<T>(
count,
initRequest,
errorFactory,
filter,
) {
if (mapper == null) {
this
} else {
mapper(this)
}
} }
suspend fun BehaviourContext.waitChatMemberUpdated( 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,
mapper: ChatMemberUpdatedMapper<ChatMemberUpdated>? = null
) = waitChatMemberUpdatedWithFilter<ChatMemberUpdatedUpdate>(count, initRequest, errorFactory, filter, mapper)
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,
mapper: ChatMemberUpdatedMapper<ChatMemberUpdated>? = null
) = waitChatMemberUpdatedWithFilter<CommonChatMemberUpdatedUpdate>(count, initRequest, errorFactory, filter, mapper)
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,
mapper: ChatMemberUpdatedMapper<ChatMemberUpdated>? = null
) = waitChatMemberUpdatedWithFilter<MyChatMemberUpdatedUpdate>(count, initRequest, errorFactory, filter, mapper)

View File

@ -5,77 +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 fun <O> BehaviourContext.waitChosenInlineResultsUpdates( @RiskFeature(lowLevelRiskFeatureMessage)
count: Int = 1, suspend inline fun <reified O> BehaviourContext.waitChosenInlineResults(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, noinline errorFactory: NullableRequestBuilder<*> = { null }
filter: SimpleFilter<ChosenInlineResult>? = null, ): Flow<O> = expectFlow(
mapper: suspend ChosenInlineResult.() -> O?
): List<O> = expectFlow(
initRequest, initRequest,
count,
errorFactory errorFactory
) { ) {
val data = it.asChosenInlineResultUpdate() ?.data (it.asChosenInlineResultUpdate() ?.data as? O).let(::listOfNotNull)
if (data != null && (filter == null || filter(data))) {
data.mapper().let(::listOfNotNull)
} else {
emptyList()
}
}.toList().toList()
private suspend inline fun <reified T : ChosenInlineResult> BehaviourContext.waitChosenInlineResults(
count: Int = 1,
initRequest: Request<*>? = null,
noinline errorFactory: NullableRequestBuilder<*> = { null },
filter: SimpleFilter<T>? = null,
noinline mapper: ChosenInlineResultMapper<T>? = null
) : List<T> = this@waitChosenInlineResults.waitChosenInlineResultsUpdates<T>(
count,
initRequest,
errorFactory,
filter ?.let {
{
(it as? T) ?.let { filter(it) } == true
}
}
) {
if (this is T) {
if (mapper == null) {
this
} else {
mapper(this)
}
} else {
null
}
} }
suspend fun BehaviourContext.waitChosenInlineResult( 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,
mapper: ChosenInlineResultMapper<ChosenInlineResult>? = null
) = waitChosenInlineResults(count, initRequest, errorFactory, filter, mapper)
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,
mapper: PollMapper<LocationChosenInlineResult>? = null
) = waitChosenInlineResults(count, initRequest, errorFactory, filter, mapper)
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,
mapper: PollMapper<BaseChosenInlineResult>? = null
) = waitChosenInlineResults(count, initRequest, errorFactory, filter, mapper)

View File

@ -2,7 +2,6 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
import dev.inmo.tgbotapi.extensions.utils.withContent import dev.inmo.tgbotapi.extensions.utils.withContent
@ -16,262 +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.toList import kotlinx.coroutines.flow.map
typealias CommonMessageToContentMapper<T> = suspend CommonMessage<T>.() -> T? typealias CommonMessageToContentMapper<T> = suspend CommonMessage<T>.() -> T?
private suspend fun <O> BehaviourContext.waitCommonContent( @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,
errorFactory: NullableRequestBuilder<*> = { null }, noinline errorFactory: NullableRequestBuilder<*> = { null }
filter: SimpleFilter<CommonMessage<MessageContent>>? = null, ): Flow<O> = waitContentMessage<O>(initRequest, includeMediaGroups, errorFactory).map { it.content }
mapper: suspend CommonMessage<MessageContent>.() -> O?
): Flow<O> = expectFlow(
initRequest,
count,
errorFactory
) {
val messages = when (it) {
is SentMediaGroupUpdate -> {
if (includeMediaGroups) {
it.data.map { it as CommonMessage<MessageContent> }
} else {
emptyList()
}
}
is BaseSentMessageUpdate -> listOf(it.data)
else -> return@expectFlow emptyList()
}
messages.mapNotNull { message ->
val asCommonMessage = message as CommonMessage<MessageContent>
if (filter == null || filter(asCommonMessage)) {
asCommonMessage.mapper()
} else {
null
}
}
}
internal inline fun <reified T : MessageContent> contentConverter(
noinline mapper: CommonMessageToContentMapper<T>? = null
): suspend CommonMessage<MessageContent>.() -> T? = mapper ?.let {
{
if (content is T) {
@Suppress("UNCHECKED_CAST")
val message = (this as CommonMessage<T>)
safelyWithoutExceptions { mapper(message) }
} else {
null
}
}
} ?: { content as? T }
private suspend inline fun <reified T : MessageContent> BehaviourContext.waitContent(
count: Int = 1,
initRequest: Request<*>? = null,
includeMediaGroups: Boolean = true,
noinline errorFactory: NullableRequestBuilder<*> = { null },
filter: SimpleFilter<CommonMessage<T>>? = null,
noinline mapper: CommonMessageToContentMapper<T>? = null
) : List<T> = waitCommonContent<T>(
count,
initRequest,
includeMediaGroups,
errorFactory,
filter ?.let {
{
it.withContent<T>() ?.let { filter(it) } == true
}
},
contentConverter(mapper)
).toList()
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,
mapper: CommonMessageToContentMapper<MessageContent>? = null
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<ContactContent>? = null
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<DiceContent>? = null
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<GameContent>? = null
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<LocationContent>? = null
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<LiveLocationContent>? = null
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<StaticLocationContent>? = null
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<PollContent>? = null
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<TextContent>? = null
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<VenueContent>? = null
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<AudioMediaGroupContent>? = null
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<DocumentMediaGroupContent>? = null
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<MediaContent>? = null
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<MediaGroupContent>? = null
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<VisualMediaGroupContent>? = null
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<TextedMediaContent>? = null
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<AnimationContent>? = null
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<AudioContent>? = null
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<DocumentContent>? = null
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<PhotoContent>? = null
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<StickerContent>? = null
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<VideoContent>? = null
) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<VideoNoteContent>? = null
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<VoiceContent>? = null
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<InvoiceContent>? = null
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)

View File

@ -16,21 +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
import kotlinx.coroutines.flow.toList
typealias CommonMessageToCommonMessageMapper<T> = suspend CommonMessage<T>.() -> CommonMessage<T>? typealias CommonMessageToCommonMessageMapper<T> = suspend CommonMessage<T>.() -> CommonMessage<T>?
internal suspend fun <O : MessageContent> BehaviourContext.waitCommonMessage( @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,
errorFactory: NullableRequestBuilder<*> = { null }, noinline errorFactory: NullableRequestBuilder<*> = { null }
filter: SimpleFilter<CommonMessage<MessageContent>>? = null,
mapper: suspend CommonMessage<MessageContent>.() -> CommonMessage<O>?
): Flow<CommonMessage<O>> = expectFlow( ): Flow<CommonMessage<O>> = expectFlow(
initRequest, initRequest,
count,
errorFactory errorFactory
) { ) {
val messages = when (it) { val messages = when (it) {
@ -45,13 +43,7 @@ internal suspend fun <O : MessageContent> BehaviourContext.waitCommonMessage(
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<MessageContent> ?: return@mapNotNull null
if (filter == null || filter(asCommonMessage)) {
asCommonMessage.mapper()
} else {
null
}
} }
} }
@ -72,209 +64,114 @@ internal inline fun <reified T : MessageContent> contentMessageConverter(
if (content is T) this as CommonMessage<T> else null if (content is T) this as CommonMessage<T> else null
} }
private suspend inline fun <reified T : MessageContent> BehaviourContext.waitContentMessage(
count: Int = 1,
initRequest: Request<*>? = null,
includeMediaGroups: Boolean = true,
noinline errorFactory: NullableRequestBuilder<*> = { null },
filter: SimpleFilter<CommonMessage<T>>? = null,
noinline mapper: CommonMessageToCommonMessageMapper<T>? = null
) : List<CommonMessage<T>> = waitCommonMessage<T>(
count,
initRequest,
includeMediaGroups,
errorFactory,
filter ?.let {
{
it.withContent<T>() ?.let { filter(it) } == true
}
},
contentMessageConverter(mapper)
).toList()
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,
mapper: CommonMessageToCommonMessageMapper<MessageContent>? = null
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<ContactContent>? = null
) = waitContentMessage(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<DiceContent>? = null
) = waitContentMessage(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<GameContent>? = null
) = waitContentMessage(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<LocationContent>? = null
) = waitContentMessage(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<LiveLocationContent>? = null
) = waitContentMessage(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<StaticLocationContent>? = null
) = waitContentMessage(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<PollContent>? = null
) = waitContentMessage(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<TextContent>? = null
) = waitContentMessage(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<VenueContent>? = null
) = waitContentMessage(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<AudioMediaGroupContent>? = null
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<DocumentMediaGroupContent>? = null
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<MediaContent>? = null
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<MediaGroupContent>? = null
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<VisualMediaGroupContent>? = null
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<TextedMediaContent>? = null
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<AnimationContent>? = null
) = waitContentMessage(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<AudioContent>? = null
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<DocumentContent>? = null
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<PhotoContent>? = null
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<StickerContent>? = null
) = waitContentMessage(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<VideoContent>? = null
) = waitContentMessage(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<VideoNoteContent>? = null
) = waitContentMessage(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<VoiceContent>? = null
) = waitContentMessage(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToCommonMessageMapper<InvoiceContent>? = null
) = waitContentMessage(count, initRequest, false, errorFactory, filter, mapper)

View File

@ -16,237 +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 fun <O> BehaviourContext.waitEditedCommonMessage( @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 }
): Flow<O> = waitEditedContentMessage<O>(initRequest, includeMediaGroups, errorFactory).map { it.content }
suspend fun BehaviourContext.waitEditedMessageContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
filter: SimpleFilter<CommonMessage<MessageContent>>? = null, includeMediaGroups: Boolean = true
mapper: suspend CommonMessage<MessageContent>.() -> O? ) = waitEditedContent<MessageContent>(initRequest, includeMediaGroups, errorFactory)
): List<O> = expectFlow(
initRequest,
count,
errorFactory
) {
val messages = when (it) {
is BaseEditMessageUpdate -> {
val commonMessage = it.data.asCommonMessage()
if (commonMessage !is MediaGroupMessage<*> || includeMediaGroups) {
listOf(commonMessage)
} else {
emptyList()
}
}
else -> return@expectFlow emptyList()
}
messages.mapNotNull { message ->
val asCommonMessage = message as CommonMessage<MessageContent>
if (filter == null || filter(asCommonMessage)) {
asCommonMessage.mapper()
} else {
null
}
}
}.toList().toList()
private suspend inline fun <reified T : MessageContent> BehaviourContext.waitEditedContent(
count: Int = 1,
initRequest: Request<*>? = null,
includeMediaGroups: Boolean = true,
noinline errorFactory: NullableRequestBuilder<*> = { null },
filter: SimpleFilter<CommonMessage<T>>? = null,
noinline mapper: CommonMessageToContentMapper<T>? = null
) : List<T> = waitEditedCommonMessage<T>(
count,
initRequest,
includeMediaGroups,
errorFactory,
filter ?.let {
{
it.withContent<T>() ?.let { filter(it) } == true
}
},
contentConverter(mapper)
)
suspend fun BehaviourContext.waitEditedContentMessage( 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,
mapper: CommonMessageToContentMapper<MessageContent>? = null
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<ContactContent>? = null
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<DiceContent>? = null
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<GameContent>? = null
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<LocationContent>? = null
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<LiveLocationContent>? = null
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<StaticLocationContent>? = null
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<TextContent>? = null
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<VenueContent>? = null
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<AudioMediaGroupContent>? = null
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<DocumentMediaGroupContent>? = null
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<MediaContent>? = null
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<MediaGroupContent>? = null
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<VisualMediaGroupContent>? = null
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<TextedMediaContent>? = null
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<AnimationContent>? = null
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<AudioContent>? = null
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<DocumentContent>? = null
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<PhotoContent>? = null
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<StickerContent>? = null
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<VideoContent>? = null
) = waitEditedContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<VideoNoteContent>? = null
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<VoiceContent>? = null
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
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,
mapper: CommonMessageToContentMapper<InvoiceContent>? = null
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)

View File

@ -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)

View File

@ -4,8 +4,7 @@ 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.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
import dev.inmo.tgbotapi.extensions.utils.asBaseSentMessageUpdate import dev.inmo.tgbotapi.extensions.utils.*
import dev.inmo.tgbotapi.extensions.utils.asChatEventMessage
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.*
@ -13,272 +12,130 @@ 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 fun <O> BehaviourContext.waitEventMessages( @RiskFeature(lowLevelRiskFeatureMessage)
suspend inline fun <reified O : ChatEvent> BehaviourContext.waitEvents(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, noinline errorFactory: NullableRequestBuilder<*> = { null }
count: Int = 1, ): Flow<O> = expectFlow(
filter: SimpleFilter<ChatEventMessage<ChatEvent>>? = null,
mapper: suspend ChatEventMessage<ChatEvent>.() -> O?
): List<O> = expectFlow(
initRequest, initRequest,
count,
errorFactory errorFactory
) { ) {
val data = it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.withEvent<O>() ?.chatEvent.let(::listOfNotNull)
if (data != null && (filter == null || filter(data))) {
data.mapper().let(::listOfNotNull)
} else {
emptyList()
}
}.toList().toList()
private suspend inline fun <reified T : ChatEvent> BehaviourContext.waitEvents(
count: Int = 1,
initRequest: Request<*>? = null,
noinline errorFactory: NullableRequestBuilder<*> = { null },
filter: SimpleFilter<ChatEventMessage<T>>? = null,
noinline mapper: EventMessageToEventMapper<T>? = null
) : List<T> = waitEventMessages<T>(
initRequest,
errorFactory,
count,
filter ?.let {
{
(it.chatEvent as? T) ?.let { filter(it as ChatEventMessage<T>) } == true
}
}
) {
if (chatEvent is T) {
@Suppress("UNCHECKED_CAST")
val message = (this as ChatEventMessage<T>)
if (mapper == null) {
message.chatEvent
} else {
mapper(message)
}
} else {
null
}
} }
suspend fun BehaviourContext.waitChannelEvents( 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,
mapper: EventMessageToEventMapper<ChannelEvent>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<PrivateEvent>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<ChatEvent>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
@Deprecated("Renamed as Video instead of Voice")
suspend fun BehaviourContext.waitVoiceChatEvents(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
count: Int = 1,
filter: SimpleFilter<ChatEventMessage<VideoChatEvent>>? = null,
mapper: EventMessageToEventMapper<VideoChatEvent>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
@Deprecated("Renamed as Video instead of Voice")
suspend fun BehaviourContext.waitVoiceChatStartedEvents(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
count: Int = 1,
filter: SimpleFilter<ChatEventMessage<VideoChatStarted>>? = null,
mapper: EventMessageToEventMapper<VideoChatStarted>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
@Deprecated("Renamed as Video instead of Voice")
suspend fun BehaviourContext.waitVoiceChatEndedEvents(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
count: Int = 1,
filter: SimpleFilter<ChatEventMessage<VideoChatEnded>>? = null,
mapper: EventMessageToEventMapper<VideoChatEnded>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
@Deprecated("Renamed as Video instead of Voice")
suspend fun BehaviourContext.waitVoiceChatParticipantsInvitedEvents(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
count: Int = 1,
filter: SimpleFilter<ChatEventMessage<VideoChatParticipantsInvited>>? = null,
mapper: EventMessageToEventMapper<VideoChatParticipantsInvited>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<VideoChatEvent>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<VideoChatStarted>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<VideoChatEnded>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<VideoChatParticipantsInvited>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<MessageAutoDeleteTimerChanged>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<PublicChatEvent>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<CommonEvent>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<GroupEvent>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<SupergroupEvent>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<ChannelChatCreated>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<DeleteChatPhoto>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<GroupChatCreated>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<LeftChatMember>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<NewChatPhoto>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<NewChatMembers>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<NewChatTitle>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<PinnedMessage>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<ProximityAlertTriggered>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<SupergroupChatCreated>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<SuccessfulPaymentEvent>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<UserLoggedIn>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
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,
mapper: EventMessageToEventMapper<WebAppData>? = null
) = waitEvents(count, initRequest, errorFactory, filter ?.let { { it is PrivateEventMessage && filter(it) } }, mapper)

View File

@ -0,0 +1,138 @@
@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)
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)

View File

@ -5,76 +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 fun <O> BehaviourContext.waitInlineQueries( @RiskFeature(lowLevelRiskFeatureMessage)
count: Int = 1, suspend inline fun <reified O : InlineQuery> BehaviourContext.waitInlineQueries(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, noinline errorFactory: NullableRequestBuilder<*> = { null }
filter: SimpleFilter<InlineQuery>? = null, ): Flow<O> = expectFlow(
mapper: suspend InlineQuery.() -> O?
): List<O> = expectFlow(
initRequest, initRequest,
count,
errorFactory errorFactory
) { ) {
val data = it.asInlineQueryUpdate() ?.data (it.asInlineQueryUpdate() ?.data as? O).let(::listOfNotNull)
if (data != null && (filter == null || filter(data))) {
data.mapper().let(::listOfNotNull)
} else {
emptyList()
}
}.toList().toList()
private suspend inline fun <reified T : InlineQuery> BehaviourContext.waitInlines(
count: Int = 1,
initRequest: Request<*>? = null,
noinline errorFactory: NullableRequestBuilder<*> = { null },
filter: SimpleFilter<T>? = null,
noinline mapper: InlineQueryMapper<T>? = null
) : List<T> = waitInlineQueries<T>(
count,
initRequest,
errorFactory,
filter ?.let {
{
(it as? T) ?.let { casted -> filter(casted) } == true
}
}
) {
if (this is T) {
if (mapper == null) {
this
} else {
mapper(this)
}
} else {
null
}
} }
suspend fun BehaviourContext.waitAnyInlineQuery( 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,
mapper: InlineQueryMapper<InlineQuery>? = null
) = waitInlines(count, initRequest, errorFactory, filter, mapper)
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,
mapper: InlineQueryMapper<BaseInlineQuery>? = null
) = waitInlines(count, initRequest, errorFactory, filter, mapper)
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,
mapper: InlineQueryMapper<LocationInlineQuery>? = null
) = waitInlines(count, initRequest, errorFactory, filter, mapper)

View File

@ -1,7 +1,9 @@
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.behaviour_builder.utils.SimpleFilter
import dev.inmo.tgbotapi.extensions.utils.asSentMediaGroupUpdate 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.requests.abstracts.Request
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.content.* import dev.inmo.tgbotapi.types.message.content.*
@ -9,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 dev.inmo.tgbotapi.utils.PreviewFeature import dev.inmo.tgbotapi.utils.RiskFeature
import kotlinx.coroutines.flow.take import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
import kotlinx.coroutines.flow.toList import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
typealias MediaGroupFilter<T> = suspend List<MediaGroupMessage<T>>.() -> Boolean 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 }
noinline filter: MediaGroupFilter<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 ->
if (mediaGroup.all { message -> message.content is T } && (filter == null || filter(mediaGroup as List<MediaGroupMessage<T>>))) {
listOf(
mediaGroup.map { it.content as T }
)
} else {
null
}
} ?: emptyList()
}.take(count).toList()
suspend fun BehaviourContext.waitMediaGroup( suspend fun BehaviourContext.waitMediaGroup(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null }
count: Int = 1, ) = buildMediaGroupWaiter<MediaGroupContent>(initRequest, errorFactory)
filter: MediaGroupFilter<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: MediaGroupFilter<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: MediaGroupFilter<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: MediaGroupFilter<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: MediaGroupFilter<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: MediaGroupFilter<VideoContent>? = null
) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter)

View File

@ -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)

View File

@ -9,57 +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 fun <O> BehaviourContext.waitPassportMessages( suspend inline fun <reified O : EncryptedPassportElement> BehaviourContext.waitPassportMessagesWith(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, noinline errorFactory: NullableRequestBuilder<*> = { null }
count: Int = 1, ): Flow<O> = expectFlow(
filter: SimpleFilter<PassportMessage>? = null,
mapper: suspend PassportMessage.() -> O?
): 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.mapper().let(::listOfNotNull)
} else {
emptyList()
}
}.toList().toList()
suspend inline fun <reified T : EncryptedPassportElement> BehaviourContext.waitPassportMessagesWith(
count: Int = 1,
initRequest: Request<*>? = null,
noinline errorFactory: NullableRequestBuilder<*> = { null },
filter: SimpleFilter<PassportMessage>? = null,
noinline mapper: PassportMessageMapper? = null
) : List<PassportData> = waitPassportMessages(
initRequest,
errorFactory,
count,
filter
) {
if (passportData.data.any { it is T }) {
if (mapper == null) {
passportData
} else {
mapper(this)
}
} else {
null
}
} }
suspend fun BehaviourContext.waitAnyPassportMessages( 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,
mapper: PassportMessageMapper? = null
) = waitPassportMessagesWith<EncryptedPassportElement>(count, initRequest, errorFactory, filter, mapper)

View File

@ -5,60 +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 fun <O> BehaviourContext.waitPollsAnswers(
count: Int = 1,
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
filter: SimpleFilter<PollAnswer>? = null,
mapper: suspend PollAnswer.() -> O?
): List<O> = expectFlow(
initRequest,
count,
errorFactory
) {
val data = it.asPollAnswerUpdate() ?.data
if (data != null && (filter == null || filter(data))) {
data.mapper().let(::listOfNotNull)
} else {
emptyList()
}
}.toList().toList()
private suspend inline fun BehaviourContext.waitPollAnswers(
count: Int = 1,
initRequest: Request<*>? = null,
noinline errorFactory: NullableRequestBuilder<*> = { null },
filter: SimpleFilter<PollAnswer>? = null,
noinline mapper: PollAnswerMapper? = null
) : List<PollAnswer> = this@waitPollAnswers.waitPollsAnswers<PollAnswer>(
count,
initRequest,
errorFactory,
filter ?.let {
{
(it as? PollAnswer) ?.let { filter(it) } == true
}
}
) {
if (mapper == null) {
this
} else {
mapper(this)
}
}
/**
* 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,
mapper: PollAnswerMapper? = null errorFactory
) = waitPollAnswers(count, initRequest, errorFactory, filter, mapper) ) {
it.asPollAnswerUpdate() ?.data.let(::listOfNotNull)
}

View File

@ -5,55 +5,22 @@ 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 fun <O> BehaviourContext.waitPollsUpdates( @RiskFeature(lowLevelRiskFeatureMessage)
count: Int = 1, suspend inline fun <reified O : Poll> BehaviourContext.waitPolls(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, noinline errorFactory: NullableRequestBuilder<*> = { null }
filter: SimpleFilter<Poll>? = null, ): Flow<O> = expectFlow(
mapper: suspend Poll.() -> O?
): List<O> = expectFlow(
initRequest, initRequest,
count,
errorFactory errorFactory
) { ) {
val data = it.asPollUpdate() ?.data (it.asPollUpdate() ?.data as? O).let(::listOfNotNull)
if (data != null && (filter == null || filter(data))) {
data.mapper().let(::listOfNotNull)
} else {
emptyList()
}
}.toList().toList()
private suspend inline fun <reified T : Poll> BehaviourContext.waitPolls(
count: Int = 1,
initRequest: Request<*>? = null,
noinline errorFactory: NullableRequestBuilder<*> = { null },
filter: SimpleFilter<T>? = null,
noinline mapper: PollMapper<T>? = null
) : List<T> = this@waitPolls.waitPollsUpdates<T>(
count,
initRequest,
errorFactory,
filter ?.let {
{
(it as? T) ?.let { filter(it) } == true
}
}
) {
if (this is T) {
if (mapper == null) {
this
} else {
mapper(this)
}
} else {
null
}
} }
/** /**
@ -61,30 +28,21 @@ private suspend inline fun <reified T : Poll> BehaviourContext.waitPolls(
*/ */
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,
mapper: PollMapper<Poll>? = null
) = waitPolls(count, initRequest, errorFactory, filter, mapper)
/** /**
* This wait will be triggered only for stopped polls and polls, which are sent by the bot * 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,
mapper: PollMapper<QuizPoll>? = null
) = waitPolls(count, initRequest, errorFactory, filter, mapper)
/** /**
* This wait will be triggered only for stopped polls and polls, which are sent by the bot * 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,
mapper: PollMapper<RegularPoll>? = null
) = waitPolls(count, initRequest, errorFactory, filter, mapper)

View File

@ -5,45 +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 fun <O> BehaviourContext.waitPreCheckoutQueries(
count: Int = 1,
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
filter: SimpleFilter<PreCheckoutQuery>? = null,
mapper: suspend PreCheckoutQuery.() -> O?
): List<O> = expectFlow(
initRequest,
count,
errorFactory
) {
val data = it.asPreCheckoutQueryUpdate() ?.data
if (data != null && (filter == null || filter(data))) {
data.mapper().let(::listOfNotNull)
} else {
emptyList()
}
}.toList().toList()
suspend fun BehaviourContext.waitPreCheckoutQueries( 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,
mapper: PreCheckoutQueryMapper? = null
) : List<PreCheckoutQuery> = waitPreCheckoutQueries(
count,
initRequest, initRequest,
errorFactory, errorFactory
filter
) { ) {
if (mapper == null) { it.asPreCheckoutQueryUpdate() ?.data.let(::listOfNotNull)
this
} else {
mapper(this)
}
} }

View File

@ -5,45 +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 fun <O> BehaviourContext.waitShippingQueries(
count: Int = 1,
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
filter: SimpleFilter<ShippingQuery>? = null,
mapper: suspend ShippingQuery.() -> O?
): List<O> = expectFlow(
initRequest,
count,
errorFactory
) {
val data = it.asShippingQueryUpdate() ?.data
if (data != null && (filter == null || filter(data))) {
data.mapper().let(::listOfNotNull)
} else {
emptyList()
}
}.toList().toList()
suspend fun BehaviourContext.waitShippingQueries( 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,
mapper: ShippingQueryMapper? = null
) : List<ShippingQuery> = waitShippingQueries(
count,
initRequest, initRequest,
errorFactory, errorFactory
filter
) { ) {
if (mapper == null) { (it.asShippingQueryUpdate() ?.data).let(::listOfNotNull)
this
} else {
mapper(this)
}
} }

View File

@ -25,7 +25,6 @@ import dev.inmo.tgbotapi.extensions.utils.withContent
import dev.inmo.tgbotapi.types.files.TelegramMediaFile import dev.inmo.tgbotapi.types.files.TelegramMediaFile
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
import dev.inmo.tgbotapi.types.message.content.* import dev.inmo.tgbotapi.types.message.content.*
import dev.inmo.tgbotapi.types.message.content.abstracts.*
import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent 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.InvoiceContent import dev.inmo.tgbotapi.types.message.content.InvoiceContent
@ -34,7 +33,6 @@ import dev.inmo.tgbotapi.types.message.content.MediaContent
import dev.inmo.tgbotapi.types.message.content.MessageContent import dev.inmo.tgbotapi.types.message.content.MessageContent
import dev.inmo.tgbotapi.types.update.abstracts.BaseEditMessageUpdate import dev.inmo.tgbotapi.types.update.abstracts.BaseEditMessageUpdate
import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.types.update.abstracts.Update
import dev.inmo.tgbotapi.utils.PreviewFeature
internal suspend inline fun <BC : BehaviourContext, reified T : MessageContent> BC.onEditedContent( internal suspend inline fun <BC : BehaviourContext, reified T : MessageContent> BC.onEditedContent(
initialFilter: CommonMessageFilter<T>? = null, initialFilter: CommonMessageFilter<T>? = null,

View File

@ -84,86 +84,6 @@ suspend fun <BC : BehaviourContext> BC.onChatEvent(
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<ChatEvent>> scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<ChatEvent>>
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
* to combinate several filters
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
* data
*/
@Deprecated("Renamed as Video instead of Voice")
suspend fun <BC : BehaviourContext> BC.onVoiceChatEvent(
initialFilter: SimpleFilter<ChatEventMessage<VideoChatEvent>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<VideoChatEvent>, Update>? = MessageFilterByChat,
markerFactory: MarkerFactory<in ChatEventMessage<VideoChatEvent>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<VideoChatEvent>>
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
* to combinate several filters
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
* data
*/
@Deprecated("Renamed as Video instead of Voice")
suspend fun <BC : BehaviourContext> BC.onVoiceChatStartedEvent(
initialFilter: SimpleFilter<ChatEventMessage<VideoChatStarted>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<VideoChatStarted>, Update>? = MessageFilterByChat,
markerFactory: MarkerFactory<in ChatEventMessage<VideoChatStarted>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<VideoChatStarted>>
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
* to combinate several filters
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
* data
*/
@Deprecated("Renamed as Video instead of Voice")
suspend fun <BC : BehaviourContext> BC.onVoiceChatEndedEvent(
initialFilter: SimpleFilter<ChatEventMessage<VideoChatEnded>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<VideoChatEnded>, Update>? = MessageFilterByChat,
markerFactory: MarkerFactory<in ChatEventMessage<VideoChatEnded>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<VideoChatEnded>>
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
* to combinate several filters
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
* data
*/
@Deprecated("Renamed as Video instead of Voice")
suspend fun <BC : BehaviourContext> BC.onVoiceChatParticipantsInvitedEvent(
initialFilter: SimpleFilter<ChatEventMessage<VideoChatParticipantsInvited>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<VideoChatParticipantsInvited>, Update>? = MessageFilterByChat,
markerFactory: MarkerFactory<in ChatEventMessage<VideoChatParticipantsInvited>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<VideoChatParticipantsInvited>>
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/** /**
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,

View File

@ -15,16 +15,17 @@ internal suspend inline fun <BC : BehaviourContext, reified T> BC.on(
noinline updateToData: (Update) -> List<T>? noinline updateToData: (Update) -> List<T>?
) = flowsUpdatesFilter.expectFlow(bot) { ) = flowsUpdatesFilter.expectFlow(bot) {
updateToData(it) ?.mapNotNull { data -> updateToData(it) ?.mapNotNull { data ->
if (initialFilter ?.invoke(data) != false) data else null if (initialFilter ?.invoke(data) != false) it to data else null
} ?: emptyList() } ?: emptyList()
}.subscribeSafelyWithoutExceptionsAsync( }.subscribeSafelyWithoutExceptionsAsync(
scope, scope,
markerFactory::invoke { markerFactory(it.second) }
) { triggerData -> ) { (update, triggerData) ->
createSubContextAndDoWithUpdatesFilter( createSubContextAndDoWithUpdatesFilter(
updatesFilter = subcontextUpdatesFilter ?.toOneType(triggerData),
stopOnCompletion = false stopOnCompletion = false
) { ) {
if (subcontextUpdatesFilter ?.invoke(this, triggerData, update) != false) {
scenarioReceiver(triggerData) scenarioReceiver(triggerData)
} }
}
} }

View File

@ -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)
} }
} }

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts
@Deprecated("Replaced", ReplaceWith("CommonContactData", "dev.inmo.tgbotapi.abstracts.CommonContactData"))
typealias CommonContactData = dev.inmo.tgbotapi.abstracts.CommonContactData

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts
@Deprecated("Replaced", ReplaceWith("CommonSendInvoiceData", "dev.inmo.tgbotapi.abstracts.CommonSendInvoiceData"))
typealias CommonSendInvoiceData = dev.inmo.tgbotapi.abstracts.CommonSendInvoiceData

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts
@Deprecated("Replaced", ReplaceWith("CommonVenueData", "dev.inmo.tgbotapi.abstracts.CommonVenueData"))
typealias CommonVenueData = dev.inmo.tgbotapi.abstracts.CommonVenueData

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts
@Deprecated("Replaced", ReplaceWith("FromUser", "dev.inmo.tgbotapi.abstracts.FromUser"))
typealias FromUser = dev.inmo.tgbotapi.abstracts.FromUser

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts
@Deprecated("Replaced", ReplaceWith("Headed", "dev.inmo.tgbotapi.abstracts.Headed"))
typealias Headed = dev.inmo.tgbotapi.abstracts.Headed

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts
@Deprecated("Replaced", ReplaceWith("HorizontallyAccured", "dev.inmo.tgbotapi.abstracts.HorizontallyAccured"))
typealias HorizontallyAccured = dev.inmo.tgbotapi.abstracts.HorizontallyAccured

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts
@Deprecated("Replaced", ReplaceWith("Livable", "dev.inmo.tgbotapi.abstracts.Livable"))
typealias Livable = dev.inmo.tgbotapi.abstracts.Livable

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts
@Deprecated("Replaced", ReplaceWith("Locationed", "dev.inmo.tgbotapi.abstracts.Locationed"))
typealias Locationed = dev.inmo.tgbotapi.abstracts.Locationed

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts
@Deprecated("Replaced", ReplaceWith("MimeTyped", "dev.inmo.tgbotapi.abstracts.MimeTyped"))
typealias MimeTyped = dev.inmo.tgbotapi.abstracts.MimeTyped

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts
@Deprecated("Replaced", ReplaceWith("Performerable", "dev.inmo.tgbotapi.abstracts.Performerable"))
typealias Performerable = dev.inmo.tgbotapi.abstracts.Performerable

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts
@Deprecated("Replaced", ReplaceWith("ProximityAlertable", "dev.inmo.tgbotapi.abstracts.ProximityAlertable"))
typealias ProximityAlertable = dev.inmo.tgbotapi.abstracts.ProximityAlertable

View File

@ -1,18 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts
@Deprecated("Replaced", ReplaceWith("Texted", "dev.inmo.tgbotapi.abstracts.Texted"))
typealias Texted = dev.inmo.tgbotapi.abstracts.Texted
@Deprecated("Replaced", ReplaceWith("TextedWithTextSources", "dev.inmo.tgbotapi.abstracts.TextedWithTextSources"))
typealias TextedWithTextSources = dev.inmo.tgbotapi.abstracts.TextedWithTextSources
@Deprecated("Replaced", ReplaceWith("ParsableOutput", "dev.inmo.tgbotapi.abstracts.ParsableOutput"))
typealias ParsableOutput = dev.inmo.tgbotapi.abstracts.ParsableOutput
@Deprecated("Replaced", ReplaceWith("EntitiesOutput", "dev.inmo.tgbotapi.abstracts.EntitiesOutput"))
typealias EntitiesOutput = dev.inmo.tgbotapi.abstracts.EntitiesOutput
@Deprecated("Replaced", ReplaceWith("TextedOutput", "dev.inmo.tgbotapi.abstracts.TextedOutput"))
typealias TextedOutput = dev.inmo.tgbotapi.abstracts.TextedOutput
@Deprecated("Replaced", ReplaceWith("TextedInput", "dev.inmo.tgbotapi.abstracts.TextedInput"))
typealias TextedInput = dev.inmo.tgbotapi.abstracts.TextedInput

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts
@Deprecated("Replaced", ReplaceWith("Titled", "dev.inmo.tgbotapi.abstracts.Titled"))
typealias Titled = dev.inmo.tgbotapi.abstracts.Titled

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts
@Deprecated("Replaced", ReplaceWith("WithUser", "dev.inmo.tgbotapi.abstracts.WithUser"))
typealias WithUser = dev.inmo.tgbotapi.abstracts.WithUser

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts.types
@Deprecated("Replaced", ReplaceWith("ChatRequest", "dev.inmo.tgbotapi.abstracts.types.ChatRequest"))
typealias ChatRequest = dev.inmo.tgbotapi.abstracts.types.ChatRequest

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts.types
@Deprecated("Replaced", ReplaceWith("DisableNotification", "dev.inmo.tgbotapi.abstracts.types.DisableNotification"))
typealias DisableNotification = dev.inmo.tgbotapi.abstracts.types.DisableNotification

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts.types
@Deprecated("Replaced", ReplaceWith("DisableWebPagePreview", "dev.inmo.tgbotapi.abstracts.types.DisableWebPagePreview"))
typealias DisableWebPagePreview = dev.inmo.tgbotapi.abstracts.types.DisableWebPagePreview

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts.types
@Deprecated("Replaced", ReplaceWith("InlineMessageAction", "dev.inmo.tgbotapi.abstracts.types.InlineMessageAction"))
typealias InlineMessageAction = dev.inmo.tgbotapi.abstracts.types.InlineMessageAction

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts.types
@Deprecated("Replaced", ReplaceWith("MessageAction:", "dev.inmo.tgbotapi.abstracts.types.MessageAction:"))
typealias MessageAction = dev.inmo.tgbotapi.abstracts.types.MessageAction

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts.types
@Deprecated("Replaced", ReplaceWith("OptionalChatRequest", "dev.inmo.tgbotapi.abstracts.types.OptionalChatRequest"))
typealias OptionalChatRequest = dev.inmo.tgbotapi.abstracts.types.OptionalChatRequest

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts.types
@Deprecated("Replaced", ReplaceWith("ProtectContent", "dev.inmo.tgbotapi.abstracts.types.ProtectContent"))
typealias ProtectContent = dev.inmo.tgbotapi.abstracts.types.ProtectContent

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts.types
@Deprecated("Replaced", ReplaceWith("ReplyMarkup", "dev.inmo.tgbotapi.abstracts.types.ReplyMarkup"))
typealias ReplyMarkup = dev.inmo.tgbotapi.abstracts.types.ReplyMarkup

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts.types
@Deprecated("Replaced", ReplaceWith("ReplyMessageId", "dev.inmo.tgbotapi.abstracts.types.ReplyMessageId"))
typealias ReplyMessageId = dev.inmo.tgbotapi.abstracts.types.ReplyMessageId

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts.types
@Deprecated("Replaced", ReplaceWith("UntilDate", "dev.inmo.tgbotapi.abstracts.types.UntilDate"))
typealias UntilDate = dev.inmo.tgbotapi.abstracts.types.UntilDate

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.bot.Ktor
@Deprecated("Replaced", ReplaceWith("KtorCallFactory", "dev.inmo.tgbotapi.bot.ktor.KtorCallFactory"))
typealias KtorCallFactory = dev.inmo.tgbotapi.bot.ktor.KtorCallFactory

View File

@ -1,32 +0,0 @@
package dev.inmo.tgbotapi.bot.Ktor
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.utils.*
@RiskFeature
@Deprecated("Replaced", ReplaceWith("createTelegramBotDefaultKtorCallRequestsFactories", "dev.inmo.tgbotapi.bot.ktor.createTelegramBotDefaultKtorCallRequestsFactories"))
fun createTelegramBotDefaultKtorCallRequestsFactories() = dev.inmo.tgbotapi.bot.ktor.createTelegramBotDefaultKtorCallRequestsFactories()
@Deprecated("Replaced", ReplaceWith("KtorRequestsExecutor", "dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutor"))
typealias KtorRequestsExecutor = dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutor
@Deprecated("Replaced", ReplaceWith("KtorRequestsExecutorBuilder", "dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutorBuilder"))
typealias KtorRequestsExecutorBuilder = dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutorBuilder
@Deprecated("telegramBot", ReplaceWith("createTelegramBotDefaultKtorCallRequestsFactories", "dev.inmo.tgbotapi.bot.ktor.telegramBot"))
inline fun telegramBot(
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
builder: KtorRequestsExecutorBuilder.() -> Unit = {}
): TelegramBot = dev.inmo.tgbotapi.bot.ktor.telegramBot(telegramAPIUrlsKeeper, builder)
/**
* Shortcut for [telegramBot]
*/
@Suppress("NOTHING_TO_INLINE")
@Deprecated("telegramBot", ReplaceWith("createTelegramBotDefaultKtorCallRequestsFactories", "dev.inmo.tgbotapi.bot.ktor.telegramBot"))
inline fun telegramBot(
token: String,
apiUrl: String = telegramBotAPIDefaultUrl,
testServer: Boolean = false,
builder: KtorRequestsExecutorBuilder.() -> Unit = {}
): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, testServer, apiUrl), builder)

View File

@ -1,6 +0,0 @@
package dev.inmo.tgbotapi.bot.Ktor.base
var defaultUpdateTimeoutForZeroDelay = dev.inmo.tgbotapi.bot.ktor.base.defaultUpdateTimeoutForZeroDelay
@Deprecated("Replaced", ReplaceWith("AbstractRequestCallFactory", "dev.inmo.tgbotapi.bot.ktor.base.AbstractRequestCallFactory"))
typealias AbstractRequestCallFactory = dev.inmo.tgbotapi.bot.ktor.base.AbstractRequestCallFactory

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.bot.Ktor.base
@Deprecated("Replaced", ReplaceWith("DownloadFileChannelRequestCallFactory", "dev.inmo.tgbotapi.bot.ktor.base.DownloadFileRequestCallFactory"))
typealias DownloadFileChannelRequestCallFactory = dev.inmo.tgbotapi.bot.ktor.base.DownloadFileRequestCallFactory

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.bot.Ktor.base
@Deprecated("Replaced", ReplaceWith("DownloadFileRequestCallFactory", "dev.inmo.tgbotapi.bot.ktor.base.DownloadFileRequestCallFactory"))
typealias DownloadFileRequestCallFactory = dev.inmo.tgbotapi.bot.ktor.base.DownloadFileRequestCallFactory

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.bot.Ktor.base
@Deprecated("Replaced", ReplaceWith("MultipartRequestCallFactory", "dev.inmo.tgbotapi.bot.ktor.base.MultipartRequestCallFactory"))
typealias MultipartRequestCallFactory = dev.inmo.tgbotapi.bot.ktor.base.MultipartRequestCallFactory

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.bot.Ktor.base
@Deprecated("Replaced", ReplaceWith("SimpleRequestCallFactory", "dev.inmo.tgbotapi.bot.ktor.base.SimpleRequestCallFactory"))
typealias SimpleRequestCallFactory = dev.inmo.tgbotapi.bot.ktor.base.SimpleRequestCallFactory

View File

@ -79,21 +79,8 @@ data class MultipartFile (
override val fileId: String = "${uuid4()}.${filename.fileExtension}" override val fileId: String = "${uuid4()}.${filename.fileExtension}"
val input: Input val input: Input
get() = inputSource() get() = inputSource()
@Deprecated("Storage file now is not necessary")
constructor(
file: StorageFile,
filename: String = file.fileName
) : this(
filename,
file::input
)
} }
@Deprecated("Storage file now is not necessary")
@Suppress("NOTHING_TO_INLINE", "unused")
inline fun StorageFile.asMultipartFile() = MultipartFile(fileName, ::input)
@Suppress("NOTHING_TO_INLINE", "unused") @Suppress("NOTHING_TO_INLINE", "unused")
suspend inline fun ByteReadChannel.asMultipartFile( suspend inline fun ByteReadChannel.asMultipartFile(
fileName: String fileName: String

View File

@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.requests.bot
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRightsImpl
import kotlinx.serialization.* import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer import kotlinx.serialization.builtins.serializer

View File

@ -1,7 +0,0 @@
package dev.inmo.tgbotapi.requests.edit.LiveLocation
@Deprecated("Replaced", ReplaceWith("editMessageLiveLocationMethod", "dev.inmo.tgbotapi.requests.edit.location.live.editMessageLiveLocationMethod"))
const val editMessageLiveLocationMethod = dev.inmo.tgbotapi.requests.edit.location.live.editMessageLiveLocationMethod
@Deprecated("Replaced", ReplaceWith("EditChatMessageLiveLocation", "dev.inmo.tgbotapi.requests.edit.location.live.EditChatMessageLiveLocation"))
typealias EditChatMessageLiveLocation = dev.inmo.tgbotapi.requests.edit.location.live.EditChatMessageLiveLocation

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.requests.edit.LiveLocation
@Deprecated("Replaced", ReplaceWith("EditInlineMessageLiveLocation", "dev.inmo.tgbotapi.requests.edit.location.live.EditInlineMessageLiveLocation"))
typealias EditInlineMessageLiveLocation = dev.inmo.tgbotapi.requests.edit.location.live.EditInlineMessageLiveLocation

View File

@ -1,7 +0,0 @@
package dev.inmo.tgbotapi.requests.edit.LiveLocation
@Deprecated("Replaced", ReplaceWith("stopMessageLiveLocationMethod", "dev.inmo.tgbotapi.requests.edit.location.live.stopMessageLiveLocationMethod"))
const val stopMessageLiveLocationMethod = dev.inmo.tgbotapi.requests.edit.location.live.stopMessageLiveLocationMethod
@Deprecated("Replaced", ReplaceWith("StopChatMessageLiveLocation", "dev.inmo.tgbotapi.requests.edit.location.live.StopChatMessageLiveLocation"))
typealias StopChatMessageLiveLocation = dev.inmo.tgbotapi.requests.edit.location.live.StopChatMessageLiveLocation

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.requests.edit.LiveLocation
@Deprecated("Replaced", ReplaceWith("StopInlineMessageLiveLocation", "dev.inmo.tgbotapi.requests.edit.location.live.StopInlineMessageLiveLocation"))
typealias StopInlineMessageLiveLocation = dev.inmo.tgbotapi.requests.edit.location.live.StopInlineMessageLiveLocation

View File

@ -1,7 +0,0 @@
package dev.inmo.tgbotapi.requests.edit.ReplyMarkup
@Deprecated("Replaced", ReplaceWith("editMessageReplyMarkupMethod", "dev.inmo.tgbotapi.requests.edit.reply_markup.editMessageReplyMarkupMethod"))
const val editMessageReplyMarkupMethod = dev.inmo.tgbotapi.requests.edit.reply_markup.editMessageReplyMarkupMethod
@Deprecated("Replaced", ReplaceWith("EditChatMessageReplyMarkup", "dev.inmo.tgbotapi.requests.edit.reply_markup.EditChatMessageReplyMarkup"))
typealias EditChatMessageReplyMarkup = dev.inmo.tgbotapi.requests.edit.reply_markup.EditChatMessageReplyMarkup

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.requests.edit.ReplyMarkup
@Deprecated("Replaced", ReplaceWith("EditInlineMessageReplyMarkup", "dev.inmo.tgbotapi.requests.edit.reply_markup.EditInlineMessageReplyMarkup"))
typealias EditInlineMessageReplyMarkup = dev.inmo.tgbotapi.requests.edit.reply_markup.EditInlineMessageReplyMarkup

View File

@ -1,7 +0,0 @@
package dev.inmo.tgbotapi.types.CallbackQuery
@Deprecated("Replaced", ReplaceWith("CallbackQuery", "dev.inmo.tgbotapi.types.queries.callback.CallbackQuery"))
typealias CallbackQuery = dev.inmo.tgbotapi.types.queries.callback.CallbackQuery
@Deprecated("Replaced", ReplaceWith("UnknownCallbackQueryType", "dev.inmo.tgbotapi.types.queries.callback.UnknownCallbackQueryType"))
typealias UnknownCallbackQueryType = dev.inmo.tgbotapi.types.queries.callback.UnknownCallbackQueryType

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types.CallbackQuery
@Deprecated("Replaced", ReplaceWith("DataCallbackQuery", "dev.inmo.tgbotapi.types.queries.callback.DataCallbackQuery"))
typealias DataCallbackQuery = dev.inmo.tgbotapi.types.queries.callback.DataCallbackQuery

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types.CallbackQuery
@Deprecated("Replaced", ReplaceWith("GameShortNameCallbackQuery", "dev.inmo.tgbotapi.types.queries.callback.GameShortNameCallbackQuery"))
typealias GameShortNameCallbackQuery = dev.inmo.tgbotapi.types.queries.callback.GameShortNameCallbackQuery

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types.CallbackQuery
@Deprecated("Replaced", ReplaceWith("InlineMessageIdCallbackQuery", "dev.inmo.tgbotapi.types.queries.callback.InlineMessageIdCallbackQuery"))
typealias InlineMessageIdCallbackQuery = dev.inmo.tgbotapi.types.queries.callback.InlineMessageIdCallbackQuery

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types.CallbackQuery
@Deprecated("Replaced", ReplaceWith("InlineMessageIdDataCallbackQuery", "dev.inmo.tgbotapi.types.queries.callback.InlineMessageIdDataCallbackQuery"))
typealias InlineMessageIdDataCallbackQuery = dev.inmo.tgbotapi.types.queries.callback.InlineMessageIdDataCallbackQuery

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types.CallbackQuery
@Deprecated("Replaced", ReplaceWith("InlineMessageIdGameShortNameCallbackQuery", "dev.inmo.tgbotapi.types.queries.callback.InlineMessageIdGameShortNameCallbackQuery"))
typealias InlineMessageIdGameShortNameCallbackQuery = dev.inmo.tgbotapi.types.queries.callback.InlineMessageIdGameShortNameCallbackQuery

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types.CallbackQuery
@Deprecated("Replaced", ReplaceWith("MessageCallbackQuery", "dev.inmo.tgbotapi.types.queries.callback.MessageCallbackQuery"))
typealias MessageCallbackQuery = dev.inmo.tgbotapi.types.queries.callback.MessageCallbackQuery

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types.CallbackQuery
@Deprecated("Replaced", ReplaceWith("MessageDataCallbackQuery", "dev.inmo.tgbotapi.types.queries.callback.MessageDataCallbackQuery"))
typealias MessageDataCallbackQuery = dev.inmo.tgbotapi.types.queries.callback.MessageDataCallbackQuery

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types.CallbackQuery
@Deprecated("Replaced", ReplaceWith("MessageGameShortNameCallbackQuery", "dev.inmo.tgbotapi.types.queries.callback.MessageGameShortNameCallbackQuery"))
typealias MessageGameShortNameCallbackQuery = dev.inmo.tgbotapi.types.queries.callback.MessageGameShortNameCallbackQuery

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types
@Deprecated("Renamed", ReplaceWith("ChatAdministratorRightsImpl", "dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRightsImpl"))
typealias ChatAdministratorRightsImpl = dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRightsImpl

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types.ChatMember
@Deprecated("AdministratorChatMemberImpl", ReplaceWith("AdministratorChatMemberImpl", "dev.inmo.tgbotapi.types.chat.member.AdministratorChatMemberImpl"))
typealias AdministratorChatMemberImpl = dev.inmo.tgbotapi.types.chat.member.AdministratorChatMemberImpl

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types.ChatMember
@Deprecated("CreatorChatMember", ReplaceWith("CreatorChatMember", "dev.inmo.tgbotapi.types.chat.member.CreatorChatMember"))
typealias CreatorChatMember = dev.inmo.tgbotapi.types.chat.member.CreatorChatMember

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types.ChatMember
@Deprecated("KickedChatMember", ReplaceWith("KickedChatMember", "dev.inmo.tgbotapi.types.chat.member.KickedChatMember"))
typealias KickedChatMember = dev.inmo.tgbotapi.types.chat.member.KickedChatMember

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types.ChatMember
@Deprecated("LeftChatMemberImpl", ReplaceWith("LeftChatMemberImpl", "dev.inmo.tgbotapi.types.chat.member.LeftChatMemberImpl"))
typealias LeftChatMemberImpl = dev.inmo.tgbotapi.types.chat.member.LeftChatMemberImpl

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types.ChatMember
@Deprecated("MemberChatMemberImpl", ReplaceWith("MemberChatMemberImpl", "dev.inmo.tgbotapi.types.chat.member.MemberChatMemberImpl"))
typealias MemberChatMemberImpl = dev.inmo.tgbotapi.types.chat.member.MemberChatMemberImpl

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types.ChatMember
@Deprecated("RestrictedChatMember", ReplaceWith("RestrictedChatMember", "dev.inmo.tgbotapi.types.chat.member.RestrictedChatMember"))
typealias RestrictedChatMember = dev.inmo.tgbotapi.types.chat.member.RestrictedChatMember

View File

@ -1,7 +0,0 @@
package dev.inmo.tgbotapi.types.ChatMember.abstracts
@Deprecated("AdministratorChatMember", ReplaceWith("AdministratorChatMember", "dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember"))
typealias AdministratorChatMember = dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember
@Deprecated("AdministratorChatMemberSerializer", ReplaceWith("AdministratorChatMemberSerializer", "dev.inmo.tgbotapi.types.chat.member.AdministratorChatMemberSerializer"))
typealias AdministratorChatMemberSerializer = dev.inmo.tgbotapi.types.chat.member.AdministratorChatMemberSerializer

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types.ChatMember.abstracts
@Deprecated("BannedChatMember", ReplaceWith("BannedChatMember", "dev.inmo.tgbotapi.types.chat.member.BannedChatMember"))
typealias BannedChatMember = dev.inmo.tgbotapi.types.chat.member.BannedChatMember

View File

@ -1,7 +0,0 @@
package dev.inmo.tgbotapi.types.ChatMember.abstracts
@Deprecated("SpecialChatAdministratorRights", ReplaceWith("SpecialChatAdministratorRights", "dev.inmo.tgbotapi.types.chat.member.SpecialChatAdministratorRights"))
typealias SpecialChatAdministratorRights = dev.inmo.tgbotapi.types.chat.member.SpecialChatAdministratorRights
@Deprecated("ChatAdministratorRights", ReplaceWith("ChatAdministratorRights", "dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRights"))
typealias ChatAdministratorRights = dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRights

View File

@ -1,7 +0,0 @@
package dev.inmo.tgbotapi.types.ChatMember.abstracts
@Deprecated("ChatMember", ReplaceWith("ChatMember", "dev.inmo.tgbotapi.types.chat.member.ChatMember"))
typealias ChatMember = dev.inmo.tgbotapi.types.chat.member.ChatMember
@Deprecated("ChatMemberSerializer", ReplaceWith("ChatMemberSerializer", "dev.inmo.tgbotapi.types.chat.member.ChatMemberSerializer"))
typealias ChatMemberSerializer = dev.inmo.tgbotapi.types.chat.member.ChatMemberSerializer

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types.ChatMember.abstracts
@Deprecated("LeftChatMember", ReplaceWith("LeftChatMember", "dev.inmo.tgbotapi.types.chat.member.LeftChatMember"))
typealias LeftChatMember = dev.inmo.tgbotapi.types.chat.member.LeftChatMember

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types.ChatMember.abstracts
@Deprecated("MemberChatMember", ReplaceWith("MemberChatMember", "dev.inmo.tgbotapi.types.chat.member.MemberChatMember"))
typealias MemberChatMember = dev.inmo.tgbotapi.types.chat.member.MemberChatMember

View File

@ -1,4 +0,0 @@
package dev.inmo.tgbotapi.types.ChatMember.abstracts
@Deprecated("SpecialRightsChatMember", ReplaceWith("SpecialRightsChatMember", "dev.inmo.tgbotapi.types.chat.member.SpecialRightsChatMember"))
typealias SpecialRightsChatMember = dev.inmo.tgbotapi.types.chat.member.SpecialRightsChatMember

View File

@ -1,39 +0,0 @@
package dev.inmo.tgbotapi.types.InputMedia
import dev.inmo.tgbotapi.requests.abstracts.InputFile
import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.message.toRawMessageEntities
import dev.inmo.tgbotapi.types.message.ParseMode
import dev.inmo.tgbotapi.types.media.TelegramMediaAnimation
import dev.inmo.tgbotapi.utils.extensions.makeString
@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaAnimation", "dev.inmo.tgbotapi.types.media.TelegramMediaAnimation"))
fun InputMediaAnimation(
file: InputFile,
text: String? = null,
parseMode: ParseMode? = null,
width: Int? = null,
height: Int? = null,
duration: Long? = null,
thumb: InputFile? = null
) = TelegramMediaAnimation(file, text, parseMode, null, width, height, duration, thumb)
@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaAnimation", "dev.inmo.tgbotapi.types.media.TelegramMediaAnimation"))
fun InputMediaAnimation(
file: InputFile,
entities: TextSourcesList,
width: Int? = null,
height: Int? = null,
duration: Long? = null,
thumb: InputFile? = null
) = TelegramMediaAnimation(
file,
entities.makeString(),
null,
entities.toRawMessageEntities(),
width,
height,
duration,
thumb
)

View File

@ -1,62 +0,0 @@
package dev.inmo.tgbotapi.types.InputMedia
import dev.inmo.tgbotapi.requests.abstracts.InputFile
import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.message.toRawMessageEntities
import dev.inmo.tgbotapi.types.message.ParseMode
import dev.inmo.tgbotapi.types.files.AudioFile
import dev.inmo.tgbotapi.types.media.TelegramMediaAudio
import dev.inmo.tgbotapi.utils.extensions.makeString
@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaAudio", "dev.inmo.tgbotapi.types.media.TelegramMediaAudio"))
fun InputMediaAudio(
file: InputFile,
entities: TextSourcesList,
duration: Long? = null,
performer: String? = null,
title: String? = null,
thumb: InputFile? = null
) = TelegramMediaAudio(
file, entities.makeString(), null, entities.toRawMessageEntities(), duration, performer, title, thumb
)
@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaAudio", "dev.inmo.tgbotapi.types.media.TelegramMediaAudio"))
fun InputMediaAudio(
file: InputFile,
text: String? = null,
parseMode: ParseMode? = null,
duration: Long? = null,
performer: String? = null,
title: String? = null,
thumb: InputFile? = null
) = TelegramMediaAudio(
file, text, parseMode, null, duration, performer, title, thumb
)
@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaAudio", "dev.inmo.tgbotapi.types.media.TelegramMediaAudio"))
fun AudioFile.toInputMediaAudio(
text: String? = null,
parseMode: ParseMode? = null,
title: String? = this.title
): InputMediaAudio = TelegramMediaAudio(
fileId,
text,
parseMode,
duration,
performer,
title,
thumb ?.fileId
)
@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaAudio", "dev.inmo.tgbotapi.types.media.TelegramMediaAudio"))
fun AudioFile.toInputMediaAudio(
textSources: TextSourcesList = emptyList(),
title: String? = this.title
): InputMediaAudio = TelegramMediaAudio(
fileId,
textSources,
duration,
performer,
title,
thumb ?.fileId
)

View File

@ -1,53 +0,0 @@
package dev.inmo.tgbotapi.types.InputMedia
import dev.inmo.tgbotapi.requests.abstracts.InputFile
import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.message.toRawMessageEntities
import dev.inmo.tgbotapi.types.message.ParseMode
import dev.inmo.tgbotapi.types.files.DocumentFile
import dev.inmo.tgbotapi.types.media.TelegramMediaDocument
import dev.inmo.tgbotapi.utils.extensions.makeString
@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaDocument", "dev.inmo.tgbotapi.types.media.TelegramMediaDocument"))
fun InputMediaDocument(
file: InputFile,
text: String? = null,
parseMode: ParseMode? = null,
thumb: InputFile? = null,
disableContentTypeDetection: Boolean? = null
) = TelegramMediaDocument(file, text, parseMode, null, thumb, disableContentTypeDetection)
@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaDocument", "dev.inmo.tgbotapi.types.media.TelegramMediaDocument"))
fun InputMediaDocument(
file: InputFile,
entities: TextSourcesList,
thumb: InputFile? = null,
disableContentTypeDetection: Boolean? = null
) = TelegramMediaDocument(
file,
entities.makeString(),
null,
entities.toRawMessageEntities(),
thumb,
disableContentTypeDetection
)
@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaDocument", "dev.inmo.tgbotapi.types.media.TelegramMediaDocument"))
fun DocumentFile.toInputMediaDocument(
text: String? = null,
parseMode: ParseMode? = null
) = TelegramMediaDocument(
fileId,
text,
parseMode,
thumb ?.fileId
)
@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaDocument", "dev.inmo.tgbotapi.types.media.TelegramMediaDocument"))
fun DocumentFile.toInputMediaDocument(
textSources: TextSourcesList = emptyList()
) = TelegramMediaDocument(
fileId,
textSources,
thumb ?.fileId
)

Some files were not shown because too many files have changed in this diff Show More