mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-02 15:00:06 +00:00
Compare commits
No commits in common. "3149fd0231b3e0b4d6533e7764840bfaef81efd2" and "e55195b3084c8dab1a1d5fdc1c7ba1b29d3efd72" have entirely different histories.
3149fd0231
...
e55195b308
12
CHANGELOG.md
12
CHANGELOG.md
@ -1,17 +1,5 @@
|
|||||||
# 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`:
|
||||||
|
@ -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=2.0.0
|
library_version=1.1.3
|
||||||
|
|
||||||
github_release_plugin_version=2.3.7
|
github_release_plugin_version=2.3.7
|
||||||
|
@ -0,0 +1,92 @@
|
|||||||
|
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)
|
@ -0,0 +1,25 @@
|
|||||||
|
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)
|
@ -0,0 +1,43 @@
|
|||||||
|
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)
|
@ -0,0 +1,17 @@
|
|||||||
|
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)
|
@ -0,0 +1,42 @@
|
|||||||
|
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)
|
||||||
|
|
@ -0,0 +1,17 @@
|
|||||||
|
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)
|
@ -47,26 +47,10 @@ 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,
|
||||||
@ -83,7 +67,7 @@ interface BehaviourContextWithFSM<T : State> : BehaviourContext, StatesMachine<T
|
|||||||
onBufferOverflow,
|
onBufferOverflow,
|
||||||
upstreamUpdatesFlow,
|
upstreamUpdatesFlow,
|
||||||
triggersHolder,
|
triggersHolder,
|
||||||
onStateHandlingErrorHandler
|
updatesFilter
|
||||||
)
|
)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@ -212,9 +196,10 @@ 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),
|
behaviourContext.copy(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, triggersHolder, updatesFilter),
|
||||||
handlers,
|
handlers,
|
||||||
statesManager,
|
statesManager,
|
||||||
onStateHandlingErrorHandler
|
onStateHandlingErrorHandler
|
||||||
@ -227,9 +212,10 @@ 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),
|
behaviourContext.copy(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, triggersHolder, updatesFilter),
|
||||||
handlers,
|
handlers,
|
||||||
statesManager,
|
statesManager,
|
||||||
onStateHandlingErrorHandler
|
onStateHandlingErrorHandler
|
||||||
|
@ -13,6 +13,9 @@ 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]
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
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>()
|
@ -49,19 +49,6 @@ 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,
|
||||||
@ -70,7 +57,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 = copy(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, triggersHolder)
|
): BehaviourContext
|
||||||
}
|
}
|
||||||
|
|
||||||
class DefaultBehaviourContext(
|
class DefaultBehaviourContext(
|
||||||
@ -80,17 +67,20 @@ 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) {
|
||||||
var lastHandledUpdate = -1L
|
(it + upstreamUpdatesFlow).distinctUntilChanged { old, new -> old.updateId == new.updateId }
|
||||||
(it + upstreamUpdatesFlow).filter {
|
} else {
|
||||||
(it.updateId > lastHandledUpdate).also { passed -> if (passed) { lastHandledUpdate = it.updateId } }
|
it
|
||||||
}
|
}
|
||||||
|
}.let {
|
||||||
|
val updatesFilter = updatesFilter
|
||||||
|
if (updatesFilter != null) {
|
||||||
|
it.filter { updatesFilter(it) }
|
||||||
} else {
|
} else {
|
||||||
it
|
it
|
||||||
}
|
}
|
||||||
@ -103,8 +93,9 @@ class DefaultBehaviourContext(
|
|||||||
broadcastChannelsSize: Int,
|
broadcastChannelsSize: Int,
|
||||||
onBufferOverflow: BufferOverflow,
|
onBufferOverflow: BufferOverflow,
|
||||||
upstreamUpdatesFlow: Flow<Update>?,
|
upstreamUpdatesFlow: Flow<Update>?,
|
||||||
triggersHolder: TriggersHolder
|
triggersHolder: TriggersHolder,
|
||||||
): DefaultBehaviourContext = DefaultBehaviourContext(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, triggersHolder)
|
updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>?
|
||||||
|
): DefaultBehaviourContext = DefaultBehaviourContext(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, triggersHolder, updatesFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BehaviourContext(
|
fun BehaviourContext(
|
||||||
@ -122,34 +113,24 @@ 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]
|
||||||
*
|
*
|
||||||
@ -174,13 +155,15 @@ 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
|
||||||
@ -192,22 +175,43 @@ 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("It is not recommended to use updates filter anymore")
|
@Deprecated("Renamed", ReplaceWith("createSubContextAndDoWithUpdatesFilter", "dev.inmo.tgbotapi.extensions.behaviour_builder.createSubContextAndDoWithUpdatesFilter"))
|
||||||
suspend fun <T, BC : BehaviourContext> BC.createSubContextAndDoWithUpdatesFilter(
|
suspend fun <T, BC : BehaviourContext> BC.doInSubContextWithUpdatesFilter(
|
||||||
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 createSubContextAndDoWithUpdatesFilter(
|
return createSubContext(
|
||||||
scope, triggersHolder, updatesUpstreamFlow, stopOnCompletion, behaviourContextReceiver
|
scope,
|
||||||
|
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
|
||||||
*/
|
*/
|
||||||
|
@ -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.flatten
|
import dev.inmo.tgbotapi.extensions.utils.flatMap
|
||||||
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,6 +20,7 @@ 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
|
||||||
@ -32,6 +33,7 @@ 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 },
|
||||||
@ -53,13 +55,19 @@ suspend fun <T> FlowsUpdatesFilter.expectFlow(
|
|||||||
} else {
|
} else {
|
||||||
result.getOrThrow()
|
result.getOrThrow()
|
||||||
}
|
}
|
||||||
}.flatten()
|
}.flatMap()
|
||||||
|
val result = if (count == null) {
|
||||||
|
flow
|
||||||
|
} else {
|
||||||
|
flow.take(count)
|
||||||
|
}
|
||||||
initRequest ?.also { safelyWithoutExceptions { bot.execute(initRequest) } }
|
initRequest ?.also { safelyWithoutExceptions { bot.execute(initRequest) } }
|
||||||
return flow
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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
|
||||||
@ -68,14 +76,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, errorFactory, cancelRequestFactory, cancelTrigger, filter)
|
) = flowsUpdatesFilter.expectFlow(bot, initRequest, count, errorFactory, cancelRequestFactory, cancelTrigger, filter)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param initRequest If not null, this request will be sent by [bot] before returning value
|
* @param initRequest If not null, this request will be sent by [bot] before returning value
|
||||||
@ -95,7 +103,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, errorFactory, cancelRequestFactory, cancelTrigger) {
|
): T = expectFlow(bot, initRequest, 1, errorFactory, cancelRequestFactory, cancelTrigger) {
|
||||||
listOfNotNull(filter.invoke(it))
|
listOfNotNull(filter.invoke(it))
|
||||||
}.first()
|
}.first()
|
||||||
|
|
||||||
@ -109,7 +117,6 @@ suspend fun <T> FlowsUpdatesFilter.expectOne(
|
|||||||
* as is, but when it returns null, then will be called [cancelTrigger] (if it will return true - [cancelRequestFactory]
|
* as is, but when it returns null, then will be called [cancelTrigger] (if it will return true - [cancelRequestFactory]
|
||||||
* will be called too), [errorFactory] and then will be returned null
|
* will be called too), [errorFactory] and then will be returned null
|
||||||
*/
|
*/
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
|
||||||
suspend fun <T> BehaviourContext.expectOne(
|
suspend fun <T> BehaviourContext.expectOne(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
@ -7,58 +7,118 @@ 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?
|
||||||
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
private suspend fun <O> BehaviourContext.waitCallbackQueries(
|
||||||
suspend inline fun <reified O> BehaviourContext.waitCallbackQueries(
|
count: Int = 1,
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
): Flow<O> = expectFlow(
|
filter: SimpleFilter<CallbackQuery>? = null,
|
||||||
|
mapper: suspend CallbackQuery.() -> O?
|
||||||
|
): List<O> = expectFlow(
|
||||||
initRequest,
|
initRequest,
|
||||||
|
count,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
(it.asCallbackQueryUpdate() ?.data as O).let(::listOfNotNull)
|
val data = it.asCallbackQueryUpdate() ?.data
|
||||||
|
if (data != null && (filter == null || filter(data))) {
|
||||||
|
data.mapper().let(::listOfNotNull)
|
||||||
|
} else {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}.toList().toList()
|
||||||
|
|
||||||
|
|
||||||
|
private suspend inline fun <reified T : CallbackQuery> BehaviourContext.waitCallbacks(
|
||||||
|
count: Int = 1,
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
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 },
|
||||||
) = waitCallbackQueries<DataCallbackQuery>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitCallbackQueries<GameShortNameCallbackQuery>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitCallbackQueries<InlineMessageIdCallbackQuery>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitCallbackQueries<InlineMessageIdDataCallbackQuery>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitCallbackQueries<InlineMessageIdGameShortNameCallbackQuery>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitCallbackQueries<MessageCallbackQuery>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitCallbackQueries<MessageDataCallbackQuery>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitCallbackQueries<MessageGameShortNameCallbackQuery>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitCallbackQueries<UnknownCallbackQueryType>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
filter: SimpleFilter<UnknownCallbackQueryType>? = null,
|
||||||
|
mapper: CallbackQueryMapper<UnknownCallbackQueryType>? = null
|
||||||
|
) = waitCallbacks(count, initRequest, errorFactory, filter, mapper)
|
||||||
|
@ -5,29 +5,45 @@ 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?
|
||||||
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
private suspend fun <O> BehaviourContext.waitChatJoinRequests(
|
||||||
suspend inline fun <reified O> BehaviourContext.internalWaitChatJoinRequests(
|
count: Int = 1,
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
): Flow<O> = expectFlow(
|
filter: SimpleFilter<ChatJoinRequest>? = null,
|
||||||
|
mapper: suspend ChatJoinRequest.() -> O?
|
||||||
|
): List<O> = expectFlow(
|
||||||
initRequest,
|
initRequest,
|
||||||
|
count,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
(it.asChatJoinRequestUpdate() ?.data as? O).let(::listOfNotNull)
|
val data = it.asChatJoinRequestUpdate() ?.data
|
||||||
|
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 },
|
||||||
) : Flow<ChatJoinRequest> = internalWaitChatJoinRequests(
|
count: Int = 1,
|
||||||
|
filter: SimpleFilter<ChatJoinRequest>? = null,
|
||||||
|
mapper: ChatJoinRequestsMapper? = null
|
||||||
|
) : List<ChatJoinRequest> = waitChatJoinRequests(
|
||||||
|
count,
|
||||||
initRequest,
|
initRequest,
|
||||||
errorFactory
|
errorFactory,
|
||||||
)
|
filter
|
||||||
|
) {
|
||||||
|
if (mapper == null) {
|
||||||
|
this
|
||||||
|
} else {
|
||||||
|
mapper(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -7,35 +7,68 @@ 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?
|
||||||
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
private suspend inline fun <reified T : ChatMemberUpdatedUpdate> BehaviourContext.waitChatMemberUpdated(
|
||||||
suspend inline fun <reified O : ChatMemberUpdatedUpdate> BehaviourContext.waitChatMemberUpdatedWithFilter(
|
count: Int = 1,
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
): Flow<ChatMemberUpdated> = expectFlow(
|
filter: SimpleFilter<T>? = null,
|
||||||
|
noinline mapper: ChatMemberUpdatedMapper<ChatMemberUpdated>
|
||||||
|
): List<ChatMemberUpdated> = expectFlow(
|
||||||
initRequest,
|
initRequest,
|
||||||
|
count,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
(it as? O) ?.data.let(::listOfNotNull)
|
val casted = (it as? T) ?: return@expectFlow emptyList()
|
||||||
|
if (filter == null || filter(casted)) {
|
||||||
|
casted.data.mapper().let(::listOfNotNull)
|
||||||
|
} else {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}.toList().toList()
|
||||||
|
|
||||||
|
private suspend inline fun <reified T : ChatMemberUpdatedUpdate> BehaviourContext.waitChatMemberUpdatedWithFilter(
|
||||||
|
count: Int = 1,
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
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 },
|
||||||
) = waitChatMemberUpdatedWithFilter<ChatMemberUpdatedUpdate>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitChatMemberUpdatedWithFilter<CommonChatMemberUpdatedUpdate>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitChatMemberUpdatedWithFilter<MyChatMemberUpdatedUpdate>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
filter: SimpleFilter<MyChatMemberUpdatedUpdate>? = null,
|
||||||
|
mapper: ChatMemberUpdatedMapper<ChatMemberUpdated>? = null
|
||||||
|
) = waitChatMemberUpdatedWithFilter<MyChatMemberUpdatedUpdate>(count, initRequest, errorFactory, filter, mapper)
|
||||||
|
@ -5,35 +5,77 @@ 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?
|
||||||
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
private suspend fun <O> BehaviourContext.waitChosenInlineResultsUpdates(
|
||||||
suspend inline fun <reified O> BehaviourContext.waitChosenInlineResults(
|
count: Int = 1,
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
): Flow<O> = expectFlow(
|
filter: SimpleFilter<ChosenInlineResult>? = null,
|
||||||
|
mapper: suspend ChosenInlineResult.() -> O?
|
||||||
|
): List<O> = expectFlow(
|
||||||
initRequest,
|
initRequest,
|
||||||
|
count,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
(it.asChosenInlineResultUpdate() ?.data as? O).let(::listOfNotNull)
|
val data = it.asChosenInlineResultUpdate() ?.data
|
||||||
|
if (data != null && (filter == null || filter(data))) {
|
||||||
|
data.mapper().let(::listOfNotNull)
|
||||||
|
} else {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}.toList().toList()
|
||||||
|
|
||||||
|
|
||||||
|
private suspend inline fun <reified T : ChosenInlineResult> BehaviourContext.waitChosenInlineResults(
|
||||||
|
count: Int = 1,
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
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 },
|
||||||
) = waitChosenInlineResults<ChosenInlineResult>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitChosenInlineResults<LocationChosenInlineResult>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitChosenInlineResults<BaseChosenInlineResult>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
filter: SimpleFilter<BaseChosenInlineResult>? = null,
|
||||||
|
mapper: PollMapper<BaseChosenInlineResult>? = null
|
||||||
|
) = waitChosenInlineResults(count, initRequest, errorFactory, filter, mapper)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
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
|
||||||
@ -15,129 +16,262 @@ import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
|
|||||||
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
|
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.toList
|
||||||
|
|
||||||
typealias CommonMessageToContentMapper<T> = suspend CommonMessage<T>.() -> T?
|
typealias CommonMessageToContentMapper<T> = suspend CommonMessage<T>.() -> T?
|
||||||
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
private suspend fun <O> BehaviourContext.waitCommonContent(
|
||||||
suspend inline fun <reified O : MessageContent> BehaviourContext.waitContent(
|
count: Int = 1,
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
includeMediaGroups: Boolean = true,
|
includeMediaGroups: Boolean = true,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
): Flow<O> = waitContentMessage<O>(initRequest, includeMediaGroups, errorFactory).map { it.content }
|
filter: SimpleFilter<CommonMessage<MessageContent>>? = null,
|
||||||
|
mapper: suspend CommonMessage<MessageContent>.() -> O?
|
||||||
|
): Flow<O> = expectFlow(
|
||||||
|
initRequest,
|
||||||
|
count,
|
||||||
|
errorFactory
|
||||||
|
) {
|
||||||
|
val messages = when (it) {
|
||||||
|
is SentMediaGroupUpdate -> {
|
||||||
|
if (includeMediaGroups) {
|
||||||
|
it.data.map { it as CommonMessage<MessageContent> }
|
||||||
|
} else {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is BaseSentMessageUpdate -> listOf(it.data)
|
||||||
|
else -> return@expectFlow emptyList()
|
||||||
|
}
|
||||||
|
messages.mapNotNull { message ->
|
||||||
|
val asCommonMessage = message as CommonMessage<MessageContent>
|
||||||
|
if (filter == null || filter(asCommonMessage)) {
|
||||||
|
asCommonMessage.mapper()
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal inline fun <reified T : MessageContent> contentConverter(
|
||||||
|
noinline mapper: CommonMessageToContentMapper<T>? = null
|
||||||
|
): suspend CommonMessage<MessageContent>.() -> T? = mapper ?.let {
|
||||||
|
{
|
||||||
|
if (content is T) {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
val message = (this as CommonMessage<T>)
|
||||||
|
safelyWithoutExceptions { mapper(message) }
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} ?: { content as? T }
|
||||||
|
|
||||||
|
private suspend inline fun <reified T : MessageContent> BehaviourContext.waitContent(
|
||||||
|
count: Int = 1,
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
includeMediaGroups: Boolean = true,
|
||||||
|
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = true
|
count: Int = 1,
|
||||||
) = waitContent<MessageContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = true,
|
||||||
|
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 },
|
||||||
) = waitContent<ContactContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContent<DiceContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContent<GameContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContent<LocationContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContent<LiveLocationContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContent<StaticLocationContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContent<PollContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContent<TextContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContent<VenueContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = true
|
count: Int = 1,
|
||||||
) = waitContent<AudioMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = true,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = true
|
count: Int = 1,
|
||||||
) = waitContent<DocumentMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = true,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = false
|
count: Int = 1,
|
||||||
) = waitContent<MediaContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = false,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = true
|
count: Int = 1,
|
||||||
) = waitContent<MediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = true,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = true
|
count: Int = 1,
|
||||||
) = waitContent<VisualMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = true,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = true
|
count: Int = 1,
|
||||||
) = waitContent<TextedMediaContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = true,
|
||||||
|
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 },
|
||||||
) = waitContent<AnimationContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = false
|
count: Int = 1,
|
||||||
) = waitContent<AudioContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = false,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = false
|
count: Int = 1,
|
||||||
) = waitContent<DocumentContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = false,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = false
|
count: Int = 1,
|
||||||
) = waitContent<PhotoContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = false,
|
||||||
|
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 },
|
||||||
) = waitContent<StickerContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = false
|
count: Int = 1,
|
||||||
) = waitContent<VideoContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = false,
|
||||||
|
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 },
|
||||||
) = waitContent<VideoNoteContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContent<VoiceContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContent<InvoiceContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
filter: SimpleFilter<CommonMessage<InvoiceContent>>? = null,
|
||||||
|
mapper: CommonMessageToContentMapper<InvoiceContent>? = null
|
||||||
|
) = waitContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||||
|
@ -16,19 +16,21 @@ 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>?
|
||||||
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
internal suspend fun <O : MessageContent> BehaviourContext.waitCommonMessage(
|
||||||
suspend inline fun <reified O : MessageContent> BehaviourContext.waitContentMessage(
|
count: Int = 1,
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
includeMediaGroups: Boolean = true,
|
includeMediaGroups: Boolean = true,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
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) {
|
||||||
@ -43,7 +45,13 @@ suspend inline fun <reified O : MessageContent> BehaviourContext.waitContentMess
|
|||||||
else -> return@expectFlow emptyList()
|
else -> return@expectFlow emptyList()
|
||||||
}
|
}
|
||||||
messages.mapNotNull { message ->
|
messages.mapNotNull { message ->
|
||||||
(message as? CommonMessage<*>) ?.withContent<O>()
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
val asCommonMessage = message as? CommonMessage<MessageContent> ?: return@mapNotNull null
|
||||||
|
if (filter == null || filter(asCommonMessage)) {
|
||||||
|
asCommonMessage.mapper()
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,114 +72,209 @@ 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 },
|
||||||
includeMediaGroups: Boolean = true
|
count: Int = 1,
|
||||||
) = waitContentMessage<MessageContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = true,
|
||||||
|
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 },
|
||||||
) = waitContentMessage<ContactContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContentMessage<DiceContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContentMessage<GameContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContentMessage<LocationContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContentMessage<LiveLocationContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContentMessage<StaticLocationContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContentMessage<PollContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContentMessage<TextContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContentMessage<VenueContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = true
|
count: Int = 1,
|
||||||
) = waitContentMessage<AudioMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = true,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = true
|
count: Int = 1,
|
||||||
) = waitContentMessage<DocumentMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = true,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = false
|
count: Int = 1,
|
||||||
) = waitContentMessage<MediaContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = false,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = true
|
count: Int = 1,
|
||||||
) = waitContentMessage<MediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = true,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = true
|
count: Int = 1,
|
||||||
) = waitContentMessage<VisualMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = true,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = true
|
count: Int = 1,
|
||||||
) = waitContentMessage<TextedMediaContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = true,
|
||||||
|
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 },
|
||||||
) = waitContentMessage<AnimationContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = false
|
count: Int = 1,
|
||||||
) = waitContentMessage<AudioContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = false,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = false
|
count: Int = 1,
|
||||||
) = waitContentMessage<DocumentContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = false,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = false
|
count: Int = 1,
|
||||||
) = waitContentMessage<PhotoContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = false,
|
||||||
|
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 },
|
||||||
) = waitContentMessage<StickerContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = false
|
count: Int = 1,
|
||||||
) = waitContentMessage<VideoContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = false,
|
||||||
|
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 },
|
||||||
) = waitContentMessage<VideoNoteContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContentMessage<VoiceContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitContentMessage<InvoiceContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
filter: SimpleFilter<CommonMessage<InvoiceContent>>? = null,
|
||||||
|
mapper: CommonMessageToCommonMessageMapper<InvoiceContent>? = null
|
||||||
|
) = waitContentMessage(count, initRequest, false, errorFactory, filter, mapper)
|
||||||
|
@ -16,127 +16,237 @@ 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 dev.inmo.tgbotapi.utils.RiskFeature
|
import kotlinx.coroutines.flow.toList
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
|
||||||
import kotlinx.coroutines.flow.*
|
|
||||||
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
private suspend fun <O> BehaviourContext.waitEditedCommonMessage(
|
||||||
suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedContent(
|
count: Int = 1,
|
||||||
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 },
|
||||||
includeMediaGroups: Boolean = true
|
filter: SimpleFilter<CommonMessage<MessageContent>>? = null,
|
||||||
) = waitEditedContent<MessageContent>(initRequest, includeMediaGroups, errorFactory)
|
mapper: suspend CommonMessage<MessageContent>.() -> O?
|
||||||
|
): List<O> = expectFlow(
|
||||||
|
initRequest,
|
||||||
|
count,
|
||||||
|
errorFactory
|
||||||
|
) {
|
||||||
|
val messages = when (it) {
|
||||||
|
is BaseEditMessageUpdate -> {
|
||||||
|
val commonMessage = it.data.asCommonMessage()
|
||||||
|
if (commonMessage !is MediaGroupMessage<*> || includeMediaGroups) {
|
||||||
|
listOf(commonMessage)
|
||||||
|
} else {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> return@expectFlow emptyList()
|
||||||
|
}
|
||||||
|
messages.mapNotNull { message ->
|
||||||
|
val asCommonMessage = message as CommonMessage<MessageContent>
|
||||||
|
if (filter == null || filter(asCommonMessage)) {
|
||||||
|
asCommonMessage.mapper()
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.toList().toList()
|
||||||
|
|
||||||
|
private suspend inline fun <reified T : MessageContent> BehaviourContext.waitEditedContent(
|
||||||
|
count: Int = 1,
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
includeMediaGroups: Boolean = true,
|
||||||
|
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = true
|
count: Int = 1,
|
||||||
) = waitEditedContent<MessageContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = true,
|
||||||
|
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 },
|
||||||
) = waitEditedContent<ContactContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEditedContent<DiceContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEditedContent<GameContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEditedContent<LocationContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEditedContent<LiveLocationContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEditedContent<StaticLocationContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEditedContent<TextContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEditedContent<VenueContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = true
|
count: Int = 1,
|
||||||
) = waitEditedContent<AudioMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = true,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = true
|
count: Int = 1,
|
||||||
) = waitEditedContent<DocumentMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = true,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = false
|
count: Int = 1,
|
||||||
) = waitEditedContent<MediaContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = false,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = true
|
count: Int = 1,
|
||||||
) = waitEditedContent<MediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = true,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = true
|
count: Int = 1,
|
||||||
) = waitEditedContent<VisualMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = true,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = true
|
count: Int = 1,
|
||||||
) = waitEditedContent<TextedMediaContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = true,
|
||||||
|
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 },
|
||||||
) = waitEditedContent<AnimationContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = false
|
count: Int = 1,
|
||||||
) = waitEditedContent<AudioContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = false,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = false
|
count: Int = 1,
|
||||||
) = waitEditedContent<DocumentContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = false,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = false
|
count: Int = 1,
|
||||||
) = waitEditedContent<PhotoContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = false,
|
||||||
|
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 },
|
||||||
) = waitEditedContent<StickerContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
includeMediaGroups: Boolean = false
|
count: Int = 1,
|
||||||
) = waitEditedContent<VideoContent>(initRequest, includeMediaGroups, errorFactory)
|
includeMediaGroups: Boolean = false,
|
||||||
|
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 },
|
||||||
) = waitEditedContent<VideoNoteContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEditedContent<VoiceContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEditedContent<InvoiceContent>(initRequest, false, errorFactory)
|
count: Int = 1,
|
||||||
|
filter: SimpleFilter<CommonMessage<InvoiceContent>>? = null,
|
||||||
|
mapper: CommonMessageToContentMapper<InvoiceContent>? = null
|
||||||
|
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
|
||||||
|
@ -1,156 +0,0 @@
|
|||||||
@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)
|
|
@ -4,7 +4,8 @@ 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.*
|
import dev.inmo.tgbotapi.extensions.utils.asBaseSentMessageUpdate
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.asChatEventMessage
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.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.*
|
||||||
@ -12,130 +13,272 @@ 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?
|
||||||
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
private suspend fun <O> BehaviourContext.waitEventMessages(
|
||||||
suspend inline fun <reified O : ChatEvent> BehaviourContext.waitEvents(
|
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
): Flow<O> = expectFlow(
|
count: Int = 1,
|
||||||
|
filter: SimpleFilter<ChatEventMessage<ChatEvent>>? = null,
|
||||||
|
mapper: suspend ChatEventMessage<ChatEvent>.() -> O?
|
||||||
|
): List<O> = expectFlow(
|
||||||
initRequest,
|
initRequest,
|
||||||
|
count,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.withEvent<O>() ?.chatEvent.let(::listOfNotNull)
|
val data = it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage()
|
||||||
|
if (data != null && (filter == null || filter(data))) {
|
||||||
|
data.mapper().let(::listOfNotNull)
|
||||||
|
} else {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}.toList().toList()
|
||||||
|
|
||||||
|
|
||||||
|
private suspend inline fun <reified T : ChatEvent> BehaviourContext.waitEvents(
|
||||||
|
count: Int = 1,
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
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 },
|
||||||
) = waitEvents<ChannelEvent>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<PrivateEvent>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<ChatEvent>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<VideoChatEvent>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<VideoChatStarted>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<VideoChatEnded>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<VideoChatParticipantsInvited>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<MessageAutoDeleteTimerChanged>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<PublicChatEvent>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<CommonEvent>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<GroupEvent>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<SupergroupEvent>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<ChannelChatCreated>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<DeleteChatPhoto>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<GroupChatCreated>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<LeftChatMember>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<NewChatPhoto>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<NewChatMembers>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<NewChatTitle>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<PinnedMessage>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<ProximityAlertTriggered>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<SupergroupChatCreated>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<SuccessfulPaymentEvent>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<UserLoggedIn>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitEvents<WebAppData>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
filter: SimpleFilter<PrivateEventMessage<WebAppData>>? = null,
|
||||||
|
mapper: EventMessageToEventMapper<WebAppData>? = null
|
||||||
|
) = waitEvents(count, initRequest, errorFactory, filter ?.let { { it is PrivateEventMessage && filter(it) } }, mapper)
|
||||||
|
@ -1,138 +0,0 @@
|
|||||||
@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)
|
|
@ -5,34 +5,76 @@ 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?
|
||||||
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
private suspend fun <O> BehaviourContext.waitInlineQueries(
|
||||||
suspend inline fun <reified O : InlineQuery> BehaviourContext.waitInlineQueries(
|
count: Int = 1,
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
): Flow<O> = expectFlow(
|
filter: SimpleFilter<InlineQuery>? = null,
|
||||||
|
mapper: suspend InlineQuery.() -> O?
|
||||||
|
): List<O> = expectFlow(
|
||||||
initRequest,
|
initRequest,
|
||||||
|
count,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
(it.asInlineQueryUpdate() ?.data as? O).let(::listOfNotNull)
|
val data = it.asInlineQueryUpdate() ?.data
|
||||||
|
if (data != null && (filter == null || filter(data))) {
|
||||||
|
data.mapper().let(::listOfNotNull)
|
||||||
|
} else {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}.toList().toList()
|
||||||
|
|
||||||
|
|
||||||
|
private suspend inline fun <reified T : InlineQuery> BehaviourContext.waitInlines(
|
||||||
|
count: Int = 1,
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
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 },
|
||||||
) = waitInlineQueries<InlineQuery>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitInlineQueries<BaseInlineQuery>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = waitInlineQueries<LocationInlineQuery>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
filter: SimpleFilter<LocationInlineQuery>? = null,
|
||||||
|
mapper: InlineQueryMapper<LocationInlineQuery>? = null
|
||||||
|
) = waitInlines(count, initRequest, errorFactory, filter, mapper)
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.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.*
|
||||||
@ -11,41 +9,62 @@ 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.RiskFeature
|
import dev.inmo.tgbotapi.utils.PreviewFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import kotlinx.coroutines.flow.take
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.toList
|
||||||
import kotlinx.coroutines.flow.map
|
|
||||||
|
|
||||||
typealias MediaGroupFilter<T> = SimpleFilter<List<MediaGroupMessage<T>>>
|
typealias MediaGroupFilter<T> = suspend List<MediaGroupMessage<T>>.() -> Boolean
|
||||||
|
|
||||||
|
internal suspend inline fun <reified T : MediaGroupContent> BehaviourContext.buildMediaGroupWaiter(
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
count: Int = 1,
|
||||||
suspend inline fun <reified O : MediaGroupContent> BehaviourContext.buildMediaGroupWaiter(
|
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
): Flow<List<O>> = buildMediaGroupMessagesWaiter<O>(initRequest, errorFactory).map { it.map { it.content } }
|
noinline filter: MediaGroupFilter<T>? = null
|
||||||
|
) = flowsUpdatesFilter.expectFlow(bot, initRequest, count, errorFactory) { update ->
|
||||||
|
update.asSentMediaGroupUpdate() ?.data ?.let { mediaGroup ->
|
||||||
|
if (mediaGroup.all { message -> message.content is T } && (filter == null || filter(mediaGroup as List<MediaGroupMessage<T>>))) {
|
||||||
|
listOf(
|
||||||
|
mediaGroup.map { it.content as T }
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
} ?: emptyList()
|
||||||
|
}.take(count).toList()
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitMediaGroup(
|
suspend fun BehaviourContext.waitMediaGroup(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
) = buildMediaGroupWaiter<MediaGroupContent>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = buildMediaGroupWaiter<AudioMediaGroupContent>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = buildMediaGroupWaiter<DocumentMediaGroupContent>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = buildMediaGroupWaiter<VisualMediaGroupContent>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = buildMediaGroupWaiter<PhotoContent>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
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 },
|
||||||
) = buildMediaGroupWaiter<VideoContent>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
filter: MediaGroupFilter<VideoContent>? = null
|
||||||
|
) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter)
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asSentMediaGroupUpdate
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.*
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
|
||||||
suspend inline fun <reified T : MediaGroupContent> BehaviourContext.buildMediaGroupMessagesWaiter(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
): Flow<List<MediaGroupMessage<T>>> = flowsUpdatesFilter.expectFlow(bot, initRequest, errorFactory) { update ->
|
|
||||||
update.asSentMediaGroupUpdate() ?.data ?.let { mediaGroup ->
|
|
||||||
val mapped = mediaGroup.mapNotNull { it.withContent<T>() }
|
|
||||||
listOf(
|
|
||||||
mapped
|
|
||||||
)
|
|
||||||
} ?: emptyList()
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitMediaGroupMessages(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
) = buildMediaGroupMessagesWaiter<MediaGroupContent>(initRequest, errorFactory)
|
|
||||||
suspend fun BehaviourContext.waitPlaylistMessages(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
) = buildMediaGroupMessagesWaiter<AudioMediaGroupContent>(initRequest, errorFactory)
|
|
||||||
suspend fun BehaviourContext.waitDocumentsGroupMessages(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
) = buildMediaGroupMessagesWaiter<DocumentMediaGroupContent>(initRequest, errorFactory)
|
|
||||||
suspend fun BehaviourContext.waitVisualGalleryMessages(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
) = buildMediaGroupMessagesWaiter<VisualMediaGroupContent>(initRequest, errorFactory)
|
|
||||||
suspend fun BehaviourContext.waitPhotoGalleryMessages(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
) = buildMediaGroupMessagesWaiter<PhotoContent>(initRequest, errorFactory)
|
|
||||||
suspend fun BehaviourContext.waitVideoGalleryMessages(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
) = buildMediaGroupMessagesWaiter<VideoContent>(initRequest, errorFactory)
|
|
@ -9,24 +9,57 @@ 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(lowLevelRiskFeatureMessage)
|
@RiskFeature("Do not use this message directly, use waitPassportMessagesWith or waitAnyPassportMessages instead")
|
||||||
suspend inline fun <reified O : EncryptedPassportElement> BehaviourContext.waitPassportMessagesWith(
|
suspend fun <O> BehaviourContext.waitPassportMessages(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
): Flow<O> = expectFlow(
|
count: Int = 1,
|
||||||
|
filter: SimpleFilter<PassportMessage>? = null,
|
||||||
|
mapper: suspend PassportMessage.() -> O?
|
||||||
|
): List<O> = expectFlow(
|
||||||
initRequest,
|
initRequest,
|
||||||
|
count,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
it.asMessageUpdate() ?.data ?.asPassportMessage() ?.passportData ?.data ?.filterIsInstance<O>() ?: emptyList()
|
val data = it.asMessageUpdate() ?.data ?.asPassportMessage() ?: return@expectFlow emptyList()
|
||||||
|
if (filter == null || filter(data)) {
|
||||||
|
data.mapper().let(::listOfNotNull)
|
||||||
|
} else {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}.toList().toList()
|
||||||
|
|
||||||
|
suspend inline fun <reified T : EncryptedPassportElement> BehaviourContext.waitPassportMessagesWith(
|
||||||
|
count: Int = 1,
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
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 },
|
||||||
) = waitPassportMessagesWith<EncryptedPassportElement>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
filter: SimpleFilter<PassportMessage>? = null,
|
||||||
|
mapper: PassportMessageMapper? = null
|
||||||
|
) = waitPassportMessagesWith<EncryptedPassportElement>(count, initRequest, errorFactory, filter, mapper)
|
||||||
|
@ -5,19 +5,60 @@ 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?
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitPollAnswers(
|
private suspend fun <O> BehaviourContext.waitPollsAnswers(
|
||||||
|
count: Int = 1,
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
): Flow<PollAnswer> = expectFlow(
|
filter: SimpleFilter<PollAnswer>? = null,
|
||||||
|
mapper: suspend PollAnswer.() -> O?
|
||||||
|
): List<O> = expectFlow(
|
||||||
initRequest,
|
initRequest,
|
||||||
|
count,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
it.asPollAnswerUpdate() ?.data.let(::listOfNotNull)
|
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(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
count: Int = 1,
|
||||||
|
filter: SimpleFilter<PollAnswer>? = null,
|
||||||
|
mapper: PollAnswerMapper? = null
|
||||||
|
) = waitPollAnswers(count, initRequest, errorFactory, filter, mapper)
|
||||||
|
@ -5,22 +5,55 @@ 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?
|
||||||
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
private suspend fun <O> BehaviourContext.waitPollsUpdates(
|
||||||
suspend inline fun <reified O : Poll> BehaviourContext.waitPolls(
|
count: Int = 1,
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
): Flow<O> = expectFlow(
|
filter: SimpleFilter<Poll>? = null,
|
||||||
|
mapper: suspend Poll.() -> O?
|
||||||
|
): List<O> = expectFlow(
|
||||||
initRequest,
|
initRequest,
|
||||||
|
count,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
(it.asPollUpdate() ?.data as? O).let(::listOfNotNull)
|
val data = it.asPollUpdate() ?.data
|
||||||
|
if (data != null && (filter == null || filter(data))) {
|
||||||
|
data.mapper().let(::listOfNotNull)
|
||||||
|
} else {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}.toList().toList()
|
||||||
|
|
||||||
|
|
||||||
|
private suspend inline fun <reified T : Poll> BehaviourContext.waitPolls(
|
||||||
|
count: Int = 1,
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,21 +61,30 @@ suspend inline fun <reified O : Poll> BehaviourContext.waitPolls(
|
|||||||
*/
|
*/
|
||||||
suspend fun BehaviourContext.waitPollUpdates(
|
suspend fun BehaviourContext.waitPollUpdates(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
) = waitPolls<Poll>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
filter: SimpleFilter<Poll>? = null,
|
||||||
|
mapper: PollMapper<Poll>? = null
|
||||||
|
) = waitPolls(count, initRequest, errorFactory, filter, mapper)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This wait will be triggered only for stopped polls and polls, which are sent by the bot
|
* 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 },
|
||||||
) = waitPolls<QuizPoll>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
filter: SimpleFilter<QuizPoll>? = null,
|
||||||
|
mapper: PollMapper<QuizPoll>? = null
|
||||||
|
) = waitPolls(count, initRequest, errorFactory, filter, mapper)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This wait will be triggered only for stopped polls and polls, which are sent by the bot
|
* 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 },
|
||||||
) = waitPolls<RegularPoll>(initRequest, errorFactory)
|
count: Int = 1,
|
||||||
|
filter: SimpleFilter<RegularPoll>? = null,
|
||||||
|
mapper: PollMapper<RegularPoll>? = null
|
||||||
|
) = waitPolls(count, initRequest, errorFactory, filter, mapper)
|
||||||
|
@ -5,19 +5,45 @@ 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?
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitPreCheckoutQueries(
|
private suspend fun <O> BehaviourContext.waitPreCheckoutQueries(
|
||||||
|
count: Int = 1,
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
): Flow<PreCheckoutQuery> = expectFlow(
|
filter: SimpleFilter<PreCheckoutQuery>? = null,
|
||||||
|
mapper: suspend PreCheckoutQuery.() -> O?
|
||||||
|
): List<O> = expectFlow(
|
||||||
initRequest,
|
initRequest,
|
||||||
|
count,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
it.asPreCheckoutQueryUpdate() ?.data.let(::listOfNotNull)
|
val data = it.asPreCheckoutQueryUpdate() ?.data
|
||||||
|
if (data != null && (filter == null || filter(data))) {
|
||||||
|
data.mapper().let(::listOfNotNull)
|
||||||
|
} else {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}.toList().toList()
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.waitPreCheckoutQueries(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
count: Int = 1,
|
||||||
|
filter: SimpleFilter<PreCheckoutQuery>? = null,
|
||||||
|
mapper: PreCheckoutQueryMapper? = null
|
||||||
|
) : List<PreCheckoutQuery> = waitPreCheckoutQueries(
|
||||||
|
count,
|
||||||
|
initRequest,
|
||||||
|
errorFactory,
|
||||||
|
filter
|
||||||
|
) {
|
||||||
|
if (mapper == null) {
|
||||||
|
this
|
||||||
|
} else {
|
||||||
|
mapper(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,17 +5,45 @@ 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?
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitShippingQueries(
|
private suspend fun <O> BehaviourContext.waitShippingQueries(
|
||||||
|
count: Int = 1,
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
): Flow<ShippingQuery> = expectFlow(
|
filter: SimpleFilter<ShippingQuery>? = null,
|
||||||
|
mapper: suspend ShippingQuery.() -> O?
|
||||||
|
): List<O> = expectFlow(
|
||||||
initRequest,
|
initRequest,
|
||||||
|
count,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
(it.asShippingQueryUpdate() ?.data).let(::listOfNotNull)
|
val data = it.asShippingQueryUpdate() ?.data
|
||||||
|
if (data != null && (filter == null || filter(data))) {
|
||||||
|
data.mapper().let(::listOfNotNull)
|
||||||
|
} else {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}.toList().toList()
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.waitShippingQueries(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
count: Int = 1,
|
||||||
|
filter: SimpleFilter<ShippingQuery>? = null,
|
||||||
|
mapper: ShippingQueryMapper? = null
|
||||||
|
) : List<ShippingQuery> = waitShippingQueries(
|
||||||
|
count,
|
||||||
|
initRequest,
|
||||||
|
errorFactory,
|
||||||
|
filter
|
||||||
|
) {
|
||||||
|
if (mapper == null) {
|
||||||
|
this
|
||||||
|
} else {
|
||||||
|
mapper(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ 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
|
||||||
@ -33,6 +34,7 @@ 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,
|
||||||
|
@ -84,6 +84,86 @@ 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,
|
||||||
|
@ -15,17 +15,16 @@ 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) it to data else null
|
if (initialFilter ?.invoke(data) != false) data else null
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
}.subscribeSafelyWithoutExceptionsAsync(
|
}.subscribeSafelyWithoutExceptionsAsync(
|
||||||
scope,
|
scope,
|
||||||
{ markerFactory(it.second) }
|
markerFactory::invoke
|
||||||
) { (update, triggerData) ->
|
) { triggerData ->
|
||||||
createSubContextAndDoWithUpdatesFilter(
|
createSubContextAndDoWithUpdatesFilter(
|
||||||
|
updatesFilter = subcontextUpdatesFilter ?.toOneType(triggerData),
|
||||||
stopOnCompletion = false
|
stopOnCompletion = false
|
||||||
) {
|
) {
|
||||||
if (subcontextUpdatesFilter ?.invoke(this, triggerData, update) != false) {
|
|
||||||
scenarioReceiver(triggerData)
|
scenarioReceiver(triggerData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -3,12 +3,9 @@ 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
|
||||||
@ -23,7 +20,11 @@ suspend fun BehaviourContext.followLocation(
|
|||||||
onLocation(message.content.location)
|
onLocation(message.content.location)
|
||||||
|
|
||||||
while (currentLocation !is StaticLocation) {
|
while (currentLocation !is StaticLocation) {
|
||||||
currentLocation = waitEditedLocationMessage().filter { it.messageId == message.messageId && it.chat.id == message.chat.id }.first().content.location
|
currentLocation = waitEditedLocation(
|
||||||
|
filter = {
|
||||||
|
it.messageId == message.messageId && it.chat.id == message.chat.id
|
||||||
|
}
|
||||||
|
).first().location
|
||||||
onLocation(currentLocation)
|
onLocation(currentLocation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("CommonContactData", "dev.inmo.tgbotapi.abstracts.CommonContactData"))
|
||||||
|
typealias CommonContactData = dev.inmo.tgbotapi.abstracts.CommonContactData
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("CommonSendInvoiceData", "dev.inmo.tgbotapi.abstracts.CommonSendInvoiceData"))
|
||||||
|
typealias CommonSendInvoiceData = dev.inmo.tgbotapi.abstracts.CommonSendInvoiceData
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("CommonVenueData", "dev.inmo.tgbotapi.abstracts.CommonVenueData"))
|
||||||
|
typealias CommonVenueData = dev.inmo.tgbotapi.abstracts.CommonVenueData
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("FromUser", "dev.inmo.tgbotapi.abstracts.FromUser"))
|
||||||
|
typealias FromUser = dev.inmo.tgbotapi.abstracts.FromUser
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("Headed", "dev.inmo.tgbotapi.abstracts.Headed"))
|
||||||
|
typealias Headed = dev.inmo.tgbotapi.abstracts.Headed
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("HorizontallyAccured", "dev.inmo.tgbotapi.abstracts.HorizontallyAccured"))
|
||||||
|
typealias HorizontallyAccured = dev.inmo.tgbotapi.abstracts.HorizontallyAccured
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("Livable", "dev.inmo.tgbotapi.abstracts.Livable"))
|
||||||
|
typealias Livable = dev.inmo.tgbotapi.abstracts.Livable
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("Locationed", "dev.inmo.tgbotapi.abstracts.Locationed"))
|
||||||
|
typealias Locationed = dev.inmo.tgbotapi.abstracts.Locationed
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("MimeTyped", "dev.inmo.tgbotapi.abstracts.MimeTyped"))
|
||||||
|
typealias MimeTyped = dev.inmo.tgbotapi.abstracts.MimeTyped
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("Performerable", "dev.inmo.tgbotapi.abstracts.Performerable"))
|
||||||
|
typealias Performerable = dev.inmo.tgbotapi.abstracts.Performerable
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("ProximityAlertable", "dev.inmo.tgbotapi.abstracts.ProximityAlertable"))
|
||||||
|
typealias ProximityAlertable = dev.inmo.tgbotapi.abstracts.ProximityAlertable
|
@ -0,0 +1,18 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("Titled", "dev.inmo.tgbotapi.abstracts.Titled"))
|
||||||
|
typealias Titled = dev.inmo.tgbotapi.abstracts.Titled
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("WithUser", "dev.inmo.tgbotapi.abstracts.WithUser"))
|
||||||
|
typealias WithUser = dev.inmo.tgbotapi.abstracts.WithUser
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts.types
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("ChatRequest", "dev.inmo.tgbotapi.abstracts.types.ChatRequest"))
|
||||||
|
typealias ChatRequest = dev.inmo.tgbotapi.abstracts.types.ChatRequest
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts.types
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("DisableNotification", "dev.inmo.tgbotapi.abstracts.types.DisableNotification"))
|
||||||
|
typealias DisableNotification = dev.inmo.tgbotapi.abstracts.types.DisableNotification
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts.types
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("DisableWebPagePreview", "dev.inmo.tgbotapi.abstracts.types.DisableWebPagePreview"))
|
||||||
|
typealias DisableWebPagePreview = dev.inmo.tgbotapi.abstracts.types.DisableWebPagePreview
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts.types
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("InlineMessageAction", "dev.inmo.tgbotapi.abstracts.types.InlineMessageAction"))
|
||||||
|
typealias InlineMessageAction = dev.inmo.tgbotapi.abstracts.types.InlineMessageAction
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts.types
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("MessageAction:", "dev.inmo.tgbotapi.abstracts.types.MessageAction:"))
|
||||||
|
typealias MessageAction = dev.inmo.tgbotapi.abstracts.types.MessageAction
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts.types
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("OptionalChatRequest", "dev.inmo.tgbotapi.abstracts.types.OptionalChatRequest"))
|
||||||
|
typealias OptionalChatRequest = dev.inmo.tgbotapi.abstracts.types.OptionalChatRequest
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts.types
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("ProtectContent", "dev.inmo.tgbotapi.abstracts.types.ProtectContent"))
|
||||||
|
typealias ProtectContent = dev.inmo.tgbotapi.abstracts.types.ProtectContent
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts.types
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("ReplyMarkup", "dev.inmo.tgbotapi.abstracts.types.ReplyMarkup"))
|
||||||
|
typealias ReplyMarkup = dev.inmo.tgbotapi.abstracts.types.ReplyMarkup
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts.types
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("ReplyMessageId", "dev.inmo.tgbotapi.abstracts.types.ReplyMessageId"))
|
||||||
|
typealias ReplyMessageId = dev.inmo.tgbotapi.abstracts.types.ReplyMessageId
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.CommonAbstracts.types
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("UntilDate", "dev.inmo.tgbotapi.abstracts.types.UntilDate"))
|
||||||
|
typealias UntilDate = dev.inmo.tgbotapi.abstracts.types.UntilDate
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.tgbotapi.bot.Ktor
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("KtorCallFactory", "dev.inmo.tgbotapi.bot.ktor.KtorCallFactory"))
|
||||||
|
typealias KtorCallFactory = dev.inmo.tgbotapi.bot.ktor.KtorCallFactory
|
@ -0,0 +1,32 @@
|
|||||||
|
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)
|
@ -0,0 +1,6 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -79,8 +79,21 @@ 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
|
||||||
|
@ -2,7 +2,6 @@ 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
|
||||||
|
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,7 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,7 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,7 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,7 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,7 @@
|
|||||||
|
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
|
@ -0,0 +1,7 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,4 @@
|
|||||||
|
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
|
@ -0,0 +1,39 @@
|
|||||||
|
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
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,62 @@
|
|||||||
|
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
|
||||||
|
)
|
@ -0,0 +1,53 @@
|
|||||||
|
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
Loading…
Reference in New Issue
Block a user