mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
fixes
This commit is contained in:
parent
b32ce88a97
commit
f6f07a5e8a
@ -1,69 +1,57 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.api.InternalUtils
|
package dev.inmo.tgbotapi.extensions.api.InternalUtils
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
|
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
|
||||||
import dev.inmo.tgbotapi.types.UpdateIdentifier
|
import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
|
||||||
import dev.inmo.tgbotapi.types.update.*
|
import dev.inmo.tgbotapi.types.update.*
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.*
|
import dev.inmo.tgbotapi.types.update.abstracts.*
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.*
|
import dev.inmo.tgbotapi.utils.extensions.asMediaGroupMessage
|
||||||
|
|
||||||
internal fun Update.lastUpdateIdentifier(): UpdateIdentifier {
|
|
||||||
return if (this is SentMediaGroupUpdate) {
|
|
||||||
origins.last().updateId
|
|
||||||
} else {
|
|
||||||
updateId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun List<Update>.lastUpdateIdentifier(): UpdateIdentifier? {
|
|
||||||
return maxByOrNull { it.updateId } ?.lastUpdateIdentifier()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will convert incoming list of updates to list with [MediaGroupUpdate]s
|
||||||
|
*/
|
||||||
internal fun List<Update>.convertWithMediaGroupUpdates(): List<Update> {
|
internal fun List<Update>.convertWithMediaGroupUpdates(): List<Update> {
|
||||||
val resultUpdates = mutableListOf<Update>()
|
val resultUpdates = mutableListOf<Update>()
|
||||||
val mediaGroups = mutableMapOf<MediaGroupIdentifier, MutableList<BaseSentMessageUpdate>>()
|
val mediaGroups = mutableMapOf<MediaGroupIdentifier, MutableList<Pair<BaseSentMessageUpdate, PossiblySentViaBotCommonMessage<MediaGroupPartContent>>>>()
|
||||||
|
|
||||||
for (update in this) {
|
for (update in this) {
|
||||||
val data = (update.data as? MediaGroupMessage<*>)
|
val message = (update.data as? PossiblySentViaBotCommonMessage<*>) ?.let {
|
||||||
if (data == null) {
|
if (it.content is MediaGroupPartContent) {
|
||||||
|
it as PossiblySentViaBotCommonMessage<MediaGroupPartContent>
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val mediaGroupId = message ?.mediaGroupId
|
||||||
|
if (message == null || mediaGroupId == null) {
|
||||||
resultUpdates.add(update)
|
resultUpdates.add(update)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
when (update) {
|
when (update) {
|
||||||
is BaseEditMessageUpdate -> resultUpdates.add(
|
|
||||||
update.toEditMediaGroupUpdate()
|
|
||||||
)
|
|
||||||
is BaseSentMessageUpdate -> {
|
is BaseSentMessageUpdate -> {
|
||||||
mediaGroups.getOrPut(data.mediaGroupId) {
|
mediaGroups.getOrPut(mediaGroupId) {
|
||||||
mutableListOf()
|
mutableListOf()
|
||||||
}.add(update)
|
}.add(update to message)
|
||||||
}
|
}
|
||||||
else -> resultUpdates.add(update)
|
else -> resultUpdates.add(update)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mediaGroups.values.map {
|
|
||||||
it.toSentMediaGroupUpdate() ?.let { mediaGroupUpdate ->
|
mediaGroups.map { (_, updatesWithMessages) ->
|
||||||
resultUpdates.add(mediaGroupUpdate)
|
val update = updatesWithMessages.maxBy { it.first.updateId }.first
|
||||||
}
|
resultUpdates.add(
|
||||||
|
update.copy(updatesWithMessages.map { it.second }.asMediaGroupMessage())
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
resultUpdates.sortBy { it.updateId }
|
resultUpdates.sortBy { it.updateId }
|
||||||
return resultUpdates
|
return resultUpdates
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun List<BaseSentMessageUpdate>.toSentMediaGroupUpdate(): SentMediaGroupUpdate? = (this as? SentMediaGroupUpdate) ?: let {
|
/**
|
||||||
if (isEmpty()) {
|
* @return [EditMessageMediaGroupUpdate] in case if [this] is [EditMessageUpdate]. When [this] object is
|
||||||
return@let null
|
* [EditChannelPostUpdate] instance - will return [EditChannelPostMediaGroupUpdate]
|
||||||
}
|
*
|
||||||
val resultList = sortedBy { it.updateId }
|
* @throws IllegalStateException
|
||||||
when (first()) {
|
*/
|
||||||
is MessageUpdate -> MessageMediaGroupUpdate(resultList)
|
internal fun BaseEditMessageUpdate.toEditMediaGroupUpdate() = this
|
||||||
is ChannelPostUpdate -> ChannelPostMediaGroupUpdate(resultList)
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun BaseEditMessageUpdate.toEditMediaGroupUpdate(): EditMediaGroupUpdate = (this as? EditMediaGroupUpdate) ?: let {
|
|
||||||
when (this) {
|
|
||||||
is EditMessageUpdate -> EditMessageMediaGroupUpdate(this)
|
|
||||||
is EditChannelPostUpdate -> EditChannelPostMediaGroupUpdate(this)
|
|
||||||
else -> error("Unsupported type of ${BaseEditMessageUpdate::class.simpleName}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,183 +0,0 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.api.send
|
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.media.sendMediaGroup
|
|
||||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
|
||||||
import dev.inmo.tgbotapi.types.media.*
|
|
||||||
import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList
|
|
||||||
import dev.inmo.tgbotapi.types.MessageId
|
|
||||||
import dev.inmo.tgbotapi.types.MessageThreadId
|
|
||||||
import dev.inmo.tgbotapi.types.message.ParseMode
|
|
||||||
import dev.inmo.tgbotapi.types.chat.Chat
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
|
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements
|
|
||||||
* will be copied as they are
|
|
||||||
*/
|
|
||||||
suspend inline fun TelegramBot.copyMessages(
|
|
||||||
toChatId: ChatIdentifier,
|
|
||||||
messages: List<MediaGroupMessage<MediaGroupPartContent>>,
|
|
||||||
text: String? = null,
|
|
||||||
parseMode: ParseMode? = null,
|
|
||||||
threadId: MessageThreadId? = null,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyToMessageId: MessageId? = null,
|
|
||||||
allowSendingWithoutReply: Boolean? = null
|
|
||||||
): List<MediaGroupMessage<MediaGroupPartContent>> {
|
|
||||||
val first = messages.first().content.toMediaGroupMemberTelegramMedia().let {
|
|
||||||
if (text != null) {
|
|
||||||
when (it) {
|
|
||||||
is TelegramMediaAudio -> it.copy(text = text, parseMode = parseMode)
|
|
||||||
is TelegramMediaDocument -> it.copy(text = text, parseMode = parseMode)
|
|
||||||
is TelegramMediaPhoto -> it.copy(text = text, parseMode = parseMode)
|
|
||||||
is TelegramMediaVideo -> it.copy(text = text, parseMode = parseMode)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sendMediaGroup(
|
|
||||||
toChatId,
|
|
||||||
listOf(first) + messages.drop(1).map {
|
|
||||||
it.content.toMediaGroupMemberTelegramMedia()
|
|
||||||
},
|
|
||||||
threadId,
|
|
||||||
disableNotification,
|
|
||||||
protectContent,
|
|
||||||
replyToMessageId,
|
|
||||||
allowSendingWithoutReply
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements
|
|
||||||
* will be copied as they are
|
|
||||||
*/
|
|
||||||
suspend inline fun TelegramBot.copyMessages(
|
|
||||||
toChat: Chat,
|
|
||||||
messages: List<MediaGroupMessage<MediaGroupPartContent>>,
|
|
||||||
text: String? = null,
|
|
||||||
parseMode: ParseMode? = null,
|
|
||||||
threadId: MessageThreadId? = null,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyToMessageId: MessageId? = null,
|
|
||||||
allowSendingWithoutReply: Boolean? = null
|
|
||||||
) = copyMessages(toChat.id, messages, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements
|
|
||||||
* will be copied as they are
|
|
||||||
*/
|
|
||||||
suspend inline fun TelegramBot.copyMessages(
|
|
||||||
toChat: ChatIdentifier,
|
|
||||||
update: SentMediaGroupUpdate,
|
|
||||||
text: String? = null,
|
|
||||||
parseMode: ParseMode? = null,
|
|
||||||
threadId: MessageThreadId? = null,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyToMessageId: MessageId? = null,
|
|
||||||
allowSendingWithoutReply: Boolean? = null
|
|
||||||
) = copyMessages(toChat, update.data, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements
|
|
||||||
* will be copied as they are
|
|
||||||
*/
|
|
||||||
suspend inline fun TelegramBot.copyMessages(
|
|
||||||
toChat: Chat,
|
|
||||||
update: SentMediaGroupUpdate,
|
|
||||||
text: String? = null,
|
|
||||||
parseMode: ParseMode? = null,
|
|
||||||
threadId: MessageThreadId? = null,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyToMessageId: MessageId? = null,
|
|
||||||
allowSendingWithoutReply: Boolean? = null
|
|
||||||
) = copyMessages(toChat.id, update, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements
|
|
||||||
* will be copied as they are
|
|
||||||
*/
|
|
||||||
suspend inline fun TelegramBot.copyMessages(
|
|
||||||
toChatId: ChatIdentifier,
|
|
||||||
messages: List<MediaGroupMessage<MediaGroupPartContent>>,
|
|
||||||
entities: TextSourcesList,
|
|
||||||
threadId: MessageThreadId? = null,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyToMessageId: MessageId? = null,
|
|
||||||
allowSendingWithoutReply: Boolean? = null
|
|
||||||
): List<MediaGroupMessage<MediaGroupPartContent>> {
|
|
||||||
val first = messages.first().content.toMediaGroupMemberTelegramMedia().let {
|
|
||||||
when (it) {
|
|
||||||
is TelegramMediaAudio -> TelegramMediaAudio(it.file, entities, it.duration, it.performer, it.title, it.thumb)
|
|
||||||
is TelegramMediaDocument -> TelegramMediaDocument(it.file, entities, it.thumb, it.disableContentTypeDetection)
|
|
||||||
is TelegramMediaPhoto -> TelegramMediaPhoto(it.file, entities)
|
|
||||||
is TelegramMediaVideo -> TelegramMediaVideo(it.file, entities, it.width, it.height, it.duration, it.thumb)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sendMediaGroup(
|
|
||||||
toChatId,
|
|
||||||
listOf(first) + messages.drop(1).map {
|
|
||||||
it.content.toMediaGroupMemberTelegramMedia()
|
|
||||||
},
|
|
||||||
threadId,
|
|
||||||
disableNotification,
|
|
||||||
protectContent,
|
|
||||||
replyToMessageId,
|
|
||||||
allowSendingWithoutReply
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements
|
|
||||||
* will be copied as they are
|
|
||||||
*/
|
|
||||||
suspend inline fun TelegramBot.copyMessages(
|
|
||||||
toChat: Chat,
|
|
||||||
messages: List<MediaGroupMessage<MediaGroupPartContent>>,
|
|
||||||
entities: TextSourcesList,
|
|
||||||
threadId: MessageThreadId? = null,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyToMessageId: MessageId? = null,
|
|
||||||
allowSendingWithoutReply: Boolean? = null
|
|
||||||
) = copyMessages(toChat.id, messages, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements
|
|
||||||
* will be copied as they are
|
|
||||||
*/
|
|
||||||
suspend inline fun TelegramBot.copyMessages(
|
|
||||||
toChat: ChatIdentifier,
|
|
||||||
update: SentMediaGroupUpdate,
|
|
||||||
entities: TextSourcesList,
|
|
||||||
threadId: MessageThreadId? = null,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyToMessageId: MessageId? = null,
|
|
||||||
allowSendingWithoutReply: Boolean? = null
|
|
||||||
) = copyMessages(toChat, update.data, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements
|
|
||||||
* will be copied as they are
|
|
||||||
*/
|
|
||||||
suspend inline fun TelegramBot.copyMessages(
|
|
||||||
toChat: Chat,
|
|
||||||
update: SentMediaGroupUpdate,
|
|
||||||
entities: TextSourcesList,
|
|
||||||
threadId: MessageThreadId? = null,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyToMessageId: MessageId? = null,
|
|
||||||
allowSendingWithoutReply: Boolean? = null
|
|
||||||
) = copyMessages(toChat.id, update, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply)
|
|
@ -1,6 +1,7 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.api.utils
|
package dev.inmo.tgbotapi.extensions.api.utils
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.InternalUtils.convertWithMediaGroupUpdates
|
import dev.inmo.tgbotapi.extensions.api.InternalUtils.convertWithMediaGroupUpdates
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
import dev.inmo.tgbotapi.updateshandlers.UpdateReceiver
|
import dev.inmo.tgbotapi.updateshandlers.UpdateReceiver
|
||||||
@ -29,10 +30,21 @@ fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation(
|
|||||||
launch {
|
launch {
|
||||||
launch {
|
launch {
|
||||||
for (update in updatesChannel) {
|
for (update in updatesChannel) {
|
||||||
when (val data = update.data) {
|
val dataAsPossiblySentViaBotCommonMessage = update.data as? PossiblySentViaBotCommonMessage<*>
|
||||||
is MediaGroupMessage<*> -> mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate)
|
|
||||||
else -> output(update)
|
if (dataAsPossiblySentViaBotCommonMessage == null) {
|
||||||
|
output(update)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val mediaGroupId = dataAsPossiblySentViaBotCommonMessage.mediaGroupId
|
||||||
|
|
||||||
|
if (mediaGroupId == null) {
|
||||||
|
output(update)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
mediaGroupChannel.send("${mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
launch {
|
launch {
|
||||||
|
@ -9,7 +9,6 @@ import dev.inmo.tgbotapi.requests.abstracts.Request
|
|||||||
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.update.abstracts.BaseSentMessageUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
@ -25,20 +24,7 @@ suspend inline fun <reified O : MessageContent> BehaviourContext.waitContentMess
|
|||||||
initRequest,
|
initRequest,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
val messages = when (it) {
|
listOfNotNull((it.data as? CommonMessage<*>) ?.withContent<O>())
|
||||||
is SentMediaGroupUpdate -> {
|
|
||||||
if (includeMediaGroups) {
|
|
||||||
it.data
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is BaseSentMessageUpdate -> listOf(it.data)
|
|
||||||
else -> return@expectFlow emptyList()
|
|
||||||
}
|
|
||||||
messages.mapNotNull { message ->
|
|
||||||
(message as? CommonMessage<*>) ?.withContent<O>()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal inline fun <reified T : MessageContent> contentMessageConverter(
|
internal inline fun <reified T : MessageContent> contentMessageConverter(
|
||||||
|
@ -15,7 +15,7 @@ suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedConte
|
|||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
includeMediaGroups: Boolean = true,
|
includeMediaGroups: Boolean = true,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
): Flow<O> = waitEditedContentMessage<O>(initRequest, includeMediaGroups, errorFactory).map { it.content }
|
): Flow<O> = waitEditedContentMessage<O>(initRequest, errorFactory).map { it.content }
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitEditedMessageContent(
|
suspend fun BehaviourContext.waitEditedMessageContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.baseEditMessageUpdateOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.commonMessageOrNull
|
import dev.inmo.tgbotapi.extensions.utils.commonMessageOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
import dev.inmo.tgbotapi.extensions.utils.withContent
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
@ -16,7 +17,6 @@ import kotlinx.coroutines.flow.Flow
|
|||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedContentMessage(
|
suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
includeMediaGroups: Boolean = true,
|
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
): Flow<CommonMessage<O>> = expectFlow(
|
): Flow<CommonMessage<O>> = expectFlow(
|
||||||
initRequest,
|
initRequest,
|
||||||
@ -25,11 +25,7 @@ suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedConte
|
|||||||
val messages = when (it) {
|
val messages = when (it) {
|
||||||
is BaseEditMessageUpdate -> {
|
is BaseEditMessageUpdate -> {
|
||||||
val commonMessage = it.data.commonMessageOrNull() ?: return@expectFlow emptyList()
|
val commonMessage = it.data.commonMessageOrNull() ?: return@expectFlow emptyList()
|
||||||
if (commonMessage !is MediaGroupMessage<*> || includeMediaGroups) {
|
|
||||||
listOf(commonMessage)
|
listOf(commonMessage)
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else -> return@expectFlow emptyList()
|
else -> return@expectFlow emptyList()
|
||||||
}
|
}
|
||||||
@ -40,109 +36,103 @@ suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedConte
|
|||||||
|
|
||||||
suspend fun BehaviourContext.waitEditedMessageContentMessage(
|
suspend fun BehaviourContext.waitEditedMessageContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
includeMediaGroups: Boolean = true
|
) = waitEditedContentMessage<MessageContent>(initRequest, errorFactory)
|
||||||
) = waitEditedContentMessage<MessageContent>(initRequest, includeMediaGroups, errorFactory)
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitEditedContactMessage(
|
suspend fun BehaviourContext.waitEditedContactMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitEditedContentMessage<ContactContent>(initRequest, false, errorFactory)
|
) = waitEditedContentMessage<ContactContent>(initRequest, errorFactory)
|
||||||
suspend fun BehaviourContext.waitEditedDiceMessage(
|
suspend fun BehaviourContext.waitEditedDiceMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitEditedContentMessage<DiceContent>(initRequest, false, errorFactory)
|
) = waitEditedContentMessage<DiceContent>(initRequest, errorFactory)
|
||||||
suspend fun BehaviourContext.waitEditedGameMessage(
|
suspend fun BehaviourContext.waitEditedGameMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitEditedContentMessage<GameContent>(initRequest, false, errorFactory)
|
) = waitEditedContentMessage<GameContent>(initRequest, errorFactory)
|
||||||
suspend fun BehaviourContext.waitEditedLocationMessage(
|
suspend fun BehaviourContext.waitEditedLocationMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitEditedContentMessage<LocationContent>(initRequest, false, errorFactory)
|
) = waitEditedContentMessage<LocationContent>(initRequest, errorFactory)
|
||||||
suspend fun BehaviourContext.waitEditedLiveLocationMessage(
|
suspend fun BehaviourContext.waitEditedLiveLocationMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitEditedContentMessage<LiveLocationContent>(initRequest, false, errorFactory)
|
) = waitEditedContentMessage<LiveLocationContent>(initRequest, errorFactory)
|
||||||
suspend fun BehaviourContext.waitEditedStaticLocationMessage(
|
suspend fun BehaviourContext.waitEditedStaticLocationMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitEditedContentMessage<StaticLocationContent>(initRequest, false, errorFactory)
|
) = waitEditedContentMessage<StaticLocationContent>(initRequest, errorFactory)
|
||||||
suspend fun BehaviourContext.waitEditedTextMessage(
|
suspend fun BehaviourContext.waitEditedTextMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitEditedContentMessage<TextContent>(initRequest, false, errorFactory)
|
) = waitEditedContentMessage<TextContent>(initRequest, errorFactory)
|
||||||
suspend fun BehaviourContext.waitEditedVenueMessage(
|
suspend fun BehaviourContext.waitEditedVenueMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitEditedContentMessage<VenueContent>(initRequest, false, errorFactory)
|
) = waitEditedContentMessage<VenueContent>(initRequest, errorFactory)
|
||||||
suspend fun BehaviourContext.waitEditedAudioMediaGroupContentMessage(
|
suspend fun BehaviourContext.waitEditedAudioMediaGroupContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
includeMediaGroups: Boolean = true
|
) = waitEditedContentMessage<AudioMediaGroupPartContent>(initRequest, errorFactory)
|
||||||
) = waitEditedContentMessage<AudioMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
|
|
||||||
suspend fun BehaviourContext.waitEditedDocumentMediaGroupContentMessage(
|
suspend fun BehaviourContext.waitEditedDocumentMediaGroupContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
includeMediaGroups: Boolean = true
|
) = waitEditedContentMessage<DocumentMediaGroupPartContent>(initRequest, errorFactory)
|
||||||
) = waitEditedContentMessage<DocumentMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
|
|
||||||
suspend fun BehaviourContext.waitEditedMediaMessage(
|
suspend fun BehaviourContext.waitEditedMediaMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
includeMediaGroups: Boolean = false
|
includeMediaGroups: Boolean = false
|
||||||
) = waitEditedContentMessage<MediaContent>(initRequest, includeMediaGroups, errorFactory)
|
) = waitEditedContentMessage<MediaContent>(initRequest, errorFactory)
|
||||||
suspend fun BehaviourContext.waitEditedAnyMediaGroupContentMessage(
|
suspend fun BehaviourContext.waitEditedAnyMediaGroupContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
includeMediaGroups: Boolean = true
|
) = waitEditedContentMessage<MediaGroupPartContent>(initRequest, errorFactory)
|
||||||
) = waitEditedContentMessage<MediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
|
|
||||||
suspend fun BehaviourContext.waitEditedVisualMediaGroupContentMessage(
|
suspend fun BehaviourContext.waitEditedVisualMediaGroupContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
includeMediaGroups: Boolean = true
|
) = waitEditedContentMessage<VisualMediaGroupPartContent>(initRequest, errorFactory)
|
||||||
) = waitEditedContentMessage<VisualMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
|
|
||||||
suspend fun BehaviourContext.waitEditedTextedMediaContentMessage(
|
suspend fun BehaviourContext.waitEditedTextedMediaContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
includeMediaGroups: Boolean = true
|
) = waitEditedContentMessage<TextedMediaContent>(initRequest, errorFactory)
|
||||||
) = waitEditedContentMessage<TextedMediaContent>(initRequest, includeMediaGroups, errorFactory)
|
|
||||||
suspend fun BehaviourContext.waitEditedAnimationMessage(
|
suspend fun BehaviourContext.waitEditedAnimationMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitEditedContentMessage<AnimationContent>(initRequest, false, errorFactory)
|
) = waitEditedContentMessage<AnimationContent>(initRequest, errorFactory)
|
||||||
suspend fun BehaviourContext.waitEditedAudioMessage(
|
suspend fun BehaviourContext.waitEditedAudioMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
includeMediaGroups: Boolean = false
|
includeMediaGroups: Boolean = false
|
||||||
) = waitEditedContentMessage<AudioContent>(initRequest, includeMediaGroups, errorFactory)
|
) = waitEditedContentMessage<AudioContent>(initRequest, errorFactory)
|
||||||
suspend fun BehaviourContext.waitEditedDocumentMessage(
|
suspend fun BehaviourContext.waitEditedDocumentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
includeMediaGroups: Boolean = false
|
includeMediaGroups: Boolean = false
|
||||||
) = waitEditedContentMessage<DocumentContent>(initRequest, includeMediaGroups, errorFactory)
|
) = waitEditedContentMessage<DocumentContent>(initRequest, errorFactory)
|
||||||
suspend fun BehaviourContext.waitEditedPhotoMessage(
|
suspend fun BehaviourContext.waitEditedPhotoMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
includeMediaGroups: Boolean = false
|
includeMediaGroups: Boolean = false
|
||||||
) = waitEditedContentMessage<PhotoContent>(initRequest, includeMediaGroups, errorFactory)
|
) = waitEditedContentMessage<PhotoContent>(initRequest, errorFactory)
|
||||||
suspend fun BehaviourContext.waitEditedStickerMessage(
|
suspend fun BehaviourContext.waitEditedStickerMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitEditedContentMessage<StickerContent>(initRequest, false, errorFactory)
|
) = waitEditedContentMessage<StickerContent>(initRequest, errorFactory)
|
||||||
suspend fun BehaviourContext.waitEditedVideoMessage(
|
suspend fun BehaviourContext.waitEditedVideoMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
includeMediaGroups: Boolean = false
|
includeMediaGroups: Boolean = false
|
||||||
) = waitEditedContentMessage<VideoContent>(initRequest, includeMediaGroups, errorFactory)
|
) = waitEditedContentMessage<VideoContent>(initRequest, errorFactory)
|
||||||
suspend fun BehaviourContext.waitEditedVideoNoteMessage(
|
suspend fun BehaviourContext.waitEditedVideoNoteMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitEditedContentMessage<VideoNoteContent>(initRequest, false, errorFactory)
|
) = waitEditedContentMessage<VideoNoteContent>(initRequest, errorFactory)
|
||||||
suspend fun BehaviourContext.waitEditedVoiceMessage(
|
suspend fun BehaviourContext.waitEditedVoiceMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitEditedContentMessage<VoiceContent>(initRequest, false, errorFactory)
|
) = waitEditedContentMessage<VoiceContent>(initRequest, errorFactory)
|
||||||
suspend fun BehaviourContext.waitEditedInvoiceMessage(
|
suspend fun BehaviourContext.waitEditedInvoiceMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitEditedContentMessage<InvoiceContent>(initRequest, false, errorFactory)
|
) = waitEditedContentMessage<InvoiceContent>(initRequest, errorFactory)
|
||||||
|
@ -1,44 +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.requests.abstracts.Request
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.*
|
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
import kotlinx.coroutines.flow.map
|
|
||||||
|
|
||||||
typealias MediaGroupFilter<T> = SimpleFilter<List<MediaGroupMessage<T>>>
|
|
||||||
|
|
||||||
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
|
||||||
suspend inline fun <reified O : MediaGroupPartContent> BehaviourContext.buildMediaGroupWaiter(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
): Flow<List<O>> = buildMediaGroupMessagesWaiter<O>(initRequest, errorFactory).map { it.map { it.content } }
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitMediaGroup(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
) = buildMediaGroupWaiter<MediaGroupPartContent>(initRequest, errorFactory)
|
|
||||||
suspend fun BehaviourContext.waitPlaylist(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
) = buildMediaGroupWaiter<AudioMediaGroupPartContent>(initRequest, errorFactory)
|
|
||||||
suspend fun BehaviourContext.waitDocumentsGroup(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
) = buildMediaGroupWaiter<DocumentMediaGroupPartContent>(initRequest, errorFactory)
|
|
||||||
suspend fun BehaviourContext.waitVisualGallery(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
) = buildMediaGroupWaiter<VisualMediaGroupPartContent>(initRequest, errorFactory)
|
|
||||||
suspend fun BehaviourContext.waitPhotoGallery(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
) = buildMediaGroupWaiter<PhotoContent>(initRequest, errorFactory)
|
|
||||||
suspend fun BehaviourContext.waitVideoGallery(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
) = buildMediaGroupWaiter<VideoContent>(initRequest, errorFactory)
|
|
@ -1,48 +0,0 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.sentMediaGroupUpdateOrNull
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.*
|
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
|
||||||
suspend inline fun <reified T : MediaGroupPartContent> BehaviourContext.buildMediaGroupMessagesWaiter(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
): Flow<List<MediaGroupMessage<T>>> = flowsUpdatesFilter.expectFlow(bot, initRequest, errorFactory) { update ->
|
|
||||||
update.sentMediaGroupUpdateOrNull() ?.data ?.let { mediaGroup ->
|
|
||||||
val mapped = mediaGroup.mapNotNull { it.withContent<T>() }
|
|
||||||
listOf(
|
|
||||||
mapped
|
|
||||||
)
|
|
||||||
} ?: emptyList()
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitMediaGroupMessages(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
) = buildMediaGroupMessagesWaiter<MediaGroupPartContent>(initRequest, errorFactory)
|
|
||||||
suspend fun BehaviourContext.waitPlaylistMessages(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
) = buildMediaGroupMessagesWaiter<AudioMediaGroupPartContent>(initRequest, errorFactory)
|
|
||||||
suspend fun BehaviourContext.waitDocumentsGroupMessages(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
) = buildMediaGroupMessagesWaiter<DocumentMediaGroupPartContent>(initRequest, errorFactory)
|
|
||||||
suspend fun BehaviourContext.waitVisualGalleryMessages(
|
|
||||||
initRequest: Request<*>? = null,
|
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
|
||||||
) = buildMediaGroupMessagesWaiter<VisualMediaGroupPartContent>(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)
|
|
@ -3,18 +3,13 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.filters
|
|||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.*
|
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.MediaGroupMessage
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
|
|
||||||
/**
|
|
||||||
* Allow only messages which are not [MediaGroupMessage]
|
|
||||||
*/
|
|
||||||
val MessageFilterExcludingMediaGroups: BehaviourContextAndTwoTypesReceiver<Boolean, CommonMessage<*>, Update> = { _, update ->
|
|
||||||
update !is MediaGroupMessage<*>
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow only messages which are not [MediaGroupMessage]
|
* Allow only messages which are not [MediaGroupMessage]
|
||||||
*/
|
*/
|
||||||
val CommonMessageFilterExcludeMediaGroups = SimpleFilter<Message> {
|
val CommonMessageFilterExcludeMediaGroups = SimpleFilter<Message> {
|
||||||
it !is MediaGroupMessage<*>
|
it !is CommonMessage<*> || it.content !is MediaGroupContent
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ 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.update.abstracts.BaseSentMessageUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
|
||||||
|
|
||||||
typealias CommonMessageFilter<T> = SimpleFilter<CommonMessage<T>>
|
typealias CommonMessageFilter<T> = SimpleFilter<CommonMessage<T>>
|
||||||
|
|
||||||
@ -26,7 +25,6 @@ internal suspend inline fun <BC : BehaviourContext, reified T : MessageContent>
|
|||||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||||
when (it) {
|
when (it) {
|
||||||
is BaseSentMessageUpdate -> it.data.whenCommonMessage(::listOfNotNull)
|
is BaseSentMessageUpdate -> it.data.whenCommonMessage(::listOfNotNull)
|
||||||
is SentMediaGroupUpdate -> it.data
|
|
||||||
else -> null
|
else -> null
|
||||||
} ?.mapNotNull { message ->
|
} ?.mapNotNull { message ->
|
||||||
if (message.content is T) message as CommonMessage<T> else null
|
if (message.content is T) message as CommonMessage<T> else null
|
||||||
|
@ -1,160 +0,0 @@
|
|||||||
@file:Suppress("unused")
|
|
||||||
|
|
||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessagesFilterByChat
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMediaGroupMarkerFactory
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.sentMediaGroupUpdateOrNull
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.*
|
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
|
||||||
import dev.inmo.tgbotapi.utils.PreviewFeature
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
internal suspend inline fun <BC : BehaviourContext, reified T : MediaGroupPartContent> BC.buildMediaGroupTrigger(
|
|
||||||
initialFilter: SimpleFilter<List<MediaGroupMessage<T>>>? = null,
|
|
||||||
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<T>>, Update>? = MessagesFilterByChat,
|
|
||||||
markerFactory: MarkerFactory<in List<MediaGroupMessage<T>>, Any> = ByChatMediaGroupMarkerFactory,
|
|
||||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<T>>>
|
|
||||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
|
||||||
(it.sentMediaGroupUpdateOrNull() ?.data ?.takeIf { messages ->
|
|
||||||
messages.all { message ->
|
|
||||||
message.content is T
|
|
||||||
}
|
|
||||||
} as? List<MediaGroupMessage<T>>) ?.let(::listOfNotNull)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
|
||||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
|
||||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
|
||||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
|
||||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
|
||||||
* to combinate several filters
|
|
||||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
|
||||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
|
||||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
|
||||||
* data
|
|
||||||
*/
|
|
||||||
suspend fun <BC : BehaviourContext> BC.onMediaGroup(
|
|
||||||
initialFilter: SimpleFilter<List<MediaGroupMessage<MediaGroupPartContent>>>? = null,
|
|
||||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<MediaGroupPartContent>>, Update>? = MessagesFilterByChat,
|
|
||||||
markerFactory: MarkerFactory<in List<MediaGroupMessage<MediaGroupPartContent>>, Any> = ByChatMediaGroupMarkerFactory,
|
|
||||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<MediaGroupPartContent>>>
|
|
||||||
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
|
||||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
|
||||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
|
||||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
|
||||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
|
||||||
* to combinate several filters
|
|
||||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
|
||||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
|
||||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
|
||||||
* data
|
|
||||||
*/
|
|
||||||
suspend fun <BC : BehaviourContext> BC.onPlaylist(
|
|
||||||
initialFilter: SimpleFilter<List<MediaGroupMessage<AudioMediaGroupPartContent>>>? = null,
|
|
||||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<AudioMediaGroupPartContent>>, Update>? = MessagesFilterByChat,
|
|
||||||
markerFactory: MarkerFactory<in List<MediaGroupMessage<AudioMediaGroupPartContent>>, Any> = ByChatMediaGroupMarkerFactory,
|
|
||||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<AudioMediaGroupPartContent>>>
|
|
||||||
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
|
||||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
|
||||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
|
||||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
|
||||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
|
||||||
* to combinate several filters
|
|
||||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
|
||||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
|
||||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
|
||||||
* data
|
|
||||||
*/
|
|
||||||
suspend fun <BC : BehaviourContext> BC.onDocumentsGroup(
|
|
||||||
initialFilter: SimpleFilter<List<MediaGroupMessage<DocumentMediaGroupPartContent>>>? = null,
|
|
||||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<DocumentMediaGroupPartContent>>, Update>? = MessagesFilterByChat,
|
|
||||||
markerFactory: MarkerFactory<in List<MediaGroupMessage<DocumentMediaGroupPartContent>>, Any> = ByChatMediaGroupMarkerFactory,
|
|
||||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<DocumentMediaGroupPartContent>>>
|
|
||||||
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
|
||||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
|
||||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
|
||||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
|
||||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
|
||||||
* to combinate several filters
|
|
||||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
|
||||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
|
||||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
|
||||||
* data
|
|
||||||
*/
|
|
||||||
suspend fun <BC : BehaviourContext> BC.onVisualGallery(
|
|
||||||
initialFilter: SimpleFilter<List<MediaGroupMessage<VisualMediaGroupPartContent>>>? = null,
|
|
||||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<VisualMediaGroupPartContent>>, Update>? = MessagesFilterByChat,
|
|
||||||
markerFactory: MarkerFactory<in List<MediaGroupMessage<VisualMediaGroupPartContent>>, Any> = ByChatMediaGroupMarkerFactory,
|
|
||||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<VisualMediaGroupPartContent>>>
|
|
||||||
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
|
||||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
|
||||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
|
||||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
|
||||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
|
||||||
* to combinate several filters
|
|
||||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
|
||||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
|
||||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
|
||||||
* data
|
|
||||||
*/
|
|
||||||
suspend fun <BC : BehaviourContext> BC.onVisualMediaGroup(
|
|
||||||
initialFilter: SimpleFilter<List<MediaGroupMessage<VisualMediaGroupPartContent>>>? = null,
|
|
||||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<VisualMediaGroupPartContent>>, Update>? = MessagesFilterByChat,
|
|
||||||
markerFactory: MarkerFactory<in List<MediaGroupMessage<VisualMediaGroupPartContent>>, Any> = ByChatMediaGroupMarkerFactory,
|
|
||||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<VisualMediaGroupPartContent>>>
|
|
||||||
) = onVisualGallery(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
|
||||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
|
||||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
|
||||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
|
||||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
|
||||||
* to combinate several filters
|
|
||||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
|
||||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
|
||||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
|
||||||
* data
|
|
||||||
*/
|
|
||||||
suspend fun <BC : BehaviourContext> BC.onPhotoGallery(
|
|
||||||
initialFilter: SimpleFilter<List<MediaGroupMessage<PhotoContent>>>? = null,
|
|
||||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<PhotoContent>>, Update>? = MessagesFilterByChat,
|
|
||||||
markerFactory: MarkerFactory<in List<MediaGroupMessage<PhotoContent>>, Any> = ByChatMediaGroupMarkerFactory,
|
|
||||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<PhotoContent>>>
|
|
||||||
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
|
||||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
|
||||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
|
||||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
|
||||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
|
||||||
* to combinate several filters
|
|
||||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
|
||||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
|
||||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
|
||||||
* data
|
|
||||||
*/
|
|
||||||
suspend fun <BC : BehaviourContext> BC.onVideoGallery(
|
|
||||||
initialFilter: SimpleFilter<List<MediaGroupMessage<VideoContent>>>? = null,
|
|
||||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<VideoContent>>, Update>? = MessagesFilterByChat,
|
|
||||||
markerFactory: MarkerFactory<in List<MediaGroupMessage<VideoContent>>, Any> = ByChatMediaGroupMarkerFactory,
|
|
||||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<VideoContent>>>
|
|
||||||
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
|
@ -1,7 +0,0 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
|
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat
|
|
||||||
|
|
||||||
object ByChatMediaGroupMarkerFactory : MarkerFactory<List<MediaGroupMessage<*>>, Any> {
|
|
||||||
override suspend fun invoke(data: List<MediaGroupMessage<*>>) = data.chat ?: error("Data must not be empty")
|
|
||||||
}
|
|
@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.requests.send.media.SendMediaGroup
|
|||||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||||
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
|
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
|
||||||
import dev.inmo.tgbotapi.types.MessageId
|
import dev.inmo.tgbotapi.types.MessageId
|
||||||
|
import dev.inmo.tgbotapi.types.MessageThreadId
|
||||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||||
import dev.inmo.tgbotapi.types.files.TelegramMediaFile
|
import dev.inmo.tgbotapi.types.files.TelegramMediaFile
|
||||||
import dev.inmo.tgbotapi.types.media.TelegramMedia
|
import dev.inmo.tgbotapi.types.media.TelegramMedia
|
||||||
@ -31,6 +32,7 @@ data class MediaGroupContent(
|
|||||||
|
|
||||||
override fun createResend(
|
override fun createResend(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
|
threadId: MessageThreadId?,
|
||||||
disableNotification: Boolean,
|
disableNotification: Boolean,
|
||||||
protectContent: Boolean,
|
protectContent: Boolean,
|
||||||
replyToMessageId: MessageId?,
|
replyToMessageId: MessageId?,
|
||||||
@ -39,10 +41,10 @@ data class MediaGroupContent(
|
|||||||
): Request<out Message> = SendMediaGroup<MediaGroupPartContent>(
|
): Request<out Message> = SendMediaGroup<MediaGroupPartContent>(
|
||||||
chatId,
|
chatId,
|
||||||
group.map { it.content.toMediaGroupMemberTelegramMedia() },
|
group.map { it.content.toMediaGroupMemberTelegramMedia() },
|
||||||
|
threadId,
|
||||||
disableNotification,
|
disableNotification,
|
||||||
protectContent,
|
protectContent,
|
||||||
replyToMessageId,
|
replyToMessageId,
|
||||||
allowSendingWithoutReply,
|
allowSendingWithoutReply
|
||||||
replyMarkup
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ typealias VideoNoteMessage = CommonMessage<VideoNoteContent>
|
|||||||
typealias StickerMessage = CommonMessage<StickerContent>
|
typealias StickerMessage = CommonMessage<StickerContent>
|
||||||
typealias TextedMediaMessage = CommonMessage<TextedMediaContent>
|
typealias TextedMediaMessage = CommonMessage<TextedMediaContent>
|
||||||
typealias VoiceMessage = CommonMessage<VoiceContent>
|
typealias VoiceMessage = CommonMessage<VoiceContent>
|
||||||
typealias MediaGroupMessage = CommonMessage<MediaGroupPartContent>
|
typealias MediaGroupMessage = CommonMessage<MediaGroupContent>
|
||||||
typealias AudioMediaGroupMessage = CommonMessage<AudioMediaGroupPartContent>
|
typealias AudioMediaGroupMessage = CommonMessage<AudioMediaGroupPartContent>
|
||||||
typealias AudioMessage = CommonMessage<AudioContent>
|
typealias AudioMessage = CommonMessage<AudioContent>
|
||||||
typealias DocumentMediaGroupMessage = CommonMessage<DocumentMediaGroupPartContent>
|
typealias DocumentMediaGroupMessage = CommonMessage<DocumentMediaGroupPartContent>
|
||||||
|
@ -2,10 +2,11 @@ package dev.inmo.tgbotapi.updateshandlers
|
|||||||
|
|
||||||
import dev.inmo.micro_utils.coroutines.plus
|
import dev.inmo.micro_utils.coroutines.plus
|
||||||
import dev.inmo.tgbotapi.types.ALL_UPDATES_LIST
|
import dev.inmo.tgbotapi.types.ALL_UPDATES_LIST
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage
|
||||||
import dev.inmo.tgbotapi.types.update.*
|
import dev.inmo.tgbotapi.types.update.*
|
||||||
|
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.UnknownUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.UnknownUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.*
|
|
||||||
import kotlinx.coroutines.channels.*
|
import kotlinx.coroutines.channels.*
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
|
|
||||||
@ -13,16 +14,22 @@ interface FlowsUpdatesFilter : UpdatesFilter {
|
|||||||
override val allowedUpdates: List<String>
|
override val allowedUpdates: List<String>
|
||||||
get() = ALL_UPDATES_LIST
|
get() = ALL_UPDATES_LIST
|
||||||
val allUpdatesFlow: Flow<Update>
|
val allUpdatesFlow: Flow<Update>
|
||||||
|
@Deprecated("Since 4.0.0 is not actual", ReplaceWith("allUpdatesFlow"))
|
||||||
val allUpdatesWithoutMediaGroupsGroupingFlow: Flow<Update>
|
val allUpdatesWithoutMediaGroupsGroupingFlow: Flow<Update>
|
||||||
|
get() = allUpdatesFlow
|
||||||
|
|
||||||
val messagesFlow: Flow<MessageUpdate>
|
val messagesFlow: Flow<MessageUpdate>
|
||||||
val messageMediaGroupsFlow: Flow<MessageMediaGroupUpdate>
|
val messageMediaGroupsFlow: Flow<MessageUpdate>
|
||||||
|
get() = messagesFlow.filter { (it.data as? PossiblySentViaBotCommonMessage<*>) ?.mediaGroupId != null }
|
||||||
val editedMessagesFlow: Flow<EditMessageUpdate>
|
val editedMessagesFlow: Flow<EditMessageUpdate>
|
||||||
val editedMessageMediaGroupsFlow: Flow<EditMessageMediaGroupUpdate>
|
val editedMessageMediaGroupsFlow: Flow<EditMessageUpdate>
|
||||||
|
get() = editedMessagesFlow.filter { (it.data as? PossiblySentViaBotCommonMessage<*>) ?.mediaGroupId != null }
|
||||||
val channelPostsFlow: Flow<ChannelPostUpdate>
|
val channelPostsFlow: Flow<ChannelPostUpdate>
|
||||||
val channelPostMediaGroupsFlow: Flow<ChannelPostMediaGroupUpdate>
|
val channelPostMediaGroupsFlow: Flow<ChannelPostUpdate>
|
||||||
|
get() = channelPostsFlow.filter { (it.data as? PossiblySentViaBotCommonMessage<*>) ?.mediaGroupId != null }
|
||||||
val editedChannelPostsFlow: Flow<EditChannelPostUpdate>
|
val editedChannelPostsFlow: Flow<EditChannelPostUpdate>
|
||||||
val editedChannelPostMediaGroupsFlow: Flow<EditChannelPostMediaGroupUpdate>
|
val editedChannelPostMediaGroupsFlow: Flow<EditChannelPostUpdate>
|
||||||
|
get() = editedChannelPostsFlow.filter { (it.data as? PossiblySentViaBotCommonMessage<*>) ?.mediaGroupId != null }
|
||||||
val chosenInlineResultsFlow: Flow<ChosenInlineResultUpdate>
|
val chosenInlineResultsFlow: Flow<ChosenInlineResultUpdate>
|
||||||
val inlineQueriesFlow: Flow<InlineQueryUpdate>
|
val inlineQueriesFlow: Flow<InlineQueryUpdate>
|
||||||
val callbackQueriesFlow: Flow<CallbackQueryUpdate>
|
val callbackQueriesFlow: Flow<CallbackQueryUpdate>
|
||||||
@ -37,23 +44,10 @@ interface FlowsUpdatesFilter : UpdatesFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract class AbstractFlowsUpdatesFilter : FlowsUpdatesFilter {
|
abstract class AbstractFlowsUpdatesFilter : FlowsUpdatesFilter {
|
||||||
override val allUpdatesWithoutMediaGroupsGroupingFlow: Flow<Update>
|
|
||||||
get() = allUpdatesFlow.flatMapConcat {
|
|
||||||
when (it) {
|
|
||||||
is SentMediaGroupUpdate -> it.origins.asFlow()
|
|
||||||
is EditMediaGroupUpdate -> flowOf(it.origin)
|
|
||||||
else -> flowOf(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override val messagesFlow: Flow<MessageUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
override val messagesFlow: Flow<MessageUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
||||||
override val messageMediaGroupsFlow: Flow<MessageMediaGroupUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
|
||||||
override val editedMessagesFlow: Flow<EditMessageUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
override val editedMessagesFlow: Flow<EditMessageUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
||||||
override val editedMessageMediaGroupsFlow: Flow<EditMessageMediaGroupUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
|
||||||
override val channelPostsFlow: Flow<ChannelPostUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
override val channelPostsFlow: Flow<ChannelPostUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
||||||
override val channelPostMediaGroupsFlow: Flow<ChannelPostMediaGroupUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
|
||||||
override val editedChannelPostsFlow: Flow<EditChannelPostUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
override val editedChannelPostsFlow: Flow<EditChannelPostUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
||||||
override val editedChannelPostMediaGroupsFlow: Flow<EditChannelPostMediaGroupUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
|
||||||
override val chosenInlineResultsFlow: Flow<ChosenInlineResultUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
override val chosenInlineResultsFlow: Flow<ChosenInlineResultUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
||||||
override val inlineQueriesFlow: Flow<InlineQueryUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
override val inlineQueriesFlow: Flow<InlineQueryUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
||||||
override val callbackQueriesFlow: Flow<CallbackQueryUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
override val callbackQueriesFlow: Flow<CallbackQueryUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
||||||
@ -92,14 +86,6 @@ class DefaultFlowsUpdatesFilter(
|
|||||||
it
|
it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Suppress("MemberVisibilityCanBePrivate")
|
|
||||||
override val allUpdatesWithoutMediaGroupsGroupingFlow: Flow<Update> = allUpdatesFlow.flatMapConcat {
|
|
||||||
when (it) {
|
|
||||||
is SentMediaGroupUpdate -> it.origins.asFlow()
|
|
||||||
is EditMediaGroupUpdate -> flowOf(it.origin)
|
|
||||||
else -> flowOf(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override val asUpdateReceiver: UpdateReceiver<Update> = additionalUpdatesSharedFlow::emit
|
override val asUpdateReceiver: UpdateReceiver<Update> = additionalUpdatesSharedFlow::emit
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.updateshandlers
|
package dev.inmo.tgbotapi.updateshandlers
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.types.*
|
|
||||||
import dev.inmo.tgbotapi.types.update.*
|
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.UnknownUpdate
|
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.*
|
|
||||||
|
|
||||||
typealias UpdateReceiver<T> = suspend (T) -> Unit
|
typealias UpdateReceiver<T> = suspend (T) -> Unit
|
||||||
|
|
||||||
@ -12,111 +8,3 @@ interface UpdatesFilter {
|
|||||||
val asUpdateReceiver: UpdateReceiver<Update>
|
val asUpdateReceiver: UpdateReceiver<Update>
|
||||||
val allowedUpdates: List<String>
|
val allowedUpdates: List<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
data class SimpleUpdatesFilter(
|
|
||||||
private val messageCallback: UpdateReceiver<MessageUpdate>? = null,
|
|
||||||
private val messageMediaGroupCallback: UpdateReceiver<MessageMediaGroupUpdate>? = null,
|
|
||||||
private val editedMessageCallback: UpdateReceiver<EditMessageUpdate>? = null,
|
|
||||||
private val editedMessageMediaGroupCallback: UpdateReceiver<EditMessageMediaGroupUpdate>? = null,
|
|
||||||
private val channelPostCallback: UpdateReceiver<ChannelPostUpdate>? = null,
|
|
||||||
private val channelPostMediaGroupCallback: UpdateReceiver<ChannelPostMediaGroupUpdate>? = null,
|
|
||||||
private val editedChannelPostCallback: UpdateReceiver<EditChannelPostUpdate>? = null,
|
|
||||||
private val editedChannelPostMediaGroupCallback: UpdateReceiver<EditChannelPostMediaGroupUpdate>? = null,
|
|
||||||
private val chosenInlineResultCallback: UpdateReceiver<ChosenInlineResultUpdate>? = null,
|
|
||||||
private val inlineQueryCallback: UpdateReceiver<InlineQueryUpdate>? = null,
|
|
||||||
private val callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null,
|
|
||||||
private val shippingQueryCallback: UpdateReceiver<ShippingQueryUpdate>? = null,
|
|
||||||
private val preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null,
|
|
||||||
private val pollUpdateCallback: UpdateReceiver<PollUpdate>? = null,
|
|
||||||
private val pollAnswerUpdateCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
|
||||||
private val unknownUpdateTypeCallback: UpdateReceiver<UnknownUpdate>? = null
|
|
||||||
) : UpdatesFilter {
|
|
||||||
override val asUpdateReceiver: UpdateReceiver<Update> = this::invoke
|
|
||||||
override val allowedUpdates = listOfNotNull(
|
|
||||||
(messageCallback ?: messageMediaGroupCallback) ?.let { UPDATE_MESSAGE },
|
|
||||||
(editedMessageCallback ?: editedMessageMediaGroupCallback) ?.let { UPDATE_EDITED_MESSAGE },
|
|
||||||
(channelPostCallback ?: channelPostMediaGroupCallback) ?.let { UPDATE_CHANNEL_POST },
|
|
||||||
(editedChannelPostCallback ?: editedChannelPostMediaGroupCallback) ?.let { UPDATE_EDITED_CHANNEL_POST },
|
|
||||||
chosenInlineResultCallback ?.let { UPDATE_CHOSEN_INLINE_RESULT },
|
|
||||||
inlineQueryCallback ?.let { UPDATE_INLINE_QUERY },
|
|
||||||
callbackQueryCallback ?.let { UPDATE_CALLBACK_QUERY },
|
|
||||||
shippingQueryCallback ?.let { UPDATE_SHIPPING_QUERY },
|
|
||||||
preCheckoutQueryCallback ?.let { UPDATE_PRE_CHECKOUT_QUERY },
|
|
||||||
pollUpdateCallback ?.let { UPDATE_POLL },
|
|
||||||
pollAnswerUpdateCallback ?.let { UPDATE_POLL_ANSWER }
|
|
||||||
)
|
|
||||||
|
|
||||||
suspend fun invoke(update: Update) {
|
|
||||||
when (update) {
|
|
||||||
is MessageUpdate -> messageCallback ?.invoke(update)
|
|
||||||
is MessageMediaGroupUpdate -> messageMediaGroupCallback ?.also { receiver ->
|
|
||||||
receiver(update)
|
|
||||||
} ?: messageCallback ?.also { receiver ->
|
|
||||||
update.origins.mapNotNull { it as? MessageUpdate }.forEach {
|
|
||||||
receiver(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is EditMessageUpdate -> editedMessageCallback ?.invoke(update)
|
|
||||||
is EditMessageMediaGroupUpdate -> editedMessageMediaGroupCallback ?.also { receiver ->
|
|
||||||
receiver(update)
|
|
||||||
} ?: editedMessageCallback ?.also { receiver ->
|
|
||||||
receiver(update.origin)
|
|
||||||
}
|
|
||||||
is ChannelPostUpdate -> channelPostCallback ?.invoke(update)
|
|
||||||
is ChannelPostMediaGroupUpdate -> channelPostMediaGroupCallback ?.also { receiver ->
|
|
||||||
receiver(update)
|
|
||||||
} ?: channelPostCallback ?.also { receiver ->
|
|
||||||
update.origins.mapNotNull { it as? ChannelPostUpdate }.forEach {
|
|
||||||
receiver(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is EditChannelPostUpdate -> editedChannelPostCallback ?.invoke(update)
|
|
||||||
is EditChannelPostMediaGroupUpdate -> editedChannelPostMediaGroupCallback ?.also { receiver ->
|
|
||||||
receiver(update)
|
|
||||||
} ?: editedChannelPostCallback ?.also { receiver ->
|
|
||||||
receiver(update.origin)
|
|
||||||
}
|
|
||||||
is ChosenInlineResultUpdate -> chosenInlineResultCallback ?.invoke(update)
|
|
||||||
is InlineQueryUpdate -> inlineQueryCallback ?.invoke(update)
|
|
||||||
is CallbackQueryUpdate -> callbackQueryCallback ?.invoke(update)
|
|
||||||
is ShippingQueryUpdate -> shippingQueryCallback ?.invoke(update)
|
|
||||||
is PreCheckoutQueryUpdate -> preCheckoutQueryCallback ?.invoke(update)
|
|
||||||
is PollUpdate -> pollUpdateCallback ?.invoke(update)
|
|
||||||
is PollAnswerUpdate -> pollAnswerUpdateCallback ?.invoke(update)
|
|
||||||
is UnknownUpdate -> unknownUpdateTypeCallback ?.invoke(update)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createSimpleUpdateFilter(
|
|
||||||
messageCallback: UpdateReceiver<MessageUpdate>? = null,
|
|
||||||
mediaGroupCallback: UpdateReceiver<MediaGroupUpdate>? = null,
|
|
||||||
editedMessageCallback: UpdateReceiver<EditMessageUpdate>? = null,
|
|
||||||
channelPostCallback: UpdateReceiver<ChannelPostUpdate>? = null,
|
|
||||||
editedChannelPostCallback: UpdateReceiver<EditChannelPostUpdate>? = null,
|
|
||||||
chosenInlineResultCallback: UpdateReceiver<ChosenInlineResultUpdate>? = null,
|
|
||||||
inlineQueryCallback: UpdateReceiver<InlineQueryUpdate>? = null,
|
|
||||||
callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null,
|
|
||||||
shippingQueryCallback: UpdateReceiver<ShippingQueryUpdate>? = null,
|
|
||||||
preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null,
|
|
||||||
pollCallback: UpdateReceiver<PollUpdate>? = null,
|
|
||||||
pollAnswerCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
|
||||||
unknownCallback: UpdateReceiver<UnknownUpdate>? = null
|
|
||||||
): UpdatesFilter = SimpleUpdatesFilter(
|
|
||||||
messageCallback = messageCallback,
|
|
||||||
messageMediaGroupCallback = mediaGroupCallback,
|
|
||||||
editedMessageCallback = editedMessageCallback,
|
|
||||||
editedMessageMediaGroupCallback = mediaGroupCallback,
|
|
||||||
channelPostCallback = channelPostCallback,
|
|
||||||
channelPostMediaGroupCallback = mediaGroupCallback,
|
|
||||||
editedChannelPostCallback = editedChannelPostCallback,
|
|
||||||
editedChannelPostMediaGroupCallback = mediaGroupCallback,
|
|
||||||
chosenInlineResultCallback = chosenInlineResultCallback,
|
|
||||||
inlineQueryCallback = inlineQueryCallback,
|
|
||||||
callbackQueryCallback = callbackQueryCallback,
|
|
||||||
shippingQueryCallback = shippingQueryCallback,
|
|
||||||
preCheckoutQueryCallback = preCheckoutQueryCallback,
|
|
||||||
pollUpdateCallback = pollCallback,
|
|
||||||
pollAnswerUpdateCallback = pollAnswerCallback,
|
|
||||||
unknownUpdateTypeCallback = unknownCallback
|
|
||||||
)
|
|
||||||
|
@ -46,7 +46,6 @@ import dev.inmo.tgbotapi.types.polls.*
|
|||||||
import dev.inmo.tgbotapi.types.queries.callback.*
|
import dev.inmo.tgbotapi.types.queries.callback.*
|
||||||
import dev.inmo.tgbotapi.types.update.*
|
import dev.inmo.tgbotapi.types.update.*
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.*
|
import dev.inmo.tgbotapi.types.update.abstracts.*
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.*
|
|
||||||
import dev.inmo.tgbotapi.utils.PreviewFeature
|
import dev.inmo.tgbotapi.utils.PreviewFeature
|
||||||
|
|
||||||
@PreviewFeature
|
@PreviewFeature
|
||||||
@ -1036,18 +1035,6 @@ inline fun Message.asChannelEventMessage(): ChannelEventMessage<ChannelEvent>? =
|
|||||||
inline fun Message.requireChannelEventMessage(): ChannelEventMessage<ChannelEvent> =
|
inline fun Message.requireChannelEventMessage(): ChannelEventMessage<ChannelEvent> =
|
||||||
this as ChannelEventMessage<ChannelEvent>
|
this as ChannelEventMessage<ChannelEvent>
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun <T> Message.whenChannelMediaGroupMessage(block: (ChannelMediaGroupMessage<MediaGroupPartContent>) -> T) =
|
|
||||||
asChannelMediaGroupMessage()?.let(block)
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun Message.asChannelMediaGroupMessage(): ChannelMediaGroupMessage<MediaGroupPartContent>? =
|
|
||||||
this as? ChannelMediaGroupMessage<MediaGroupPartContent>
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun Message.requireChannelMediaGroupMessage(): ChannelMediaGroupMessage<MediaGroupPartContent> =
|
|
||||||
this as ChannelMediaGroupMessage<MediaGroupPartContent>
|
|
||||||
|
|
||||||
@PreviewFeature
|
@PreviewFeature
|
||||||
inline fun <T> Message.whenCommonGroupEventMessage(block: (CommonGroupEventMessage<GroupEvent>) -> T) =
|
inline fun <T> Message.whenCommonGroupEventMessage(block: (CommonGroupEventMessage<GroupEvent>) -> T) =
|
||||||
asCommonGroupEventMessage()?.let(block)
|
asCommonGroupEventMessage()?.let(block)
|
||||||
@ -1060,18 +1047,6 @@ inline fun Message.asCommonGroupEventMessage(): CommonGroupEventMessage<GroupEve
|
|||||||
inline fun Message.requireCommonGroupEventMessage(): CommonGroupEventMessage<GroupEvent> =
|
inline fun Message.requireCommonGroupEventMessage(): CommonGroupEventMessage<GroupEvent> =
|
||||||
this as CommonGroupEventMessage<GroupEvent>
|
this as CommonGroupEventMessage<GroupEvent>
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun <T> Message.whenCommonMediaGroupMessage(block: (CommonMediaGroupMessage<MediaGroupPartContent>) -> T) =
|
|
||||||
asCommonMediaGroupMessage()?.let(block)
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun Message.asCommonMediaGroupMessage(): CommonMediaGroupMessage<MediaGroupPartContent>? =
|
|
||||||
this as? CommonMediaGroupMessage<MediaGroupPartContent>
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun Message.requireCommonMediaGroupMessage(): CommonMediaGroupMessage<MediaGroupPartContent> =
|
|
||||||
this as CommonMediaGroupMessage<MediaGroupPartContent>
|
|
||||||
|
|
||||||
@PreviewFeature
|
@PreviewFeature
|
||||||
inline fun <T> Message.whenCommonSupergroupEventMessage(block: (CommonSupergroupEventMessage<SupergroupEvent>) -> T) =
|
inline fun <T> Message.whenCommonSupergroupEventMessage(block: (CommonSupergroupEventMessage<SupergroupEvent>) -> T) =
|
||||||
asCommonSupergroupEventMessage()?.let(block)
|
asCommonSupergroupEventMessage()?.let(block)
|
||||||
@ -1219,16 +1194,16 @@ inline fun Message.requireGroupContentMessage(): GroupContentMessage<MessageCont
|
|||||||
this as GroupContentMessage<MessageContent>
|
this as GroupContentMessage<MessageContent>
|
||||||
|
|
||||||
@PreviewFeature
|
@PreviewFeature
|
||||||
inline fun <T> Message.whenMediaGroupMessage(block: (MediaGroupMessage<MediaGroupPartContent>) -> T) =
|
inline fun <T> Message.whenMediaGroupMessage(block: (MediaGroupMessage) -> T) =
|
||||||
asMediaGroupMessage()?.let(block)
|
asMediaGroupMessage()?.let(block)
|
||||||
|
|
||||||
@PreviewFeature
|
@PreviewFeature
|
||||||
inline fun Message.asMediaGroupMessage(): MediaGroupMessage<MediaGroupPartContent>? =
|
inline fun Message.asMediaGroupMessage(): MediaGroupMessage? =
|
||||||
this as? MediaGroupMessage<MediaGroupPartContent>
|
this as? MediaGroupMessage
|
||||||
|
|
||||||
@PreviewFeature
|
@PreviewFeature
|
||||||
inline fun Message.requireMediaGroupMessage(): MediaGroupMessage<MediaGroupPartContent> =
|
inline fun Message.requireMediaGroupMessage(): MediaGroupMessage =
|
||||||
this as MediaGroupMessage<MediaGroupPartContent>
|
this as MediaGroupMessage
|
||||||
|
|
||||||
@PreviewFeature
|
@PreviewFeature
|
||||||
inline fun <T> Message.whenPossiblyEditedMessage(block: (PossiblyEditedMessage) -> T) =
|
inline fun <T> Message.whenPossiblyEditedMessage(block: (PossiblyEditedMessage) -> T) =
|
||||||
@ -2218,79 +2193,6 @@ inline fun Update.asInlineQueryUpdate(): InlineQueryUpdate? = this as? InlineQue
|
|||||||
@PreviewFeature
|
@PreviewFeature
|
||||||
inline fun Update.requireInlineQueryUpdate(): InlineQueryUpdate = this as InlineQueryUpdate
|
inline fun Update.requireInlineQueryUpdate(): InlineQueryUpdate = this as InlineQueryUpdate
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun <T> Update.whenChannelPostMediaGroupUpdate(block: (ChannelPostMediaGroupUpdate) -> T) =
|
|
||||||
asChannelPostMediaGroupUpdate()?.let(block)
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun Update.asChannelPostMediaGroupUpdate(): ChannelPostMediaGroupUpdate? = this as? ChannelPostMediaGroupUpdate
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun Update.requireChannelPostMediaGroupUpdate(): ChannelPostMediaGroupUpdate =
|
|
||||||
this as ChannelPostMediaGroupUpdate
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun <T> Update.whenEditChannelPostMediaGroupUpdate(block: (EditChannelPostMediaGroupUpdate) -> T) =
|
|
||||||
asEditChannelPostMediaGroupUpdate()?.let(block)
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun Update.asEditChannelPostMediaGroupUpdate(): EditChannelPostMediaGroupUpdate? =
|
|
||||||
this as? EditChannelPostMediaGroupUpdate
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun Update.requireEditChannelPostMediaGroupUpdate(): EditChannelPostMediaGroupUpdate =
|
|
||||||
this as EditChannelPostMediaGroupUpdate
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun <T> Update.whenEditMediaGroupUpdate(block: (EditMediaGroupUpdate) -> T) =
|
|
||||||
asEditMediaGroupUpdate()?.let(block)
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun Update.asEditMediaGroupUpdate(): EditMediaGroupUpdate? = this as? EditMediaGroupUpdate
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun Update.requireEditMediaGroupUpdate(): EditMediaGroupUpdate = this as EditMediaGroupUpdate
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun <T> Update.whenEditMessageMediaGroupUpdate(block: (EditMessageMediaGroupUpdate) -> T) =
|
|
||||||
asEditMessageMediaGroupUpdate()?.let(block)
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun Update.asEditMessageMediaGroupUpdate(): EditMessageMediaGroupUpdate? = this as? EditMessageMediaGroupUpdate
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun Update.requireEditMessageMediaGroupUpdate(): EditMessageMediaGroupUpdate =
|
|
||||||
this as EditMessageMediaGroupUpdate
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun <T> Update.whenMediaGroupUpdate(block: (MediaGroupUpdate) -> T) = asMediaGroupUpdate()?.let(block)
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun Update.asMediaGroupUpdate(): MediaGroupUpdate? = this as? MediaGroupUpdate
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun Update.requireMediaGroupUpdate(): MediaGroupUpdate = this as MediaGroupUpdate
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun <T> Update.whenMessageMediaGroupUpdate(block: (MessageMediaGroupUpdate) -> T) =
|
|
||||||
asMessageMediaGroupUpdate()?.let(block)
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun Update.asMessageMediaGroupUpdate(): MessageMediaGroupUpdate? = this as? MessageMediaGroupUpdate
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun Update.requireMessageMediaGroupUpdate(): MessageMediaGroupUpdate = this as MessageMediaGroupUpdate
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun <T> Update.whenSentMediaGroupUpdate(block: (SentMediaGroupUpdate) -> T) =
|
|
||||||
asSentMediaGroupUpdate()?.let(block)
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun Update.asSentMediaGroupUpdate(): SentMediaGroupUpdate? = this as? SentMediaGroupUpdate
|
|
||||||
|
|
||||||
@PreviewFeature
|
|
||||||
inline fun Update.requireSentMediaGroupUpdate(): SentMediaGroupUpdate = this as SentMediaGroupUpdate
|
|
||||||
|
|
||||||
@PreviewFeature
|
@PreviewFeature
|
||||||
inline fun <T> Update.whenMessageUpdate(block: (MessageUpdate) -> T) = asMessageUpdate()?.let(block)
|
inline fun <T> Update.whenMessageUpdate(block: (MessageUpdate) -> T) = asMessageUpdate()?.let(block)
|
||||||
|
|
||||||
|
@ -280,8 +280,10 @@ import dev.inmo.tgbotapi.types.message.abstracts.GroupEventMessage
|
|||||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyEditedMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyEditedMessage
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyForwardedMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyForwardedMessage
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyMediaGroupMessage
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyPaymentMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyPaymentMessage
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyTopicMessage
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.PublicContentMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.PublicContentMessage
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.SignedMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.SignedMessage
|
||||||
@ -301,6 +303,8 @@ import dev.inmo.tgbotapi.types.message.content.LiveLocationContent
|
|||||||
import dev.inmo.tgbotapi.types.message.content.LocationContent
|
import dev.inmo.tgbotapi.types.message.content.LocationContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.MediaCollectionContent
|
import dev.inmo.tgbotapi.types.message.content.MediaCollectionContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.MediaContent
|
import dev.inmo.tgbotapi.types.message.content.MediaContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.MediaGroupCollectionContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
|
import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.MessageContent
|
import dev.inmo.tgbotapi.types.message.content.MessageContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.PhotoContent
|
import dev.inmo.tgbotapi.types.message.content.PhotoContent
|
||||||
@ -438,13 +442,6 @@ import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
|||||||
import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.UnknownUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.UnknownUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.ChannelPostMediaGroupUpdate
|
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.EditChannelPostMediaGroupUpdate
|
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.EditMediaGroupUpdate
|
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.EditMessageMediaGroupUpdate
|
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.MediaGroupUpdate
|
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.MessageMediaGroupUpdate
|
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
|
||||||
import kotlin.Suppress
|
import kotlin.Suppress
|
||||||
|
|
||||||
public inline fun CommonSendInvoiceData.createInvoiceLinkOrNull(): CreateInvoiceLink? = this as?
|
public inline fun CommonSendInvoiceData.createInvoiceLinkOrNull(): CreateInvoiceLink? = this as?
|
||||||
@ -738,18 +735,6 @@ public inline fun <T>
|
|||||||
WithUser.ifCommonGroupEventMessage(block: (CommonGroupEventMessage<GroupEvent>) -> T): T? =
|
WithUser.ifCommonGroupEventMessage(block: (CommonGroupEventMessage<GroupEvent>) -> T): T? =
|
||||||
commonGroupEventMessageOrNull() ?.let(block)
|
commonGroupEventMessageOrNull() ?.let(block)
|
||||||
|
|
||||||
public inline fun WithUser.commonMediaGroupMessageOrNull():
|
|
||||||
CommonMediaGroupMessage<MediaGroupPartContent>? = this as?
|
|
||||||
dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
|
|
||||||
|
|
||||||
public inline fun WithUser.commonMediaGroupMessageOrThrow():
|
|
||||||
CommonMediaGroupMessage<MediaGroupPartContent> = this as
|
|
||||||
dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
|
|
||||||
|
|
||||||
public inline fun <T>
|
|
||||||
WithUser.ifCommonMediaGroupMessage(block: (CommonMediaGroupMessage<MediaGroupPartContent>) -> T): T?
|
|
||||||
= commonMediaGroupMessageOrNull() ?.let(block)
|
|
||||||
|
|
||||||
public inline fun WithUser.commonSupergroupEventMessageOrNull():
|
public inline fun WithUser.commonSupergroupEventMessageOrNull():
|
||||||
CommonSupergroupEventMessage<SupergroupEvent>? = this as?
|
CommonSupergroupEventMessage<SupergroupEvent>? = this as?
|
||||||
dev.inmo.tgbotapi.types.message.CommonSupergroupEventMessage<dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent>
|
dev.inmo.tgbotapi.types.message.CommonSupergroupEventMessage<dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent>
|
||||||
@ -3032,18 +3017,6 @@ public inline fun <T>
|
|||||||
Message.ifChannelEventMessage(block: (ChannelEventMessage<ChannelEvent>) -> T): T? =
|
Message.ifChannelEventMessage(block: (ChannelEventMessage<ChannelEvent>) -> T): T? =
|
||||||
channelEventMessageOrNull() ?.let(block)
|
channelEventMessageOrNull() ?.let(block)
|
||||||
|
|
||||||
public inline fun Message.channelMediaGroupMessageOrNull():
|
|
||||||
ChannelMediaGroupMessage<MediaGroupPartContent>? = this as?
|
|
||||||
dev.inmo.tgbotapi.types.message.ChannelMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
|
|
||||||
|
|
||||||
public inline fun Message.channelMediaGroupMessageOrThrow():
|
|
||||||
ChannelMediaGroupMessage<MediaGroupPartContent> = this as
|
|
||||||
dev.inmo.tgbotapi.types.message.ChannelMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
|
|
||||||
|
|
||||||
public inline fun <T>
|
|
||||||
Message.ifChannelMediaGroupMessage(block: (ChannelMediaGroupMessage<MediaGroupPartContent>) -> T):
|
|
||||||
T? = channelMediaGroupMessageOrNull() ?.let(block)
|
|
||||||
|
|
||||||
public inline fun Message.commonGroupEventMessageOrNull(): CommonGroupEventMessage<GroupEvent>? =
|
public inline fun Message.commonGroupEventMessageOrNull(): CommonGroupEventMessage<GroupEvent>? =
|
||||||
this as?
|
this as?
|
||||||
dev.inmo.tgbotapi.types.message.CommonGroupEventMessage<dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent>
|
dev.inmo.tgbotapi.types.message.CommonGroupEventMessage<dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent>
|
||||||
@ -3056,18 +3029,6 @@ public inline fun <T>
|
|||||||
Message.ifCommonGroupEventMessage(block: (CommonGroupEventMessage<GroupEvent>) -> T): T? =
|
Message.ifCommonGroupEventMessage(block: (CommonGroupEventMessage<GroupEvent>) -> T): T? =
|
||||||
commonGroupEventMessageOrNull() ?.let(block)
|
commonGroupEventMessageOrNull() ?.let(block)
|
||||||
|
|
||||||
public inline fun Message.commonMediaGroupMessageOrNull():
|
|
||||||
CommonMediaGroupMessage<MediaGroupPartContent>? = this as?
|
|
||||||
dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
|
|
||||||
|
|
||||||
public inline fun Message.commonMediaGroupMessageOrThrow():
|
|
||||||
CommonMediaGroupMessage<MediaGroupPartContent> = this as
|
|
||||||
dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
|
|
||||||
|
|
||||||
public inline fun <T>
|
|
||||||
Message.ifCommonMediaGroupMessage(block: (CommonMediaGroupMessage<MediaGroupPartContent>) -> T): T?
|
|
||||||
= commonMediaGroupMessageOrNull() ?.let(block)
|
|
||||||
|
|
||||||
public inline fun Message.commonSupergroupEventMessageOrNull():
|
public inline fun Message.commonSupergroupEventMessageOrNull():
|
||||||
CommonSupergroupEventMessage<SupergroupEvent>? = this as?
|
CommonSupergroupEventMessage<SupergroupEvent>? = this as?
|
||||||
dev.inmo.tgbotapi.types.message.CommonSupergroupEventMessage<dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent>
|
dev.inmo.tgbotapi.types.message.CommonSupergroupEventMessage<dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent>
|
||||||
@ -3372,17 +3333,6 @@ public inline fun <T>
|
|||||||
Message.ifCommonForumContentMessage(block: (CommonForumContentMessage<MessageContent>) -> T): T?
|
Message.ifCommonForumContentMessage(block: (CommonForumContentMessage<MessageContent>) -> T): T?
|
||||||
= commonForumContentMessageOrNull() ?.let(block)
|
= commonForumContentMessageOrNull() ?.let(block)
|
||||||
|
|
||||||
public inline fun Message.mediaGroupMessageOrNull(): MediaGroupMessage<MediaGroupPartContent>? = this
|
|
||||||
as?
|
|
||||||
dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
|
|
||||||
|
|
||||||
public inline fun Message.mediaGroupMessageOrThrow(): MediaGroupMessage<MediaGroupPartContent> = this as
|
|
||||||
dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
|
|
||||||
|
|
||||||
public inline fun <T>
|
|
||||||
Message.ifMediaGroupMessage(block: (MediaGroupMessage<MediaGroupPartContent>) -> T): T? =
|
|
||||||
mediaGroupMessageOrNull() ?.let(block)
|
|
||||||
|
|
||||||
public inline fun Message.unknownMessageTypeOrNull(): UnknownMessageType? = this as?
|
public inline fun Message.unknownMessageTypeOrNull(): UnknownMessageType? = this as?
|
||||||
dev.inmo.tgbotapi.types.message.abstracts.UnknownMessageType
|
dev.inmo.tgbotapi.types.message.abstracts.UnknownMessageType
|
||||||
|
|
||||||
@ -3410,6 +3360,18 @@ public inline fun Message.possiblyForwardedMessageOrThrow(): PossiblyForwardedMe
|
|||||||
public inline fun <T> Message.ifPossiblyForwardedMessage(block: (PossiblyForwardedMessage) -> T): T?
|
public inline fun <T> Message.ifPossiblyForwardedMessage(block: (PossiblyForwardedMessage) -> T): T?
|
||||||
= possiblyForwardedMessageOrNull() ?.let(block)
|
= possiblyForwardedMessageOrNull() ?.let(block)
|
||||||
|
|
||||||
|
public inline fun Message.possiblyMediaGroupMessageOrNull():
|
||||||
|
PossiblyMediaGroupMessage<MessageContent>? = this as?
|
||||||
|
dev.inmo.tgbotapi.types.message.abstracts.PossiblyMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MessageContent>
|
||||||
|
|
||||||
|
public inline fun Message.possiblyMediaGroupMessageOrThrow():
|
||||||
|
PossiblyMediaGroupMessage<MessageContent> = this as
|
||||||
|
dev.inmo.tgbotapi.types.message.abstracts.PossiblyMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MessageContent>
|
||||||
|
|
||||||
|
public inline fun <T>
|
||||||
|
Message.ifPossiblyMediaGroupMessage(block: (PossiblyMediaGroupMessage<MessageContent>) -> T): T?
|
||||||
|
= possiblyMediaGroupMessageOrNull() ?.let(block)
|
||||||
|
|
||||||
public inline fun Message.possiblyPaymentMessageOrNull(): PossiblyPaymentMessage? = this as?
|
public inline fun Message.possiblyPaymentMessageOrNull(): PossiblyPaymentMessage? = this as?
|
||||||
dev.inmo.tgbotapi.types.message.abstracts.PossiblyPaymentMessage
|
dev.inmo.tgbotapi.types.message.abstracts.PossiblyPaymentMessage
|
||||||
|
|
||||||
@ -3431,6 +3393,15 @@ public inline fun <T>
|
|||||||
Message.ifPossiblySentViaBotCommonMessage(block: (PossiblySentViaBotCommonMessage<MessageContent>) -> T):
|
Message.ifPossiblySentViaBotCommonMessage(block: (PossiblySentViaBotCommonMessage<MessageContent>) -> T):
|
||||||
T? = possiblySentViaBotCommonMessageOrNull() ?.let(block)
|
T? = possiblySentViaBotCommonMessageOrNull() ?.let(block)
|
||||||
|
|
||||||
|
public inline fun Message.possiblyTopicMessageOrNull(): PossiblyTopicMessage? = this as?
|
||||||
|
dev.inmo.tgbotapi.types.message.abstracts.PossiblyTopicMessage
|
||||||
|
|
||||||
|
public inline fun Message.possiblyTopicMessageOrThrow(): PossiblyTopicMessage = this as
|
||||||
|
dev.inmo.tgbotapi.types.message.abstracts.PossiblyTopicMessage
|
||||||
|
|
||||||
|
public inline fun <T> Message.ifPossiblyTopicMessage(block: (PossiblyTopicMessage) -> T): T? =
|
||||||
|
possiblyTopicMessageOrNull() ?.let(block)
|
||||||
|
|
||||||
public inline fun Message.privateContentMessageOrNull(): PrivateContentMessage<MessageContent>? =
|
public inline fun Message.privateContentMessageOrNull(): PrivateContentMessage<MessageContent>? =
|
||||||
this as?
|
this as?
|
||||||
dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage<dev.inmo.tgbotapi.types.message.content.MessageContent>
|
dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage<dev.inmo.tgbotapi.types.message.content.MessageContent>
|
||||||
@ -3506,34 +3477,27 @@ public inline fun ResendableContent.mediaContentOrThrow(): MediaContent = this a
|
|||||||
public inline fun <T> ResendableContent.ifMediaContent(block: (MediaContent) -> T): T? =
|
public inline fun <T> ResendableContent.ifMediaContent(block: (MediaContent) -> T): T? =
|
||||||
mediaContentOrNull() ?.let(block)
|
mediaContentOrNull() ?.let(block)
|
||||||
|
|
||||||
public inline fun ResendableContent.audioMediaGroupContentOrNull(): AudioMediaGroupPartContent? = this
|
public inline fun ResendableContent.audioMediaGroupPartContentOrNull(): AudioMediaGroupPartContent?
|
||||||
as? dev.inmo.tgbotapi.types.message.content.AudioMediaGroupPartContent
|
= this as? dev.inmo.tgbotapi.types.message.content.AudioMediaGroupPartContent
|
||||||
|
|
||||||
public inline fun ResendableContent.audioMediaGroupContentOrThrow(): AudioMediaGroupPartContent = this
|
public inline fun ResendableContent.audioMediaGroupPartContentOrThrow(): AudioMediaGroupPartContent
|
||||||
as dev.inmo.tgbotapi.types.message.content.AudioMediaGroupPartContent
|
= this as dev.inmo.tgbotapi.types.message.content.AudioMediaGroupPartContent
|
||||||
|
|
||||||
public inline fun <T>
|
public inline fun <T>
|
||||||
ResendableContent.ifAudioMediaGroupContent(block: (AudioMediaGroupPartContent) -> T): T? =
|
ResendableContent.ifAudioMediaGroupPartContent(block: (AudioMediaGroupPartContent) -> T): T? =
|
||||||
audioMediaGroupContentOrNull() ?.let(block)
|
audioMediaGroupPartContentOrNull() ?.let(block)
|
||||||
|
|
||||||
public inline fun ResendableContent.documentMediaGroupContentOrNull(): DocumentMediaGroupPartContent? =
|
public inline fun ResendableContent.documentMediaGroupPartContentOrNull():
|
||||||
this as? dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupPartContent
|
DocumentMediaGroupPartContent? = this as?
|
||||||
|
dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupPartContent
|
||||||
|
|
||||||
public inline fun ResendableContent.documentMediaGroupContentOrThrow(): DocumentMediaGroupPartContent =
|
public inline fun ResendableContent.documentMediaGroupPartContentOrThrow():
|
||||||
this as dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupPartContent
|
DocumentMediaGroupPartContent = this as
|
||||||
|
dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupPartContent
|
||||||
|
|
||||||
public inline fun <T>
|
public inline fun <T>
|
||||||
ResendableContent.ifDocumentMediaGroupContent(block: (DocumentMediaGroupPartContent) -> T): T? =
|
ResendableContent.ifDocumentMediaGroupPartContent(block: (DocumentMediaGroupPartContent) -> T):
|
||||||
documentMediaGroupContentOrNull() ?.let(block)
|
T? = documentMediaGroupPartContentOrNull() ?.let(block)
|
||||||
|
|
||||||
public inline fun ResendableContent.mediaGroupContentOrNull(): MediaGroupPartContent? = this as?
|
|
||||||
dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
|
|
||||||
|
|
||||||
public inline fun ResendableContent.mediaGroupContentOrThrow(): MediaGroupPartContent = this as
|
|
||||||
dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
|
|
||||||
|
|
||||||
public inline fun <T> ResendableContent.ifMediaGroupContent(block: (MediaGroupPartContent) -> T): T? =
|
|
||||||
mediaGroupContentOrNull() ?.let(block)
|
|
||||||
|
|
||||||
public inline fun ResendableContent.textedMediaContentOrNull(): TextedMediaContent? = this as?
|
public inline fun ResendableContent.textedMediaContentOrNull(): TextedMediaContent? = this as?
|
||||||
dev.inmo.tgbotapi.types.message.content.TextedMediaContent
|
dev.inmo.tgbotapi.types.message.content.TextedMediaContent
|
||||||
@ -3544,15 +3508,39 @@ public inline fun ResendableContent.textedMediaContentOrThrow(): TextedMediaCont
|
|||||||
public inline fun <T> ResendableContent.ifTextedMediaContent(block: (TextedMediaContent) -> T): T? =
|
public inline fun <T> ResendableContent.ifTextedMediaContent(block: (TextedMediaContent) -> T): T? =
|
||||||
textedMediaContentOrNull() ?.let(block)
|
textedMediaContentOrNull() ?.let(block)
|
||||||
|
|
||||||
public inline fun ResendableContent.visualMediaGroupContentOrNull(): VisualMediaGroupPartContent? = this
|
public inline fun ResendableContent.mediaGroupCollectionContentOrNull():
|
||||||
as? dev.inmo.tgbotapi.types.message.content.VisualMediaGroupPartContent
|
MediaGroupCollectionContent? = this as?
|
||||||
|
dev.inmo.tgbotapi.types.message.content.MediaGroupCollectionContent
|
||||||
|
|
||||||
public inline fun ResendableContent.visualMediaGroupContentOrThrow(): VisualMediaGroupPartContent = this
|
public inline fun ResendableContent.mediaGroupCollectionContentOrThrow():
|
||||||
as dev.inmo.tgbotapi.types.message.content.VisualMediaGroupPartContent
|
MediaGroupCollectionContent = this as
|
||||||
|
dev.inmo.tgbotapi.types.message.content.MediaGroupCollectionContent
|
||||||
|
|
||||||
public inline fun <T>
|
public inline fun <T>
|
||||||
ResendableContent.ifVisualMediaGroupContent(block: (VisualMediaGroupPartContent) -> T): T? =
|
ResendableContent.ifMediaGroupCollectionContent(block: (MediaGroupCollectionContent) -> T): T? =
|
||||||
visualMediaGroupContentOrNull() ?.let(block)
|
mediaGroupCollectionContentOrNull() ?.let(block)
|
||||||
|
|
||||||
|
public inline fun ResendableContent.mediaGroupPartContentOrNull(): MediaGroupPartContent? = this as?
|
||||||
|
dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
|
||||||
|
|
||||||
|
public inline fun ResendableContent.mediaGroupPartContentOrThrow(): MediaGroupPartContent = this as
|
||||||
|
dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
|
||||||
|
|
||||||
|
public inline fun <T>
|
||||||
|
ResendableContent.ifMediaGroupPartContent(block: (MediaGroupPartContent) -> T): T? =
|
||||||
|
mediaGroupPartContentOrNull() ?.let(block)
|
||||||
|
|
||||||
|
public inline fun ResendableContent.visualMediaGroupPartContentOrNull():
|
||||||
|
VisualMediaGroupPartContent? = this as?
|
||||||
|
dev.inmo.tgbotapi.types.message.content.VisualMediaGroupPartContent
|
||||||
|
|
||||||
|
public inline fun ResendableContent.visualMediaGroupPartContentOrThrow():
|
||||||
|
VisualMediaGroupPartContent = this as
|
||||||
|
dev.inmo.tgbotapi.types.message.content.VisualMediaGroupPartContent
|
||||||
|
|
||||||
|
public inline fun <T>
|
||||||
|
ResendableContent.ifVisualMediaGroupPartContent(block: (VisualMediaGroupPartContent) -> T): T? =
|
||||||
|
visualMediaGroupPartContentOrNull() ?.let(block)
|
||||||
|
|
||||||
public inline fun ResendableContent.animationContentOrNull(): AnimationContent? = this as?
|
public inline fun ResendableContent.animationContentOrNull(): AnimationContent? = this as?
|
||||||
dev.inmo.tgbotapi.types.message.content.AnimationContent
|
dev.inmo.tgbotapi.types.message.content.AnimationContent
|
||||||
@ -3645,6 +3633,15 @@ public inline fun <T>
|
|||||||
ResendableContent.ifStaticLocationContent(block: (StaticLocationContent) -> T): T? =
|
ResendableContent.ifStaticLocationContent(block: (StaticLocationContent) -> T): T? =
|
||||||
staticLocationContentOrNull() ?.let(block)
|
staticLocationContentOrNull() ?.let(block)
|
||||||
|
|
||||||
|
public inline fun ResendableContent.mediaGroupContentOrNull(): MediaGroupContent? = this as?
|
||||||
|
dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
||||||
|
|
||||||
|
public inline fun ResendableContent.mediaGroupContentOrThrow(): MediaGroupContent = this as
|
||||||
|
dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
||||||
|
|
||||||
|
public inline fun <T> ResendableContent.ifMediaGroupContent(block: (MediaGroupContent) -> T): T? =
|
||||||
|
mediaGroupContentOrNull() ?.let(block)
|
||||||
|
|
||||||
public inline fun ResendableContent.photoContentOrNull(): PhotoContent? = this as?
|
public inline fun ResendableContent.photoContentOrNull(): PhotoContent? = this as?
|
||||||
dev.inmo.tgbotapi.types.message.content.PhotoContent
|
dev.inmo.tgbotapi.types.message.content.PhotoContent
|
||||||
|
|
||||||
@ -4728,69 +4725,3 @@ public inline fun Update.unknownUpdateOrThrow(): UnknownUpdate = this as
|
|||||||
|
|
||||||
public inline fun <T> Update.ifUnknownUpdate(block: (UnknownUpdate) -> T): T? =
|
public inline fun <T> Update.ifUnknownUpdate(block: (UnknownUpdate) -> T): T? =
|
||||||
unknownUpdateOrNull() ?.let(block)
|
unknownUpdateOrNull() ?.let(block)
|
||||||
|
|
||||||
public inline fun Update.channelPostMediaGroupUpdateOrNull(): ChannelPostMediaGroupUpdate? = this
|
|
||||||
as? dev.inmo.tgbotapi.types.update.media_group.ChannelPostMediaGroupUpdate
|
|
||||||
|
|
||||||
public inline fun Update.channelPostMediaGroupUpdateOrThrow(): ChannelPostMediaGroupUpdate = this as
|
|
||||||
dev.inmo.tgbotapi.types.update.media_group.ChannelPostMediaGroupUpdate
|
|
||||||
|
|
||||||
public inline fun <T>
|
|
||||||
Update.ifChannelPostMediaGroupUpdate(block: (ChannelPostMediaGroupUpdate) -> T): T? =
|
|
||||||
channelPostMediaGroupUpdateOrNull() ?.let(block)
|
|
||||||
|
|
||||||
public inline fun Update.editChannelPostMediaGroupUpdateOrNull(): EditChannelPostMediaGroupUpdate? =
|
|
||||||
this as? dev.inmo.tgbotapi.types.update.media_group.EditChannelPostMediaGroupUpdate
|
|
||||||
|
|
||||||
public inline fun Update.editChannelPostMediaGroupUpdateOrThrow(): EditChannelPostMediaGroupUpdate =
|
|
||||||
this as dev.inmo.tgbotapi.types.update.media_group.EditChannelPostMediaGroupUpdate
|
|
||||||
|
|
||||||
public inline fun <T>
|
|
||||||
Update.ifEditChannelPostMediaGroupUpdate(block: (EditChannelPostMediaGroupUpdate) -> T): T? =
|
|
||||||
editChannelPostMediaGroupUpdateOrNull() ?.let(block)
|
|
||||||
|
|
||||||
public inline fun Update.editMessageMediaGroupUpdateOrNull(): EditMessageMediaGroupUpdate? = this
|
|
||||||
as? dev.inmo.tgbotapi.types.update.media_group.EditMessageMediaGroupUpdate
|
|
||||||
|
|
||||||
public inline fun Update.editMessageMediaGroupUpdateOrThrow(): EditMessageMediaGroupUpdate = this as
|
|
||||||
dev.inmo.tgbotapi.types.update.media_group.EditMessageMediaGroupUpdate
|
|
||||||
|
|
||||||
public inline fun <T>
|
|
||||||
Update.ifEditMessageMediaGroupUpdate(block: (EditMessageMediaGroupUpdate) -> T): T? =
|
|
||||||
editMessageMediaGroupUpdateOrNull() ?.let(block)
|
|
||||||
|
|
||||||
public inline fun Update.mediaGroupUpdateOrNull(): MediaGroupUpdate? = this as?
|
|
||||||
dev.inmo.tgbotapi.types.update.media_group.MediaGroupUpdate
|
|
||||||
|
|
||||||
public inline fun Update.mediaGroupUpdateOrThrow(): MediaGroupUpdate = this as
|
|
||||||
dev.inmo.tgbotapi.types.update.media_group.MediaGroupUpdate
|
|
||||||
|
|
||||||
public inline fun <T> Update.ifMediaGroupUpdate(block: (MediaGroupUpdate) -> T): T? =
|
|
||||||
mediaGroupUpdateOrNull() ?.let(block)
|
|
||||||
|
|
||||||
public inline fun Update.sentMediaGroupUpdateOrNull(): SentMediaGroupUpdate? = this as?
|
|
||||||
dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
|
||||||
|
|
||||||
public inline fun Update.sentMediaGroupUpdateOrThrow(): SentMediaGroupUpdate = this as
|
|
||||||
dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
|
||||||
|
|
||||||
public inline fun <T> Update.ifSentMediaGroupUpdate(block: (SentMediaGroupUpdate) -> T): T? =
|
|
||||||
sentMediaGroupUpdateOrNull() ?.let(block)
|
|
||||||
|
|
||||||
public inline fun Update.editMediaGroupUpdateOrNull(): EditMediaGroupUpdate? = this as?
|
|
||||||
dev.inmo.tgbotapi.types.update.media_group.EditMediaGroupUpdate
|
|
||||||
|
|
||||||
public inline fun Update.editMediaGroupUpdateOrThrow(): EditMediaGroupUpdate = this as
|
|
||||||
dev.inmo.tgbotapi.types.update.media_group.EditMediaGroupUpdate
|
|
||||||
|
|
||||||
public inline fun <T> Update.ifEditMediaGroupUpdate(block: (EditMediaGroupUpdate) -> T): T? =
|
|
||||||
editMediaGroupUpdateOrNull() ?.let(block)
|
|
||||||
|
|
||||||
public inline fun Update.messageMediaGroupUpdateOrNull(): MessageMediaGroupUpdate? = this as?
|
|
||||||
dev.inmo.tgbotapi.types.update.media_group.MessageMediaGroupUpdate
|
|
||||||
|
|
||||||
public inline fun Update.messageMediaGroupUpdateOrThrow(): MessageMediaGroupUpdate = this as
|
|
||||||
dev.inmo.tgbotapi.types.update.media_group.MessageMediaGroupUpdate
|
|
||||||
|
|
||||||
public inline fun <T> Update.ifMessageMediaGroupUpdate(block: (MessageMediaGroupUpdate) -> T): T? =
|
|
||||||
messageMediaGroupUpdateOrNull() ?.let(block)
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.utils
|
package dev.inmo.tgbotapi.extensions.utils
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.*
|
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.MediaGroupMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
|
import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.MessageContent
|
import dev.inmo.tgbotapi.types.message.content.MessageContent
|
||||||
|
|
||||||
@ -36,6 +37,3 @@ inline fun <reified T : MessageContent> AnonymousGroupContentMessage<*>.requireW
|
|||||||
|
|
||||||
inline fun <reified T : MessageContent> CommonGroupContentMessage<*>.withContent() = if (content is T) { this as CommonGroupContentMessage<T> } else { null }
|
inline fun <reified T : MessageContent> CommonGroupContentMessage<*>.withContent() = if (content is T) { this as CommonGroupContentMessage<T> } else { null }
|
||||||
inline fun <reified T : MessageContent> CommonGroupContentMessage<*>.requireWithContent() = withContent<T>()!!
|
inline fun <reified T : MessageContent> CommonGroupContentMessage<*>.requireWithContent() = withContent<T>()!!
|
||||||
|
|
||||||
inline fun <reified T : MediaGroupPartContent> MediaGroupMessage<*>.withContent() = if (content is T) { this as MediaGroupMessage<T> } else { null }
|
|
||||||
inline fun <reified T : MediaGroupPartContent> MediaGroupMessage<*>.requireWithContent() = withContent<T>()!!
|
|
||||||
|
@ -3,21 +3,15 @@ package dev.inmo.tgbotapi.extensions.utils.extensions
|
|||||||
import dev.inmo.tgbotapi.abstracts.FromUser
|
import dev.inmo.tgbotapi.abstracts.FromUser
|
||||||
import dev.inmo.tgbotapi.abstracts.WithUser
|
import dev.inmo.tgbotapi.abstracts.WithUser
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asUser
|
import dev.inmo.tgbotapi.extensions.utils.asUser
|
||||||
import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat
|
|
||||||
import dev.inmo.tgbotapi.types.chat.Chat
|
import dev.inmo.tgbotapi.types.chat.Chat
|
||||||
import dev.inmo.tgbotapi.types.chat.User
|
import dev.inmo.tgbotapi.types.chat.User
|
||||||
import dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate
|
import dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.*
|
|
||||||
import dev.inmo.tgbotapi.utils.PreviewFeature
|
import dev.inmo.tgbotapi.utils.PreviewFeature
|
||||||
|
|
||||||
@PreviewFeature
|
@PreviewFeature
|
||||||
fun Update.sourceChat(): Chat? = when (this) {
|
fun Update.sourceChat(): Chat? = when (this) {
|
||||||
is MediaGroupUpdate -> when (this) {
|
|
||||||
is SentMediaGroupUpdate -> data.chat
|
|
||||||
is EditMediaGroupUpdate -> data.chat
|
|
||||||
}
|
|
||||||
is BaseMessageUpdate -> data.chat
|
is BaseMessageUpdate -> data.chat
|
||||||
is ChatJoinRequestUpdate -> data.chat
|
is ChatJoinRequestUpdate -> data.chat
|
||||||
else -> {
|
else -> {
|
||||||
|
@ -8,7 +8,6 @@ import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
|||||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.*
|
import dev.inmo.tgbotapi.types.message.content.*
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
|
||||||
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
|
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
@ -30,19 +29,6 @@ inline fun <reified T : MessageContent> filterForContentMessage(): suspend (Cont
|
|||||||
inline fun <reified T: MessageContent> Flow<BaseSentMessageUpdate>.filterContentMessages(
|
inline fun <reified T: MessageContent> Flow<BaseSentMessageUpdate>.filterContentMessages(
|
||||||
): Flow<ContentMessage<T>> = asContentMessagesFlow().mapNotNull(filterForContentMessage())
|
): Flow<ContentMessage<T>> = asContentMessagesFlow().mapNotNull(filterForContentMessage())
|
||||||
|
|
||||||
@RiskFeature("This method is low-level")
|
|
||||||
inline fun <reified T : MediaGroupPartContent> Flow<SentMediaGroupUpdate>.filterMediaGroupMessages(
|
|
||||||
): Flow<List<CommonMessage<T>>> = map {
|
|
||||||
it.data.mapNotNull { message ->
|
|
||||||
if (message.content is T) {
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
message as CommonMessage<T>
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param scopeToIncludeChannels This parameter is required when you want to include [textMessages] for channels too.
|
* @param scopeToIncludeChannels This parameter is required when you want to include [textMessages] for channels too.
|
||||||
* In this case will be created new channel which will aggregate messages from [FlowsUpdatesFilter.messagesFlow] and
|
* In this case will be created new channel which will aggregate messages from [FlowsUpdatesFilter.messagesFlow] and
|
||||||
@ -62,39 +48,9 @@ inline fun <reified T: MessageContent> FlowsUpdatesFilter.filterContentMessages(
|
|||||||
} ?: messagesFlow).filterContentMessages()
|
} ?: messagesFlow).filterContentMessages()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param scopeToIncludeChannels This parameter is required when you want to include [SentMediaGroupUpdate] for channels
|
|
||||||
* too. In this case will be created new channel which will aggregate messages from [FlowsUpdatesFilter.messagesFlow] and
|
|
||||||
* [FlowsUpdatesFilter.channelPostsFlow]. In case it is null will be used [Flow]s mapping
|
|
||||||
*/
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
|
||||||
inline fun <reified T: MediaGroupPartContent> FlowsUpdatesFilter.filterMediaGroupMessages(
|
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
|
||||||
): Flow<List<CommonMessage<T>>> {
|
|
||||||
return (scopeToIncludeChannels ?.let { scope ->
|
|
||||||
aggregateFlows(
|
|
||||||
scope,
|
|
||||||
messageMediaGroupsFlow,
|
|
||||||
channelPostMediaGroupsFlow
|
|
||||||
)
|
|
||||||
} ?: messageMediaGroupsFlow).filterMediaGroupMessages()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun FlowsUpdatesFilter.sentMessages(
|
fun FlowsUpdatesFilter.sentMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
): Flow<ContentMessage<MessageContent>> = filterContentMessages(scopeToIncludeChannels)
|
): Flow<ContentMessage<MessageContent>> = filterContentMessages(scopeToIncludeChannels)
|
||||||
fun FlowsUpdatesFilter.sentMessagesWithMediaGroups(
|
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
|
||||||
): Flow<ContentMessage<MessageContent>> = merge(
|
|
||||||
sentMessages(scopeToIncludeChannels),
|
|
||||||
mediaGroupMessages(scopeToIncludeChannels).flatMap {
|
|
||||||
it.mapNotNull {
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
it as? ContentMessage<MessageContent>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
fun Flow<BaseSentMessageUpdate>.animationMessages() = filterContentMessages<AnimationContent>()
|
fun Flow<BaseSentMessageUpdate>.animationMessages() = filterContentMessages<AnimationContent>()
|
||||||
fun FlowsUpdatesFilter.animationMessages(
|
fun FlowsUpdatesFilter.animationMessages(
|
||||||
@ -105,12 +61,6 @@ fun Flow<BaseSentMessageUpdate>.audioMessages() = filterContentMessages<AudioCon
|
|||||||
fun FlowsUpdatesFilter.audioMessages(
|
fun FlowsUpdatesFilter.audioMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<AudioContent>(scopeToIncludeChannels)
|
) = filterContentMessages<AudioContent>(scopeToIncludeChannels)
|
||||||
fun FlowsUpdatesFilter.audioMessagesWithMediaGroups(
|
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
|
||||||
) = merge(
|
|
||||||
filterContentMessages<AudioContent>(scopeToIncludeChannels),
|
|
||||||
mediaGroupAudioMessages(scopeToIncludeChannels).flatten()
|
|
||||||
)
|
|
||||||
|
|
||||||
fun Flow<BaseSentMessageUpdate>.contactMessages() = filterContentMessages<ContactContent>()
|
fun Flow<BaseSentMessageUpdate>.contactMessages() = filterContentMessages<ContactContent>()
|
||||||
fun FlowsUpdatesFilter.contactMessages(
|
fun FlowsUpdatesFilter.contactMessages(
|
||||||
@ -126,12 +76,6 @@ fun Flow<BaseSentMessageUpdate>.documentMessages() = filterContentMessages<Docum
|
|||||||
fun FlowsUpdatesFilter.documentMessages(
|
fun FlowsUpdatesFilter.documentMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<DocumentContent>(scopeToIncludeChannels)
|
) = filterContentMessages<DocumentContent>(scopeToIncludeChannels)
|
||||||
fun FlowsUpdatesFilter.documentMessagesWithMediaGroups(
|
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
|
||||||
) = merge(
|
|
||||||
filterContentMessages<DocumentContent>(scopeToIncludeChannels),
|
|
||||||
mediaGroupDocumentMessages(scopeToIncludeChannels).flatten()
|
|
||||||
)
|
|
||||||
|
|
||||||
fun Flow<BaseSentMessageUpdate>.gameMessages() = filterContentMessages<GameContent>()
|
fun Flow<BaseSentMessageUpdate>.gameMessages() = filterContentMessages<GameContent>()
|
||||||
fun FlowsUpdatesFilter.gameMessages(
|
fun FlowsUpdatesFilter.gameMessages(
|
||||||
@ -153,12 +97,6 @@ fun Flow<BaseSentMessageUpdate>.imageMessages() = photoMessages()
|
|||||||
fun FlowsUpdatesFilter.photoMessages(
|
fun FlowsUpdatesFilter.photoMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<PhotoContent>(scopeToIncludeChannels)
|
) = filterContentMessages<PhotoContent>(scopeToIncludeChannels)
|
||||||
fun FlowsUpdatesFilter.photoMessagesWithMediaGroups(
|
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
|
||||||
) = merge(
|
|
||||||
filterContentMessages<PhotoContent>(scopeToIncludeChannels),
|
|
||||||
mediaGroupPhotosMessages(scopeToIncludeChannels).flatten()
|
|
||||||
)
|
|
||||||
/**
|
/**
|
||||||
* Shortcut for [photoMessages]
|
* Shortcut for [photoMessages]
|
||||||
*/
|
*/
|
||||||
@ -166,9 +104,6 @@ fun FlowsUpdatesFilter.photoMessagesWithMediaGroups(
|
|||||||
inline fun FlowsUpdatesFilter.imageMessages(
|
inline fun FlowsUpdatesFilter.imageMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = photoMessages(scopeToIncludeChannels)
|
) = photoMessages(scopeToIncludeChannels)
|
||||||
fun FlowsUpdatesFilter.imageMessagesWithMediaGroups(
|
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
|
||||||
) = photoMessagesWithMediaGroups(scopeToIncludeChannels)
|
|
||||||
|
|
||||||
fun Flow<BaseSentMessageUpdate>.pollMessages() = filterContentMessages<PollContent>()
|
fun Flow<BaseSentMessageUpdate>.pollMessages() = filterContentMessages<PollContent>()
|
||||||
fun FlowsUpdatesFilter.pollMessages(
|
fun FlowsUpdatesFilter.pollMessages(
|
||||||
@ -194,12 +129,6 @@ fun Flow<BaseSentMessageUpdate>.videoMessages() = filterContentMessages<VideoCon
|
|||||||
fun FlowsUpdatesFilter.videoMessages(
|
fun FlowsUpdatesFilter.videoMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<VideoContent>(scopeToIncludeChannels)
|
) = filterContentMessages<VideoContent>(scopeToIncludeChannels)
|
||||||
fun FlowsUpdatesFilter.videoMessagesWithMediaGroups(
|
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
|
||||||
) = merge(
|
|
||||||
filterContentMessages<VideoContent>(scopeToIncludeChannels),
|
|
||||||
mediaGroupVideosMessages(scopeToIncludeChannels).flatten()
|
|
||||||
)
|
|
||||||
|
|
||||||
fun Flow<BaseSentMessageUpdate>.videoNoteMessages() = filterContentMessages<VideoNoteContent>()
|
fun Flow<BaseSentMessageUpdate>.videoNoteMessages() = filterContentMessages<VideoNoteContent>()
|
||||||
fun FlowsUpdatesFilter.videoNoteMessages(
|
fun FlowsUpdatesFilter.videoNoteMessages(
|
||||||
@ -210,34 +139,3 @@ fun Flow<BaseSentMessageUpdate>.voiceMessages() = filterContentMessages<VoiceCon
|
|||||||
fun FlowsUpdatesFilter.voiceMessages(
|
fun FlowsUpdatesFilter.voiceMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<VoiceContent>(scopeToIncludeChannels)
|
) = filterContentMessages<VoiceContent>(scopeToIncludeChannels)
|
||||||
|
|
||||||
|
|
||||||
fun Flow<SentMediaGroupUpdate>.mediaGroupMessages() = filterMediaGroupMessages<MediaGroupPartContent>()
|
|
||||||
fun FlowsUpdatesFilter.mediaGroupMessages(
|
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
|
||||||
) = filterMediaGroupMessages<MediaGroupPartContent>(scopeToIncludeChannels)
|
|
||||||
|
|
||||||
fun Flow<SentMediaGroupUpdate>.mediaGroupPhotosMessages() = filterMediaGroupMessages<PhotoContent>()
|
|
||||||
fun FlowsUpdatesFilter.mediaGroupPhotosMessages(
|
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
|
||||||
) = filterMediaGroupMessages<PhotoContent>(scopeToIncludeChannels)
|
|
||||||
|
|
||||||
fun Flow<SentMediaGroupUpdate>.mediaGroupVideosMessages() = filterMediaGroupMessages<VideoContent>()
|
|
||||||
fun FlowsUpdatesFilter.mediaGroupVideosMessages(
|
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
|
||||||
) = filterMediaGroupMessages<VideoContent>(scopeToIncludeChannels)
|
|
||||||
|
|
||||||
fun Flow<SentMediaGroupUpdate>.mediaGroupVisualMessages() = filterMediaGroupMessages<VisualMediaGroupPartContent>()
|
|
||||||
fun FlowsUpdatesFilter.mediaGroupVisualMessages(
|
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
|
||||||
) = filterMediaGroupMessages<VisualMediaGroupPartContent>(scopeToIncludeChannels)
|
|
||||||
|
|
||||||
fun Flow<SentMediaGroupUpdate>.mediaGroupAudioMessages() = filterMediaGroupMessages<AudioContent>()
|
|
||||||
fun FlowsUpdatesFilter.mediaGroupAudioMessages(
|
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
|
||||||
) = filterMediaGroupMessages<AudioContent>(scopeToIncludeChannels)
|
|
||||||
|
|
||||||
fun Flow<SentMediaGroupUpdate>.mediaGroupDocumentMessages() = filterMediaGroupMessages<DocumentContent>()
|
|
||||||
fun FlowsUpdatesFilter.mediaGroupDocumentMessages(
|
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
|
||||||
) = filterMediaGroupMessages<DocumentContent>(scopeToIncludeChannels)
|
|
||||||
|
@ -1,69 +0,0 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.utils.shortcuts
|
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.requests.send.media.SendMediaGroup
|
|
||||||
import dev.inmo.tgbotapi.types.*
|
|
||||||
import dev.inmo.tgbotapi.types.chat.Chat
|
|
||||||
import dev.inmo.tgbotapi.types.message.ForwardInfo
|
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.*
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
|
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
|
||||||
|
|
||||||
val List<CommonMessage<out MediaGroupPartContent>>.forwardInfo: ForwardInfo?
|
|
||||||
get() = firstOrNull() ?.forwardInfo
|
|
||||||
val List<CommonMessage<out MediaGroupPartContent>>.replyTo: Message?
|
|
||||||
get() = firstOrNull() ?.replyTo
|
|
||||||
val List<CommonMessage<out MediaGroupPartContent>>.chat: Chat?
|
|
||||||
get() = firstOrNull() ?.chat
|
|
||||||
val List<MediaGroupMessage<*>>.mediaGroupId: MediaGroupIdentifier?
|
|
||||||
get() = firstOrNull() ?.mediaGroupId
|
|
||||||
|
|
||||||
val SentMediaGroupUpdate.forwardInfo: ForwardInfo?
|
|
||||||
get() = data.first().forwardInfo
|
|
||||||
val SentMediaGroupUpdate.replyTo: Message?
|
|
||||||
get() = data.first().replyTo
|
|
||||||
val SentMediaGroupUpdate.chat: Chat
|
|
||||||
get() = data.chat!!
|
|
||||||
val SentMediaGroupUpdate.mediaGroupId: MediaGroupIdentifier
|
|
||||||
get() = data.mediaGroupId!!
|
|
||||||
|
|
||||||
fun List<CommonMessage<MediaGroupPartContent>>.createResend(
|
|
||||||
chatId: ChatId,
|
|
||||||
threadId: MessageThreadId? = null,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyTo: MessageId? = null
|
|
||||||
) = SendMediaGroup<MediaGroupPartContent>(
|
|
||||||
chatId,
|
|
||||||
map { it.content.toMediaGroupMemberTelegramMedia() },
|
|
||||||
threadId,
|
|
||||||
disableNotification,
|
|
||||||
protectContent,
|
|
||||||
replyTo
|
|
||||||
)
|
|
||||||
|
|
||||||
fun List<CommonMessage<MediaGroupPartContent>>.createResend(
|
|
||||||
chat: Chat,
|
|
||||||
threadId: MessageThreadId? = null,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyTo: MessageId? = null
|
|
||||||
) = createResend(
|
|
||||||
chat.id,
|
|
||||||
threadId,
|
|
||||||
disableNotification,
|
|
||||||
protectContent,
|
|
||||||
replyTo
|
|
||||||
)
|
|
||||||
|
|
||||||
fun SentMediaGroupUpdate.createResend(
|
|
||||||
threadId: MessageThreadId? = null,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyTo: MessageId? = null
|
|
||||||
) = data.createResend(
|
|
||||||
chat,
|
|
||||||
threadId,
|
|
||||||
disableNotification,
|
|
||||||
protectContent,
|
|
||||||
replyTo
|
|
||||||
)
|
|
@ -1,7 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.utils.updates
|
package dev.inmo.tgbotapi.extensions.utils.updates
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.*
|
import dev.inmo.tgbotapi.types.update.abstracts.*
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.*
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.filterIsInstance
|
import kotlinx.coroutines.flow.filterIsInstance
|
||||||
|
|
||||||
@ -16,22 +15,3 @@ fun Flow<BaseMessageUpdate>.onlySentMessageUpdates(): Flow<BaseSentMessageUpdate
|
|||||||
* Converts flow to [Flow] of [BaseSentMessageUpdate]
|
* Converts flow to [Flow] of [BaseSentMessageUpdate]
|
||||||
*/
|
*/
|
||||||
fun Flow<BaseMessageUpdate>.onlyEditMessageUpdates(): Flow<BaseEditMessageUpdate> = filterIsInstance()
|
fun Flow<BaseMessageUpdate>.onlyEditMessageUpdates(): Flow<BaseEditMessageUpdate> = filterIsInstance()
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts flow to [Flow] of [MediaGroupUpdate]. Please, remember that it could be either [EditMediaGroupUpdate]
|
|
||||||
* or [SentMediaGroupUpdate]
|
|
||||||
*
|
|
||||||
* @see onlySentMediaGroupUpdates
|
|
||||||
* @see onlyEditMediaGroupUpdates
|
|
||||||
*/
|
|
||||||
fun Flow<BaseMessageUpdate>.onlyMediaGroupsUpdates(): Flow<MediaGroupUpdate> = filterIsInstance()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts flow to [Flow] of [SentMediaGroupUpdate]
|
|
||||||
*/
|
|
||||||
fun Flow<MediaGroupUpdate>.onlySentMediaGroupUpdates(): Flow<SentMediaGroupUpdate> = filterIsInstance()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts flow to [Flow] of [EditMediaGroupUpdate]
|
|
||||||
*/
|
|
||||||
fun Flow<MediaGroupUpdate>.onlyEditMediaGroupUpdates(): Flow<EditMediaGroupUpdate> = filterIsInstance()
|
|
||||||
|
@ -3,7 +3,6 @@ package dev.inmo.tgbotapi.extensions.utils.updates
|
|||||||
import dev.inmo.tgbotapi.types.ChatId
|
import dev.inmo.tgbotapi.types.ChatId
|
||||||
import dev.inmo.tgbotapi.types.chat.Chat
|
import dev.inmo.tgbotapi.types.chat.Chat
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.filter
|
import kotlinx.coroutines.flow.filter
|
||||||
|
|
||||||
@ -15,13 +14,3 @@ fun <T : BaseMessageUpdate> Flow<T>.filterBaseMessageUpdatesByChatId(chatId: Cha
|
|||||||
* [Flow.filter] incoming [BaseMessageUpdate]s by their [ChatId] using [Chat.id] of [chat]
|
* [Flow.filter] incoming [BaseMessageUpdate]s by their [ChatId] using [Chat.id] of [chat]
|
||||||
*/
|
*/
|
||||||
fun <T : BaseMessageUpdate> Flow<T>.filterBaseMessageUpdatesByChat(chat: Chat): Flow<T> = filterBaseMessageUpdatesByChatId(chat.id)
|
fun <T : BaseMessageUpdate> Flow<T>.filterBaseMessageUpdatesByChat(chat: Chat): Flow<T> = filterBaseMessageUpdatesByChatId(chat.id)
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* [Flow.filter] incoming [SentMediaGroupUpdate]s by their [ChatId]
|
|
||||||
*/
|
|
||||||
fun <T : SentMediaGroupUpdate> Flow<T>.filterSentMediaGroupUpdatesByChatId(chatId: ChatId): Flow<T> = filter { it.data.first().chat.id == chatId }
|
|
||||||
/**
|
|
||||||
* [Flow.filter] incoming [SentMediaGroupUpdate]s by their [ChatId] using [Chat.id] of [chat]
|
|
||||||
*/
|
|
||||||
fun <T : SentMediaGroupUpdate> Flow<T>.filterSentMediaGroupUpdatesByChat(chat: Chat): Flow<T> = filterSentMediaGroupUpdatesByChatId(chat.id)
|
|
||||||
|
@ -8,9 +8,11 @@ import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates
|
|||||||
import dev.inmo.tgbotapi.extensions.utils.updates.lastUpdateIdentifier
|
import dev.inmo.tgbotapi.extensions.utils.updates.lastUpdateIdentifier
|
||||||
import dev.inmo.tgbotapi.requests.GetUpdates
|
import dev.inmo.tgbotapi.requests.GetUpdates
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
||||||
import dev.inmo.tgbotapi.types.update.*
|
import dev.inmo.tgbotapi.types.update.*
|
||||||
|
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
|
||||||
import dev.inmo.tgbotapi.updateshandlers.*
|
import dev.inmo.tgbotapi.updateshandlers.*
|
||||||
import io.ktor.client.plugins.HttpRequestTimeoutException
|
import io.ktor.client.plugins.HttpRequestTimeoutException
|
||||||
import io.ktor.utils.io.CancellationException
|
import io.ktor.utils.io.CancellationException
|
||||||
@ -56,7 +58,10 @@ fun TelegramBot.longPollingFlow(
|
|||||||
* We are throw out the last media group and will reretrieve it again in the next get updates
|
* We are throw out the last media group and will reretrieve it again in the next get updates
|
||||||
* and it will guarantee that it is full
|
* and it will guarantee that it is full
|
||||||
*/
|
*/
|
||||||
if (originalUpdates.size == getUpdatesLimit.last && converted.last() is SentMediaGroupUpdate) {
|
if (
|
||||||
|
originalUpdates.size == getUpdatesLimit.last
|
||||||
|
&& ((converted.last() as? BaseSentMessageUpdate) ?.data as? CommonMessage<*>) ?.content is MediaGroupContent
|
||||||
|
) {
|
||||||
converted - converted.last()
|
converted - converted.last()
|
||||||
} else {
|
} else {
|
||||||
converted
|
converted
|
||||||
@ -67,7 +72,7 @@ fun TelegramBot.longPollingFlow(
|
|||||||
for (update in updates) {
|
for (update in updates) {
|
||||||
send(update)
|
send(update)
|
||||||
|
|
||||||
lastUpdateIdentifier = update.lastUpdateIdentifier()
|
lastUpdateIdentifier = update.updateId
|
||||||
}
|
}
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
cancel(it as? CancellationException ?: return@onFailure)
|
cancel(it as? CancellationException ?: return@onFailure)
|
||||||
|
Loading…
Reference in New Issue
Block a user