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

Merge pull request #677 from InsanusMokrassar/task/676-rework_of_media_groups

676 Rework of media groups
This commit is contained in:
InsanusMokrassar 2022-11-08 13:09:21 +06:00 committed by GitHub
commit d715bc0a9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
65 changed files with 888 additions and 1326 deletions

View File

@ -1,70 +1,57 @@
package dev.inmo.tgbotapi.extensions.api.InternalUtils
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
import dev.inmo.tgbotapi.types.UpdateIdentifier
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
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.abstracts.*
import dev.inmo.tgbotapi.types.update.media_group.*
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()
}
import dev.inmo.tgbotapi.utils.extensions.asMediaGroupMessage
/**
* Will convert incoming list of updates to list with [MediaGroupUpdate]s
*/
internal fun List<Update>.convertWithMediaGroupUpdates(): List<Update> {
val resultUpdates = mutableListOf<Update>()
val mediaGroups = mutableMapOf<MediaGroupIdentifier, MutableList<BaseSentMessageUpdate>>()
val mediaGroups = mutableMapOf<MediaGroupIdentifier, MutableList<Pair<BaseSentMessageUpdate, PossiblySentViaBotCommonMessage<MediaGroupPartContent>>>>()
for (update in this) {
val data = (update.data as? MediaGroupMessage<*>)
if (data == null) {
val message = (update.data as? PossiblySentViaBotCommonMessage<*>) ?.let {
if (it.content is MediaGroupPartContent) {
it as PossiblySentViaBotCommonMessage<MediaGroupPartContent>
} else {
null
}
}
val mediaGroupId = message ?.mediaGroupId
if (message == null || mediaGroupId == null) {
resultUpdates.add(update)
continue
}
when (update) {
is BaseEditMessageUpdate -> resultUpdates.add(
update.toEditMediaGroupUpdate()
)
is BaseSentMessageUpdate -> {
mediaGroups.getOrPut(data.mediaGroupId) {
mediaGroups.getOrPut(mediaGroupId) {
mutableListOf()
}.add(update)
}.add(update to message)
}
else -> resultUpdates.add(update)
}
}
mediaGroups.values.map {
it.toSentMediaGroupUpdate() ?.let { mediaGroupUpdate ->
resultUpdates.add(mediaGroupUpdate)
}
mediaGroups.map { (_, updatesWithMessages) ->
val update = updatesWithMessages.maxBy { it.first.updateId }.first
resultUpdates.add(
update.copy(updatesWithMessages.map { it.second }.asMediaGroupMessage())
)
}
resultUpdates.sortBy { it.updateId }
return resultUpdates
}
internal fun List<BaseSentMessageUpdate>.toSentMediaGroupUpdate(): SentMediaGroupUpdate? = (this as? SentMediaGroupUpdate) ?: let {
if (isEmpty()) {
return@let null
}
val resultList = sortedBy { it.updateId }
when (first()) {
is MessageUpdate -> MessageMediaGroupUpdate(resultList)
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}")
}
}
/**
* @return [EditMessageMediaGroupUpdate] in case if [this] is [EditMessageUpdate]. When [this] object is
* [EditChannelPostUpdate] instance - will return [EditChannelPostMediaGroupUpdate]
*
* @throws IllegalStateException
*/
internal fun BaseEditMessageUpdate.toEditMediaGroupUpdate() = this

View File

@ -1,184 +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.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
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<MediaGroupContent>>,
text: String? = null,
parseMode: ParseMode? = null,
threadId: MessageThreadId? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null
): List<MediaGroupMessage<MediaGroupContent>> {
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<MediaGroupContent>>,
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<MediaGroupContent>>,
entities: TextSourcesList,
threadId: MessageThreadId? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null
): List<MediaGroupMessage<MediaGroupContent>> {
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<MediaGroupContent>>,
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)

View File

@ -1235,7 +1235,7 @@ suspend fun TelegramBot.reply(
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
is AudioMediaGroupContent -> reply(
is AudioMediaGroupPartContent -> reply(
to = to,
audio = content.media,
text = text,
@ -1307,7 +1307,7 @@ suspend fun TelegramBot.reply(
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
is AudioMediaGroupContent -> reply(
is AudioMediaGroupPartContent -> reply(
to = to,
audio = content.media,
entities = entities,

View File

@ -1393,7 +1393,7 @@ suspend fun TelegramBot.reply(
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
is AudioMediaGroupContent -> reply(
is AudioMediaGroupPartContent -> reply(
toChatId = toChatId,
toMessageId = toMessageId,
audio = content.media,
@ -1479,7 +1479,7 @@ suspend fun TelegramBot.reply(
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
is AudioMediaGroupContent -> reply(
is AudioMediaGroupPartContent -> reply(
toChatId = toChatId,
toMessageId = toMessageId,
audio = content.media,

View File

@ -1453,7 +1453,7 @@ suspend fun TelegramBot.send(
@JvmName("sendMedaGroupByContent")
suspend fun TelegramBot.send(
chatId: ChatIdentifier,
media: List<MediaGroupContent>,
media: List<MediaGroupPartContent>,
threadId: MessageThreadId? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
@ -1468,7 +1468,7 @@ suspend fun TelegramBot.send(
@JvmName("sendMedaGroupByContent")
suspend fun TelegramBot.send(
chat: Chat,
media: List<MediaGroupContent>,
media: List<MediaGroupPartContent>,
threadId: MessageThreadId? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
@ -1622,7 +1622,7 @@ suspend fun TelegramBot.send(
@JvmName("sendVisualMediaGroupByContent")
suspend fun TelegramBot.send(
chatId: ChatIdentifier,
media: List<VisualMediaGroupContent>,
media: List<VisualMediaGroupPartContent>,
threadId: MessageThreadId? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
@ -1636,7 +1636,7 @@ suspend fun TelegramBot.send(
@JvmName("sendVisualMediaGroupByContent")
suspend fun TelegramBot.send(
chat: Chat,
media: List<VisualMediaGroupContent>,
media: List<VisualMediaGroupPartContent>,
threadId: MessageThreadId? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,

View File

@ -7,8 +7,8 @@ import dev.inmo.tgbotapi.types.media.*
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.chat.Chat
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupPartContent
import dev.inmo.tgbotapi.types.message.content.AudioContent
import dev.inmo.tgbotapi.types.message.content.DocumentContent
import dev.inmo.tgbotapi.utils.RiskFeature
@ -27,7 +27,7 @@ suspend fun TelegramBot.sendMediaGroup(
replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null
) = execute(
SendMediaGroup<MediaGroupContent>(
SendMediaGroup<MediaGroupPartContent>(
chatId, media, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply
)
)
@ -55,7 +55,7 @@ suspend fun TelegramBot.sendMediaGroup(
@JvmName("sendMedaGroupByContent")
suspend fun TelegramBot.sendMediaGroup(
chatId: ChatIdentifier,
media: List<MediaGroupContent>,
media: List<MediaGroupPartContent>,
threadId: MessageThreadId? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
@ -72,7 +72,7 @@ suspend fun TelegramBot.sendMediaGroup(
@JvmName("sendMedaGroupByContent")
suspend fun TelegramBot.sendMediaGroup(
chat: Chat,
media: List<MediaGroupContent>,
media: List<MediaGroupPartContent>,
threadId: MessageThreadId? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
@ -248,7 +248,7 @@ suspend fun TelegramBot.sendVisualMediaGroup(
@JvmName("sendVisualMediaGroupByContent")
suspend fun TelegramBot.sendVisualMediaGroup(
chatId: ChatIdentifier,
media: List<VisualMediaGroupContent>,
media: List<VisualMediaGroupPartContent>,
threadId: MessageThreadId? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
@ -264,7 +264,7 @@ suspend fun TelegramBot.sendVisualMediaGroup(
@JvmName("sendVisualMediaGroupByContent")
suspend fun TelegramBot.sendVisualMediaGroup(
chat: Chat,
media: List<VisualMediaGroupContent>,
media: List<VisualMediaGroupPartContent>,
threadId: MessageThreadId? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,

View File

@ -1,7 +1,7 @@
package dev.inmo.tgbotapi.extensions.api.utils
import dev.inmo.tgbotapi.extensions.api.InternalUtils.convertWithMediaGroupUpdates
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage
import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate
import dev.inmo.tgbotapi.types.update.abstracts.Update
import dev.inmo.tgbotapi.updateshandlers.UpdateReceiver
@ -30,10 +30,21 @@ fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation(
launch {
launch {
for (update in updatesChannel) {
when (val data = update.data) {
is MediaGroupMessage<*> -> mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate)
else -> output(update)
val dataAsPossiblySentViaBotCommonMessage = update.data as? PossiblySentViaBotCommonMessage<*>
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 {

View File

@ -66,12 +66,12 @@ suspend fun BehaviourContext.waitAudioMediaGroupContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitContent<AudioMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
) = waitContent<AudioMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
suspend fun BehaviourContext.waitDocumentMediaGroupContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitContent<DocumentMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
) = waitContent<DocumentMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
suspend fun BehaviourContext.waitMedia(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
@ -81,12 +81,12 @@ suspend fun BehaviourContext.waitAnyMediaGroupContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitContent<MediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
) = waitContent<MediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
suspend fun BehaviourContext.waitVisualMediaGroupContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitContent<VisualMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
) = waitContent<VisualMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
suspend fun BehaviourContext.waitTextedMediaContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },

View File

@ -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.content.*
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.lowLevelRiskFeatureMessage
import kotlinx.coroutines.flow.Flow
@ -25,20 +24,7 @@ suspend inline fun <reified O : MessageContent> BehaviourContext.waitContentMess
initRequest,
errorFactory
) {
val messages = when (it) {
is SentMediaGroupUpdate -> {
if (includeMediaGroups) {
it.data
} else {
emptyList()
}
}
is BaseSentMessageUpdate -> listOf(it.data)
else -> return@expectFlow emptyList()
}
messages.mapNotNull { message ->
(message as? CommonMessage<*>) ?.withContent<O>()
}
listOfNotNull((it.data as? CommonMessage<*>) ?.withContent<O>())
}
internal inline fun <reified T : MessageContent> contentMessageConverter(
@ -103,12 +89,12 @@ suspend fun BehaviourContext.waitAudioMediaGroupContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitContentMessage<AudioMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
) = waitContentMessage<AudioMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
suspend fun BehaviourContext.waitDocumentMediaGroupContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitContentMessage<DocumentMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
) = waitContentMessage<DocumentMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
suspend fun BehaviourContext.waitMediaMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
@ -118,12 +104,12 @@ suspend fun BehaviourContext.waitAnyMediaGroupContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitContentMessage<MediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
) = waitContentMessage<MediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
suspend fun BehaviourContext.waitVisualMediaGroupContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitContentMessage<VisualMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
) = waitContentMessage<VisualMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
suspend fun BehaviourContext.waitTextedMediaContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },

View File

@ -15,7 +15,7 @@ suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedConte
initRequest: Request<*>? = null,
includeMediaGroups: Boolean = true,
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(
initRequest: Request<*>? = null,
@ -64,12 +64,12 @@ suspend fun BehaviourContext.waitEditedAudioMediaGroupContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitEditedContent<AudioMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
) = waitEditedContent<AudioMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
suspend fun BehaviourContext.waitEditedDocumentMediaGroupContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitEditedContent<DocumentMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
) = waitEditedContent<DocumentMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
suspend fun BehaviourContext.waitEditedMedia(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
@ -79,12 +79,12 @@ suspend fun BehaviourContext.waitEditedAnyMediaGroupContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitEditedContent<MediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
) = waitEditedContent<MediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
suspend fun BehaviourContext.waitEditedVisualMediaGroupContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitEditedContent<VisualMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
) = waitEditedContent<VisualMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
suspend fun BehaviourContext.waitEditedTextedMediaContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },

View File

@ -3,11 +3,11 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
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.withContent
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.content.*
import dev.inmo.tgbotapi.types.update.abstracts.BaseEditMessageUpdate
import dev.inmo.tgbotapi.utils.RiskFeature
@ -17,7 +17,6 @@ import kotlinx.coroutines.flow.Flow
@RiskFeature(lowLevelRiskFeatureMessage)
suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedContentMessage(
initRequest: Request<*>? = null,
includeMediaGroups: Boolean = true,
noinline errorFactory: NullableRequestBuilder<*> = { null }
): Flow<CommonMessage<O>> = expectFlow(
initRequest,
@ -26,11 +25,7 @@ suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedConte
val messages = when (it) {
is BaseEditMessageUpdate -> {
val commonMessage = it.data.commonMessageOrNull() ?: return@expectFlow emptyList()
if (commonMessage !is MediaGroupMessage<*> || includeMediaGroups) {
listOf(commonMessage)
} else {
emptyList()
}
listOf(commonMessage)
}
else -> return@expectFlow emptyList()
}
@ -41,109 +36,103 @@ suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedConte
suspend fun BehaviourContext.waitEditedMessageContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitEditedContentMessage<MessageContent>(initRequest, includeMediaGroups, errorFactory)
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<MessageContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedContactMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<ContactContent>(initRequest, false, errorFactory)
) = waitEditedContentMessage<ContactContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedDiceMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<DiceContent>(initRequest, false, errorFactory)
) = waitEditedContentMessage<DiceContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedGameMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<GameContent>(initRequest, false, errorFactory)
) = waitEditedContentMessage<GameContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedLocationMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<LocationContent>(initRequest, false, errorFactory)
) = waitEditedContentMessage<LocationContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedLiveLocationMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<LiveLocationContent>(initRequest, false, errorFactory)
) = waitEditedContentMessage<LiveLocationContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedStaticLocationMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<StaticLocationContent>(initRequest, false, errorFactory)
) = waitEditedContentMessage<StaticLocationContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedTextMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<TextContent>(initRequest, false, errorFactory)
) = waitEditedContentMessage<TextContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedVenueMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<VenueContent>(initRequest, false, errorFactory)
) = waitEditedContentMessage<VenueContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedAudioMediaGroupContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitEditedContentMessage<AudioMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<AudioMediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedDocumentMediaGroupContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitEditedContentMessage<DocumentMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<DocumentMediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedMediaMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = false
) = waitEditedContentMessage<MediaContent>(initRequest, includeMediaGroups, errorFactory)
) = waitEditedContentMessage<MediaContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedAnyMediaGroupContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitEditedContentMessage<MediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<MediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedVisualMediaGroupContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitEditedContentMessage<VisualMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<VisualMediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedTextedMediaContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitEditedContentMessage<TextedMediaContent>(initRequest, includeMediaGroups, errorFactory)
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<TextedMediaContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedAnimationMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<AnimationContent>(initRequest, false, errorFactory)
) = waitEditedContentMessage<AnimationContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedAudioMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = false
) = waitEditedContentMessage<AudioContent>(initRequest, includeMediaGroups, errorFactory)
) = waitEditedContentMessage<AudioContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedDocumentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = false
) = waitEditedContentMessage<DocumentContent>(initRequest, includeMediaGroups, errorFactory)
) = waitEditedContentMessage<DocumentContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedPhotoMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = false
) = waitEditedContentMessage<PhotoContent>(initRequest, includeMediaGroups, errorFactory)
) = waitEditedContentMessage<PhotoContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedStickerMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<StickerContent>(initRequest, false, errorFactory)
) = waitEditedContentMessage<StickerContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedVideoMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = false
) = waitEditedContentMessage<VideoContent>(initRequest, includeMediaGroups, errorFactory)
) = waitEditedContentMessage<VideoContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedVideoNoteMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<VideoNoteContent>(initRequest, false, errorFactory)
) = waitEditedContentMessage<VideoNoteContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedVoiceMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<VoiceContent>(initRequest, false, errorFactory)
) = waitEditedContentMessage<VoiceContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedInvoiceMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<InvoiceContent>(initRequest, false, errorFactory)
) = waitEditedContentMessage<InvoiceContent>(initRequest, errorFactory)

View File

@ -1,40 +1,46 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
import dev.inmo.tgbotapi.extensions.utils.baseSentMessageUpdateOrNull
import dev.inmo.tgbotapi.extensions.utils.commonMessageOrNull
import dev.inmo.tgbotapi.extensions.utils.withContent
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.content.*
import dev.inmo.tgbotapi.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 : MediaGroupContent> BehaviourContext.buildMediaGroupWaiter(
suspend inline fun <reified T : MediaGroupPartContent> BehaviourContext.buildMediaGroupWaiter(
initRequest: Request<*>? = null,
noinline errorFactory: NullableRequestBuilder<*> = { null }
): Flow<List<O>> = buildMediaGroupMessagesWaiter<O>(initRequest, errorFactory).map { it.map { it.content } }
): Flow<MediaGroupContent<T>> = flowsUpdatesFilter.expectFlow(bot, initRequest, errorFactory) { update ->
update.baseSentMessageUpdateOrNull() ?.data ?.commonMessageOrNull() ?.withContentOrNull<MediaGroupContent<*>>() ?.let { message ->
if (message.content.group.all { it is T }) {
listOf(message.content as MediaGroupContent<T>)
} else {
null
}
} ?: emptyList()
}
suspend fun BehaviourContext.waitMediaGroup(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = buildMediaGroupWaiter<MediaGroupContent>(initRequest, errorFactory)
) = buildMediaGroupWaiter<MediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitPlaylist(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = buildMediaGroupWaiter<AudioMediaGroupContent>(initRequest, errorFactory)
) = buildMediaGroupWaiter<AudioMediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitDocumentsGroup(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = buildMediaGroupWaiter<DocumentMediaGroupContent>(initRequest, errorFactory)
) = buildMediaGroupWaiter<DocumentMediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitVisualGallery(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = buildMediaGroupWaiter<VisualMediaGroupContent>(initRequest, errorFactory)
) = buildMediaGroupWaiter<VisualMediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitPhotoGallery(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }

View File

@ -1,44 +1,46 @@
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.baseSentMessageUpdateOrNull
import dev.inmo.tgbotapi.extensions.utils.commonMessageOrNull
import dev.inmo.tgbotapi.extensions.utils.withContent
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.content.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
import kotlinx.coroutines.flow.Flow
@RiskFeature(lowLevelRiskFeatureMessage)
suspend inline fun <reified T : MediaGroupContent> BehaviourContext.buildMediaGroupMessagesWaiter(
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
)
): Flow<MediaGroupMessage<T>> = flowsUpdatesFilter.expectFlow(bot, initRequest, errorFactory) { update ->
update.baseSentMessageUpdateOrNull() ?.data ?.commonMessageOrNull() ?.withContentOrNull<MediaGroupContent<*>>() ?.let { message ->
if (message.content.group.all { it is T }) {
listOf(message as MediaGroupMessage<T>)
} else {
null
}
} ?: emptyList()
}
suspend fun BehaviourContext.waitMediaGroupMessages(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = buildMediaGroupMessagesWaiter<MediaGroupContent>(initRequest, errorFactory)
) = buildMediaGroupMessagesWaiter<MediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitPlaylistMessages(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = buildMediaGroupMessagesWaiter<AudioMediaGroupContent>(initRequest, errorFactory)
) = buildMediaGroupMessagesWaiter<AudioMediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitDocumentsGroupMessages(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = buildMediaGroupMessagesWaiter<DocumentMediaGroupContent>(initRequest, errorFactory)
) = buildMediaGroupMessagesWaiter<DocumentMediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitVisualGalleryMessages(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = buildMediaGroupMessagesWaiter<VisualMediaGroupContent>(initRequest, errorFactory)
) = buildMediaGroupMessagesWaiter<VisualMediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitPhotoGalleryMessages(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }

View File

@ -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.utils.SimpleFilter
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
/**
* Allow only messages which are not [MediaGroupMessage]
*/
val MessageFilterExcludingMediaGroups: BehaviourContextAndTwoTypesReceiver<Boolean, CommonMessage<*>, Update> = { _, update ->
update !is MediaGroupMessage<*>
}
/**
* Allow only messages which are not [MediaGroupMessage]
*/
val CommonMessageFilterExcludeMediaGroups = SimpleFilter<Message> {
it !is MediaGroupMessage<*>
it !is CommonMessage<*> || it.content !is MediaGroupContent<*>
}

View File

@ -14,7 +14,6 @@ import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
import dev.inmo.tgbotapi.types.message.content.*
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
import dev.inmo.tgbotapi.types.update.abstracts.Update
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
typealias CommonMessageFilter<T> = SimpleFilter<CommonMessage<T>>
@ -26,7 +25,6 @@ internal suspend inline fun <BC : BehaviourContext, reified T : MessageContent>
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
when (it) {
is BaseSentMessageUpdate -> it.data.whenCommonMessage(::listOfNotNull)
is SentMediaGroupUpdate -> it.data
else -> null
} ?.mapNotNull { message ->
if (message.content is T) message as CommonMessage<T> else null
@ -287,7 +285,7 @@ suspend fun <BC : BehaviourContext> BC.onVenue(
* data
*/
suspend fun <BC : BehaviourContext> BC.onAudioMediaGroup(
initialFilter: CommonMessageFilter<AudioMediaGroupContent>? = null,
initialFilter: CommonMessageFilter<AudioMediaGroupPartContent>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, AudioMediaGroupMessage, Update> = MessageFilterByChat,
markerFactory: MarkerFactory<in AudioMediaGroupMessage, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, AudioMediaGroupMessage>
@ -311,7 +309,7 @@ suspend fun <BC : BehaviourContext> BC.onAudioMediaGroup(
* data
*/
suspend fun <BC : BehaviourContext> BC.onDocumentMediaGroupContent(
initialFilter: CommonMessageFilter<DocumentMediaGroupContent>? = null,
initialFilter: CommonMessageFilter<DocumentMediaGroupPartContent>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, DocumentMediaGroupMessage, Update> = MessageFilterByChat,
markerFactory: MarkerFactory<in DocumentMediaGroupMessage, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, DocumentMediaGroupMessage>

View File

@ -222,7 +222,7 @@ suspend fun <BC : BehaviourContext> BC.onEditedVenue(
* data
*/
suspend fun <BC : BehaviourContext> BC.onEditedAudioMediaGroup(
initialFilter: CommonMessageFilter<AudioMediaGroupContent>? = null,
initialFilter: CommonMessageFilter<AudioMediaGroupPartContent>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, AudioMediaGroupMessage, Update> = MessageFilterByChat,
markerFactory: MarkerFactory<in AudioMediaGroupMessage, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, AudioMediaGroupMessage>
@ -246,7 +246,7 @@ suspend fun <BC : BehaviourContext> BC.onEditedAudioMediaGroup(
* data
*/
suspend fun <BC : BehaviourContext> BC.onEditedDocumentMediaGroupContent(
initialFilter: CommonMessageFilter<DocumentMediaGroupContent>? = null,
initialFilter: CommonMessageFilter<DocumentMediaGroupPartContent>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, DocumentMediaGroupMessage, Update> = MessageFilterByChat,
markerFactory: MarkerFactory<in DocumentMediaGroupMessage, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, DocumentMediaGroupMessage>

View File

@ -13,11 +13,20 @@ internal suspend inline fun <BC : BehaviourContext, reified T> BC.on(
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, T, Update>? = null,
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, T>,
noinline updateToData: (Update) -> List<T>?
) = flowsUpdatesFilter.expectFlow(bot) {
updateToData(it) ?.mapNotNull { data ->
if (initialFilter ?.invoke(data) != false) it to data else null
} ?: emptyList()
}.subscribeSafelyWithoutExceptionsAsync(
) = flowsUpdatesFilter.expectFlow(
bot,
filter = initialFilter ?.let {
{
updateToData(it) ?.mapNotNull { data ->
if (initialFilter(data)) it to data else null
} ?: emptyList()
}
} ?: {
updateToData(it) ?.mapNotNull { data ->
it to data
} ?: emptyList()
}
).subscribeSafelyWithoutExceptionsAsync(
scope,
{ markerFactory(it.second) }
) { (update, triggerData) ->

View File

@ -0,0 +1,164 @@
@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.utils.SimpleFilter
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
import dev.inmo.tgbotapi.extensions.utils.baseSentMessageUpdateOrNull
import dev.inmo.tgbotapi.extensions.utils.commonMessageOrNull
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
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.buildMediaGroupMessagesTrigger(
initialFilter: SimpleFilter<MediaGroupMessage<T>>? = null,
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MediaGroupMessage<T>, Update>? = null,
markerFactory: MarkerFactory<in MediaGroupMessage<T>, Any> = ByChatMessageMarkerFactory,
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MediaGroupMessage<T>>
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
it.baseSentMessageUpdateOrNull() ?.data ?.commonMessageOrNull() ?.withContentOrNull<MediaGroupContent<*>>() ?.let {
if (it.content.group.all { it.content is T }) {
listOf(it as MediaGroupMessage<T>)
} else {
null
}
} ?: emptyList()
}
/**
* @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.onMediaGroupMessages(
initialFilter: SimpleFilter<MediaGroupMessage<MediaGroupPartContent>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MediaGroupMessage<MediaGroupPartContent>, Update>? = null,
markerFactory: MarkerFactory<in MediaGroupMessage<MediaGroupPartContent>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MediaGroupMessage<MediaGroupPartContent>>
) = buildMediaGroupMessagesTrigger(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.onPlaylistMessages(
initialFilter: SimpleFilter<MediaGroupMessage<AudioMediaGroupPartContent>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MediaGroupMessage<AudioMediaGroupPartContent>, Update>? = null,
markerFactory: MarkerFactory<in MediaGroupMessage<AudioMediaGroupPartContent>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MediaGroupMessage<AudioMediaGroupPartContent>>
) = buildMediaGroupMessagesTrigger(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.onDocumentsGroupMessages(
initialFilter: SimpleFilter<MediaGroupMessage<DocumentMediaGroupPartContent>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MediaGroupMessage<DocumentMediaGroupPartContent>, Update>? = null,
markerFactory: MarkerFactory<in MediaGroupMessage<DocumentMediaGroupPartContent>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MediaGroupMessage<DocumentMediaGroupPartContent>>
) = buildMediaGroupMessagesTrigger(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.onVisualGalleryMessages(
initialFilter: SimpleFilter<MediaGroupMessage<VisualMediaGroupPartContent>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MediaGroupMessage<VisualMediaGroupPartContent>, Update>? = null,
markerFactory: MarkerFactory<in MediaGroupMessage<VisualMediaGroupPartContent>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MediaGroupMessage<VisualMediaGroupPartContent>>
) = buildMediaGroupMessagesTrigger(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.onVisualMediaGroupMessages(
initialFilter: SimpleFilter<MediaGroupMessage<VisualMediaGroupPartContent>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MediaGroupMessage<VisualMediaGroupPartContent>, Update>? = null,
markerFactory: MarkerFactory<in MediaGroupMessage<VisualMediaGroupPartContent>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MediaGroupMessage<VisualMediaGroupPartContent>>
) = onVisualGalleryMessages(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.onPhotoGalleryMessages(
initialFilter: SimpleFilter<MediaGroupMessage<PhotoContent>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MediaGroupMessage<PhotoContent>, Update>? = null,
markerFactory: MarkerFactory<in MediaGroupMessage<PhotoContent>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MediaGroupMessage<PhotoContent>>
) = buildMediaGroupMessagesTrigger(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.onVideoGalleryMessages(
initialFilter: SimpleFilter<MediaGroupMessage<VideoContent>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MediaGroupMessage<VideoContent>, Update>? = null,
markerFactory: MarkerFactory<in MediaGroupMessage<VideoContent>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MediaGroupMessage<VideoContent>>
) = buildMediaGroupMessagesTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)

View File

@ -3,28 +3,31 @@
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.AnyMarkerFactory
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
import dev.inmo.tgbotapi.extensions.utils.sentMediaGroupUpdateOrNull
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.extensions.utils.baseSentMessageUpdateOrNull
import dev.inmo.tgbotapi.extensions.utils.commonMessageOrNull
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
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 : MediaGroupContent> 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>>>
internal suspend inline fun <BC : BehaviourContext, reified T : MediaGroupPartContent> BC.buildMediaGroupTrigger(
initialFilter: SimpleFilter<MediaGroupContent<T>>? = null,
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MediaGroupContent<T>, Update>? = null,
markerFactory: MarkerFactory<in MediaGroupContent<T>, Any> = AnyMarkerFactory(),
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MediaGroupContent<T>>
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
(it.sentMediaGroupUpdateOrNull() ?.data ?.takeIf { messages ->
messages.all { message ->
message.content is T
it.baseSentMessageUpdateOrNull() ?.data ?.commonMessageOrNull() ?.withContentOrNull<MediaGroupContent<*>>() ?.let {
if (it.content.group.all { it.content is T }) {
listOf(it.content as MediaGroupContent<T>)
} else {
null
}
} as? List<MediaGroupMessage<T>>) ?.let(::listOfNotNull)
} ?: emptyList()
}
/**
@ -40,10 +43,10 @@ internal suspend inline fun <BC : BehaviourContext, reified T : MediaGroupConten
* data
*/
suspend fun <BC : BehaviourContext> BC.onMediaGroup(
initialFilter: SimpleFilter<List<MediaGroupMessage<MediaGroupContent>>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<MediaGroupContent>>, Update>? = MessagesFilterByChat,
markerFactory: MarkerFactory<in List<MediaGroupMessage<MediaGroupContent>>, Any> = ByChatMediaGroupMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<MediaGroupContent>>>
initialFilter: SimpleFilter<MediaGroupContent<MediaGroupPartContent>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MediaGroupContent<MediaGroupPartContent>, Update>? = null,
markerFactory: MarkerFactory<in MediaGroupContent<MediaGroupPartContent>, Any> = AnyMarkerFactory(),
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MediaGroupContent<MediaGroupPartContent>>
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
@ -59,10 +62,10 @@ suspend fun <BC : BehaviourContext> BC.onMediaGroup(
* data
*/
suspend fun <BC : BehaviourContext> BC.onPlaylist(
initialFilter: SimpleFilter<List<MediaGroupMessage<AudioMediaGroupContent>>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<AudioMediaGroupContent>>, Update>? = MessagesFilterByChat,
markerFactory: MarkerFactory<in List<MediaGroupMessage<AudioMediaGroupContent>>, Any> = ByChatMediaGroupMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<AudioMediaGroupContent>>>
initialFilter: SimpleFilter<MediaGroupContent<AudioMediaGroupPartContent>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MediaGroupContent<AudioMediaGroupPartContent>, Update>? = null,
markerFactory: MarkerFactory<in MediaGroupContent<AudioMediaGroupPartContent>, Any> = AnyMarkerFactory(),
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MediaGroupContent<AudioMediaGroupPartContent>>
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
@ -78,10 +81,10 @@ suspend fun <BC : BehaviourContext> BC.onPlaylist(
* data
*/
suspend fun <BC : BehaviourContext> BC.onDocumentsGroup(
initialFilter: SimpleFilter<List<MediaGroupMessage<DocumentMediaGroupContent>>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<DocumentMediaGroupContent>>, Update>? = MessagesFilterByChat,
markerFactory: MarkerFactory<in List<MediaGroupMessage<DocumentMediaGroupContent>>, Any> = ByChatMediaGroupMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<DocumentMediaGroupContent>>>
initialFilter: SimpleFilter<MediaGroupContent<DocumentMediaGroupPartContent>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MediaGroupContent<DocumentMediaGroupPartContent>, Update>? = null,
markerFactory: MarkerFactory<in MediaGroupContent<DocumentMediaGroupPartContent>, Any> = AnyMarkerFactory(),
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MediaGroupContent<DocumentMediaGroupPartContent>>
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
@ -97,10 +100,10 @@ suspend fun <BC : BehaviourContext> BC.onDocumentsGroup(
* data
*/
suspend fun <BC : BehaviourContext> BC.onVisualGallery(
initialFilter: SimpleFilter<List<MediaGroupMessage<VisualMediaGroupContent>>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<VisualMediaGroupContent>>, Update>? = MessagesFilterByChat,
markerFactory: MarkerFactory<in List<MediaGroupMessage<VisualMediaGroupContent>>, Any> = ByChatMediaGroupMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<VisualMediaGroupContent>>>
initialFilter: SimpleFilter<MediaGroupContent<VisualMediaGroupPartContent>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MediaGroupContent<VisualMediaGroupPartContent>, Update>? = null,
markerFactory: MarkerFactory<in MediaGroupContent<VisualMediaGroupPartContent>, Any> = AnyMarkerFactory(),
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MediaGroupContent<VisualMediaGroupPartContent>>
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
@ -116,10 +119,10 @@ suspend fun <BC : BehaviourContext> BC.onVisualGallery(
* data
*/
suspend fun <BC : BehaviourContext> BC.onVisualMediaGroup(
initialFilter: SimpleFilter<List<MediaGroupMessage<VisualMediaGroupContent>>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<VisualMediaGroupContent>>, Update>? = MessagesFilterByChat,
markerFactory: MarkerFactory<in List<MediaGroupMessage<VisualMediaGroupContent>>, Any> = ByChatMediaGroupMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<VisualMediaGroupContent>>>
initialFilter: SimpleFilter<MediaGroupContent<VisualMediaGroupPartContent>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MediaGroupContent<VisualMediaGroupPartContent>, Update>? = null,
markerFactory: MarkerFactory<in MediaGroupContent<VisualMediaGroupPartContent>, Any> = AnyMarkerFactory(),
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MediaGroupContent<VisualMediaGroupPartContent>>
) = onVisualGallery(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
@ -135,10 +138,10 @@ suspend fun <BC : BehaviourContext> BC.onVisualMediaGroup(
* 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>>>
initialFilter: SimpleFilter<MediaGroupContent<PhotoContent>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MediaGroupContent<PhotoContent>, Update>? = null,
markerFactory: MarkerFactory<in MediaGroupContent<PhotoContent>, Any> = AnyMarkerFactory(),
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MediaGroupContent<PhotoContent>>
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
@ -154,8 +157,8 @@ suspend fun <BC : BehaviourContext> BC.onPhotoGallery(
* 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>>>
initialFilter: SimpleFilter<MediaGroupContent<VideoContent>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, MediaGroupContent<VideoContent>, Update>? = null,
markerFactory: MarkerFactory<in MediaGroupContent<VideoContent>, Any> = AnyMarkerFactory(),
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, MediaGroupContent<VideoContent>>
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)

View File

@ -0,0 +1,5 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
private val commonAnyMarker = MarkerFactory<Any, Any> { it }
fun <T> AnyMarkerFactory() = commonAnyMarker as MarkerFactory<T, T>

View File

@ -1,8 +0,0 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
object ByChatMediaGroupMarkerFactory : MarkerFactory<List<MediaGroupMessage<*>>, Any> {
override suspend fun invoke(data: List<MediaGroupMessage<*>>) = data.chat ?: error("Data must not be empty")
}

View File

@ -6,22 +6,30 @@ import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest
import dev.inmo.tgbotapi.requests.send.media.base.*
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.media.*
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializerClass
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupPartContent
import dev.inmo.tgbotapi.types.message.content.AudioContent
import dev.inmo.tgbotapi.types.message.content.DocumentContent
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.extensions.asMediaGroupMessage
import kotlinx.serialization.*
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.buildJsonArray
import kotlinx.serialization.json.jsonPrimitive
const val rawSendingMediaGroupsWarning = "Media groups contains restrictions related to combinations of media" +
" types. Currently it is possible to combine photo + video OR audio OR documents"
@RiskFeature(rawSendingMediaGroupsWarning)
fun <T : MediaGroupContent> SendMediaGroup(
fun <T : MediaGroupPartContent> SendMediaGroup(
chatId: ChatIdentifier,
media: List<MediaGroupMemberTelegramMedia>,
threadId: MessageThreadId? = null,
@ -29,7 +37,7 @@ fun <T : MediaGroupContent> SendMediaGroup(
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null
): Request<List<MediaGroupMessage<T>>> {
): Request<PossiblySentViaBotCommonMessage<T>> {
if (media.size !in mediaCountInMediaGroup) {
throwRangeError("Count of members in media group", mediaCountInMediaGroup, media.size)
}
@ -62,7 +70,7 @@ fun <T : MediaGroupContent> SendMediaGroup(
data,
SendMediaGroupFiles(files)
)
}) as Request<List<MediaGroupMessage<T>>>
}) as Request<PossiblySentViaBotCommonMessage<T>>
}
/**
@ -112,10 +120,22 @@ inline fun SendVisualMediaGroup(
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null
) = SendMediaGroup<VisualMediaGroupContent>(chatId, media, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply)
) = SendMediaGroup<VisualMediaGroupPartContent>(chatId, media, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply)
private val messagesListSerializer: KSerializer<List<MediaGroupMessage<MediaGroupContent>>>
= ListSerializer(TelegramBotAPIMessageDeserializeOnlySerializerClass())
private object MessagesListSerializer: KSerializer<PossiblySentViaBotCommonMessage<MediaGroupContent<MediaGroupPartContent>>> {
private val serializer = ListSerializer(TelegramBotAPIMessageDeserializeOnlySerializerClass<PossiblySentViaBotCommonMessage<MediaGroupPartContent>>())
override val descriptor: SerialDescriptor = serializer.descriptor
override fun deserialize(decoder: Decoder): PossiblySentViaBotCommonMessage<MediaGroupContent<MediaGroupPartContent>> {
val messages = serializer.deserialize(decoder)
return messages.asMediaGroupMessage()
}
override fun serialize(encoder: Encoder, value: PossiblySentViaBotCommonMessage<MediaGroupContent<MediaGroupPartContent>>) {
serializer.serialize(encoder, value.content.group.map { it.sourceMessage })
}
}
@Serializable
data class SendMediaGroupData internal constructor(
@ -132,7 +152,8 @@ data class SendMediaGroupData internal constructor(
override val replyToMessageId: MessageId? = null,
@SerialName(allowSendingWithoutReplyField)
override val allowSendingWithoutReply: Boolean? = null
) : DataRequest<List<MediaGroupMessage<MediaGroupContent>>>, SendMessageRequest<List<MediaGroupMessage<MediaGroupContent>>> {
) : DataRequest<PossiblySentViaBotCommonMessage<MediaGroupContent<MediaGroupPartContent>>>,
SendMessageRequest<PossiblySentViaBotCommonMessage<MediaGroupContent<MediaGroupPartContent>>> {
@SerialName(mediaField)
private val convertedMedia: String
get() = buildJsonArray {
@ -145,8 +166,8 @@ data class SendMediaGroupData internal constructor(
override fun method(): String = "sendMediaGroup"
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override val resultDeserializer: DeserializationStrategy<List<MediaGroupMessage<MediaGroupContent>>>
get() = messagesListSerializer
override val resultDeserializer: DeserializationStrategy<PossiblySentViaBotCommonMessage<MediaGroupContent<MediaGroupPartContent>>>
get() = MessagesListSerializer
}
data class SendMediaGroupFiles internal constructor(

View File

@ -151,6 +151,7 @@ const val chatIdField = "chat_id"
const val senderChatIdField = "sender_chat_id"
const val messageIdField = "message_id"
const val messageThreadIdField = "message_thread_id"
const val mediaGroupIdField = "media_group_id"
const val updateIdField = "update_id"
const val fromChatIdField = "from_chat_id"
const val disableWebPagePreviewField = "disable_web_page_preview"

View File

@ -19,5 +19,6 @@ data class ChannelContentMessageImpl<T: MessageContent>(
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?,
override val senderBot: CommonBot?,
override val authorSignature: AuthorSignature?
override val authorSignature: AuthorSignature?,
override val mediaGroupId: MediaGroupIdentifier?,
) : ChannelContentMessage<T>

View File

@ -1,25 +0,0 @@
package dev.inmo.tgbotapi.types.message
import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.chat.Chat
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
data class ChannelMediaGroupMessage<T : MediaGroupContent>(
override val messageId: MessageId,
override val threadId: MessageThreadId?,
override val chat: Chat,
override val date: DateTime,
override val mediaGroupId: MediaGroupIdentifier,
override val content: T,
override val editDate: DateTime?,
override val hasProtectedContent: Boolean,
override val forwardInfo: ForwardInfo?,
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?
) : MediaGroupMessage<T>

View File

@ -1,24 +0,0 @@
package dev.inmo.tgbotapi.types.message
import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.chat.Chat
import dev.inmo.tgbotapi.types.chat.User
import dev.inmo.tgbotapi.types.message.abstracts.*
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
data class CommonMediaGroupMessage<T : MediaGroupContent>(
override val messageId: MessageId,
override val threadId: MessageThreadId?,
override val from: User,
override val chat: Chat,
override val date: DateTime,
override val mediaGroupId: MediaGroupIdentifier,
override val content: T,
override val editDate: DateTime?,
override val hasProtectedContent: Boolean,
override val forwardInfo: ForwardInfo?,
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?
) : MediaGroupMessage<T>, FromUserMessage

View File

@ -21,7 +21,8 @@ data class ConnectedFromChannelGroupContentMessageImpl<T : MessageContent>(
override val replyMarkup: InlineKeyboardMarkup?,
override val content: T,
override val senderBot: CommonBot?,
override val authorSignature: AuthorSignature?
override val authorSignature: AuthorSignature?,
override val mediaGroupId: MediaGroupIdentifier?,
) : ConnectedFromChannelGroupContentMessage<T>
data class UnconnectedFromChannelGroupContentMessageImpl<T: MessageContent>(
@ -36,7 +37,8 @@ data class UnconnectedFromChannelGroupContentMessageImpl<T: MessageContent>(
override val replyMarkup: InlineKeyboardMarkup?,
override val content: T,
override val senderBot: CommonBot?,
override val authorSignature: AuthorSignature?
override val authorSignature: AuthorSignature?,
override val mediaGroupId: MediaGroupIdentifier?,
) : UnconnectedFromChannelGroupContentMessage<T>
data class AnonymousGroupContentMessageImpl<T : MessageContent>(
@ -50,7 +52,8 @@ data class AnonymousGroupContentMessageImpl<T : MessageContent>(
override val replyMarkup: InlineKeyboardMarkup?,
override val content: T,
override val senderBot: CommonBot?,
override val authorSignature: AuthorSignature?
override val authorSignature: AuthorSignature?,
override val mediaGroupId: MediaGroupIdentifier?,
) : AnonymousGroupContentMessage<T>
data class CommonGroupContentMessageImpl<T : MessageContent>(
@ -64,7 +67,8 @@ data class CommonGroupContentMessageImpl<T : MessageContent>(
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?,
override val content: T,
override val senderBot: CommonBot?
override val senderBot: CommonBot?,
override val mediaGroupId: MediaGroupIdentifier?,
) : CommonGroupContentMessage<T>
data class FromChannelForumContentMessageImpl<T: MessageContent>(
@ -80,7 +84,8 @@ data class FromChannelForumContentMessageImpl<T: MessageContent>(
override val replyMarkup: InlineKeyboardMarkup?,
override val content: T,
override val senderBot: CommonBot?,
override val authorSignature: AuthorSignature?
override val authorSignature: AuthorSignature?,
override val mediaGroupId: MediaGroupIdentifier?,
) : FromChannelForumContentMessage<T>
data class AnonymousForumContentMessageImpl<T : MessageContent>(
@ -95,7 +100,8 @@ data class AnonymousForumContentMessageImpl<T : MessageContent>(
override val replyMarkup: InlineKeyboardMarkup?,
override val content: T,
override val senderBot: CommonBot?,
override val authorSignature: AuthorSignature?
override val authorSignature: AuthorSignature?,
override val mediaGroupId: MediaGroupIdentifier?,
) : AnonymousForumContentMessage<T>
data class CommonForumContentMessageImpl<T : MessageContent>(
@ -110,5 +116,6 @@ data class CommonForumContentMessageImpl<T : MessageContent>(
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?,
override val content: T,
override val senderBot: CommonBot?
override val senderBot: CommonBot?,
override val mediaGroupId: MediaGroupIdentifier?,
) : CommonForumContentMessage<T>

View File

@ -21,5 +21,6 @@ data class PrivateContentMessageImpl<T: MessageContent>(
override val forwardInfo: ForwardInfo?,
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?,
override val senderBot: CommonBot?
override val senderBot: CommonBot?,
override val mediaGroupId: MediaGroupIdentifier?,
) : PrivateContentMessage<T>

View File

@ -269,45 +269,7 @@ internal data class RawMessage(
)
else -> error("Expected one of the public chats, but was $chat (in extracting of chat event message)")
}
} ?: content?.let { content ->
media_group_id?.let {
val checkedContent = when (content) {
is PhotoContent -> content
is VideoContent -> content
is AudioContent -> content
is DocumentContent -> content
else -> error("Unsupported content for media group")
}
when (from) {
null -> ChannelMediaGroupMessage(
messageId,
messageThreadId,
chat,
date.asDate,
it,
checkedContent,
edit_date?.asDate,
has_protected_content == true,
forwarded,
reply_to_message?.asMessage,
reply_markup
)
else -> CommonMediaGroupMessage(
messageId,
messageThreadId,
from,
chat,
date.asDate,
it,
checkedContent,
edit_date?.asDate,
has_protected_content == true,
forwarded,
reply_to_message?.asMessage,
reply_markup
)
}
} ?: when (chat) {
} ?: content?.let { content -> when (chat) {
is PublicChat -> when (chat) {
is ChannelChat -> ChannelContentMessageImpl(
messageId,
@ -320,7 +282,8 @@ internal data class RawMessage(
reply_to_message?.asMessage,
reply_markup,
via_bot,
author_signature
author_signature,
media_group_id
)
is ForumChat -> if (messageThreadId != null) {
when (sender_chat) {
@ -337,7 +300,8 @@ internal data class RawMessage(
reply_markup,
content,
via_bot,
author_signature
author_signature,
media_group_id
)
is GroupChat -> AnonymousForumContentMessageImpl(
chat,
@ -351,7 +315,8 @@ internal data class RawMessage(
reply_markup,
content,
via_bot,
author_signature
author_signature,
media_group_id
)
null -> CommonForumContentMessageImpl(
chat,
@ -365,7 +330,8 @@ internal data class RawMessage(
reply_to_message ?.asMessage,
reply_markup,
content,
via_bot
via_bot,
media_group_id
)
}
} else {
@ -383,7 +349,8 @@ internal data class RawMessage(
reply_markup,
content,
via_bot,
author_signature
author_signature,
media_group_id
)
} else {
UnconnectedFromChannelGroupContentMessageImpl(
@ -398,7 +365,8 @@ internal data class RawMessage(
reply_markup,
content,
via_bot,
author_signature
author_signature,
media_group_id
)
}
is GroupChat -> AnonymousGroupContentMessageImpl(
@ -412,7 +380,8 @@ internal data class RawMessage(
reply_markup,
content,
via_bot,
author_signature
author_signature,
media_group_id
)
null -> CommonGroupContentMessageImpl(
chat,
@ -425,7 +394,8 @@ internal data class RawMessage(
reply_to_message ?.asMessage,
reply_markup,
content,
via_bot
via_bot,
media_group_id
)
}
}
@ -443,7 +413,8 @@ internal data class RawMessage(
reply_markup,
content,
via_bot,
author_signature
author_signature,
media_group_id
)
} else {
UnconnectedFromChannelGroupContentMessageImpl(
@ -458,7 +429,8 @@ internal data class RawMessage(
reply_markup,
content,
via_bot,
author_signature
author_signature,
media_group_id
)
}
is GroupChat -> AnonymousGroupContentMessageImpl(
@ -472,7 +444,8 @@ internal data class RawMessage(
reply_markup,
content,
via_bot,
author_signature
author_signature,
media_group_id
)
null -> CommonGroupContentMessageImpl(
chat,
@ -485,7 +458,8 @@ internal data class RawMessage(
reply_to_message ?.asMessage,
reply_markup,
content,
via_bot
via_bot,
media_group_id
)
}
}
@ -500,7 +474,8 @@ internal data class RawMessage(
forwarded,
reply_to_message?.asMessage,
reply_markup,
via_bot
via_bot,
media_group_id
)
else -> error("Unknown type of chat: $chat")
}

View File

@ -2,9 +2,10 @@ package dev.inmo.tgbotapi.types.message.abstracts
import dev.inmo.tgbotapi.types.message.content.MessageContent
interface CommonMessage<T: MessageContent> : Message,
sealed interface CommonMessage<T: MessageContent> : Message,
PossiblyForwardedMessage,
PossiblyEditedMessage,
PossiblyReplyMessage,
PossiblyMarkedUp,
PossiblyMediaGroupMessage<T>,
ContentMessage<T>

View File

@ -1,10 +0,0 @@
package dev.inmo.tgbotapi.types.message.abstracts
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
interface MediaGroupMessage<T : MediaGroupContent> : CommonMessage<T> {
val mediaGroupId: MediaGroupIdentifier
val threadId: MessageThreadId?
}

View File

@ -0,0 +1,8 @@
package dev.inmo.tgbotapi.types.message.abstracts
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
import dev.inmo.tgbotapi.types.message.content.MessageContent
interface PossiblyMediaGroupMessage<T : MessageContent> : ContentMessage<T> {
val mediaGroupId: MediaGroupIdentifier?
}

View File

@ -2,4 +2,4 @@ package dev.inmo.tgbotapi.types.message.abstracts
import dev.inmo.tgbotapi.types.message.content.MessageContent
interface PossiblySentViaBotCommonMessage<T: MessageContent> : CommonMessage<T>, PossiblySentViaBot
sealed interface PossiblySentViaBotCommonMessage<T: MessageContent> : CommonMessage<T>, PossiblySentViaBot

View File

@ -3,6 +3,6 @@ package dev.inmo.tgbotapi.types.message.abstracts
import dev.inmo.tgbotapi.types.chat.PublicChat
import dev.inmo.tgbotapi.types.message.content.MessageContent
interface PublicContentMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T> {
sealed interface PublicContentMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T> {
override val chat: PublicChat
}

View File

@ -16,10 +16,10 @@ sealed interface MessageContent: ResendableContent {
companion object {
@RiskFeature("This serialization module can be changed in near releases")
fun serializationModule(
visualMediaGroupContentAdditionalBuilder: PolymorphicModuleBuilder<VisualMediaGroupContent>.() -> Unit = {},
documentMediaGroupContentAdditionalBuilder: PolymorphicModuleBuilder<DocumentMediaGroupContent>.() -> Unit = {},
audioMediaGroupContentAdditionalBuilder: PolymorphicModuleBuilder<AudioMediaGroupContent>.() -> Unit = {},
mediaGroupContentAdditionalBuilder: PolymorphicModuleBuilder<MediaGroupContent>.() -> Unit = {},
visualMediaGroupContentAdditionalBuilder: PolymorphicModuleBuilder<VisualMediaGroupPartContent>.() -> Unit = {},
documentMediaGroupContentAdditionalBuilder: PolymorphicModuleBuilder<DocumentMediaGroupPartContent>.() -> Unit = {},
audioMediaGroupContentAdditionalBuilder: PolymorphicModuleBuilder<AudioMediaGroupPartContent>.() -> Unit = {},
mediaGroupPartContentAdditionalBuilder: PolymorphicModuleBuilder<MediaGroupPartContent>.() -> Unit = {},
textedMediaContentAdditionalBuilder: PolymorphicModuleBuilder<TextedMediaContent>.() -> Unit = {},
mediaContentAdditionalBuilder: PolymorphicModuleBuilder<MediaContent>.() -> Unit = {},
mediaCollectionContentAdditionalBuilder: PolymorphicModuleBuilder<MediaCollectionContent<*>>.() -> Unit = {},
@ -74,24 +74,24 @@ sealed interface MessageContent: ResendableContent {
textedMediaContentAdditionalBuilder()
}
polymorphic(MediaGroupContent::class) {
polymorphic(MediaGroupPartContent::class) {
subclass(PhotoContent::class)
subclass(AudioContent::class)
subclass(DocumentContent::class)
mediaGroupContentAdditionalBuilder()
mediaGroupPartContentAdditionalBuilder()
}
polymorphic(AudioMediaGroupContent::class) {
polymorphic(AudioMediaGroupPartContent::class) {
subclass(AudioContent::class)
audioMediaGroupContentAdditionalBuilder()
}
polymorphic(DocumentMediaGroupContent::class) {
polymorphic(DocumentMediaGroupPartContent::class) {
subclass(DocumentContent::class)
documentMediaGroupContentAdditionalBuilder()
}
polymorphic(VisualMediaGroupContent::class) {
polymorphic(VisualMediaGroupPartContent::class) {
subclass(PhotoContent::class)
subclass(VideoContent::class)

View File

@ -1,28 +1,44 @@
package dev.inmo.tgbotapi.types.message.content
import dev.inmo.tgbotapi.abstracts.TextedInput
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.files.AudioFile
import dev.inmo.tgbotapi.types.files.DocumentFile
import dev.inmo.tgbotapi.types.media.*
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage
import kotlinx.serialization.Serializable
sealed interface AudioMediaGroupContent : MediaGroupContent {
sealed interface AudioMediaGroupPartContent : MediaGroupPartContent {
override val media: AudioFile
override fun toMediaGroupMemberTelegramMedia(): AudioMediaGroupMemberTelegramMedia
}
sealed interface DocumentMediaGroupContent : MediaGroupContent {
sealed interface DocumentMediaGroupPartContent : MediaGroupPartContent {
override val media: DocumentFile
override fun toMediaGroupMemberTelegramMedia(): DocumentMediaGroupMemberTelegramMedia
}
sealed interface MediaGroupContent : TextedMediaContent {
sealed interface TextedMediaContent : MediaContent, TextedInput
sealed interface MediaGroupCollectionContent<T : MediaGroupPartContent> : TextedMediaContent {
@Serializable
data class PartWrapper<T : MediaGroupPartContent>(
val messageId: MessageId,
val content: T,
val sourceMessage: PossiblySentViaBotCommonMessage<T>
)
val group: List<PartWrapper<T>>
val mediaGroupId: MediaGroupIdentifier
}
sealed interface MediaGroupPartContent : TextedMediaContent {
fun toMediaGroupMemberTelegramMedia(): MediaGroupMemberTelegramMedia
}
sealed interface TextedMediaContent : MediaContent, TextedInput
sealed interface VisualMediaGroupContent : MediaGroupContent {
sealed interface VisualMediaGroupPartContent : MediaGroupPartContent {
override fun toMediaGroupMemberTelegramMedia(): VisualMediaGroupMemberTelegramMedia
}

View File

@ -18,7 +18,7 @@ data class AudioContent(
override val media: AudioFile,
override val text: String? = null,
override val textSources: TextSourcesList = emptyList()
) : AudioMediaGroupContent {
) : AudioMediaGroupPartContent {
override fun createResend(
chatId: ChatIdentifier,
messageThreadId: MessageThreadId?,

View File

@ -20,7 +20,7 @@ data class DocumentContent(
override val media: DocumentFile,
override val text: String? = null,
override val textSources: TextSourcesList = emptyList()
) : DocumentMediaGroupContent {
) : DocumentMediaGroupPartContent {
override fun createResend(
chatId: ChatIdentifier,
messageThreadId: MessageThreadId?,

View File

@ -0,0 +1,50 @@
package dev.inmo.tgbotapi.types.message.content
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.requests.send.media.SendMediaGroup
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.files.TelegramMediaFile
import dev.inmo.tgbotapi.types.media.TelegramMedia
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.textsources.TextSource
import kotlinx.serialization.Serializable
@Serializable
data class MediaGroupContent<T : MediaGroupPartContent>(
override val group: List<MediaGroupCollectionContent.PartWrapper<T>>,
override val mediaGroupId: MediaGroupIdentifier
) : MediaGroupCollectionContent<T> {
val mainContent: MediaGroupPartContent
get() = group.first().content
override val media: TelegramMediaFile
get() = mainContent.media
override val textSources: List<TextSource>
get() = mainContent.textSources
override val text: String?
get() = mainContent.text
override fun asTelegramMedia(): TelegramMedia = mainContent.asTelegramMedia()
override fun createResend(
chatId: ChatIdentifier,
threadId: MessageThreadId?,
disableNotification: Boolean,
protectContent: Boolean,
replyToMessageId: MessageId?,
allowSendingWithoutReply: Boolean?,
replyMarkup: KeyboardMarkup?
): Request<out Message> = SendMediaGroup<MediaGroupPartContent>(
chatId,
group.map { it.content.toMediaGroupMemberTelegramMedia() },
threadId,
disableNotification,
protectContent,
replyToMessageId,
allowSendingWithoutReply
)
}

View File

@ -18,7 +18,7 @@ data class PhotoContent(
override val mediaCollection: Photo,
override val text: String? = null,
override val textSources: TextSourcesList = emptyList()
) : MediaCollectionContent<PhotoSize>, VisualMediaGroupContent {
) : MediaCollectionContent<PhotoSize>, VisualMediaGroupPartContent {
override val media: PhotoSize = mediaCollection.biggest() ?: throw IllegalStateException("Can't locate any photo size for this content")
override fun createResend(

View File

@ -20,12 +20,12 @@ typealias VideoNoteMessage = CommonMessage<VideoNoteContent>
typealias StickerMessage = CommonMessage<StickerContent>
typealias TextedMediaMessage = CommonMessage<TextedMediaContent>
typealias VoiceMessage = CommonMessage<VoiceContent>
typealias MediaGroupMessage = CommonMessage<MediaGroupContent>
typealias AudioMediaGroupMessage = CommonMessage<AudioMediaGroupContent>
typealias MediaGroupMessage<T> = CommonMessage<MediaGroupContent<T>>
typealias AudioMediaGroupMessage = CommonMessage<AudioMediaGroupPartContent>
typealias AudioMessage = CommonMessage<AudioContent>
typealias DocumentMediaGroupMessage = CommonMessage<DocumentMediaGroupContent>
typealias DocumentMediaGroupMessage = CommonMessage<DocumentMediaGroupPartContent>
typealias DocumentMessage = CommonMessage<DocumentContent>
typealias VisualMediaGroupMessage = CommonMessage<VisualMediaGroupContent>
typealias VisualMediaGroupMessage = CommonMessage<VisualMediaGroupPartContent>
typealias VideoMessage = CommonMessage<VideoContent>
typealias PhotoMessage = CommonMessage<PhotoContent>
typealias AnimationMessage = CommonMessage<AnimationContent>

View File

@ -18,7 +18,7 @@ data class VideoContent(
override val media: VideoFile,
override val text: String? = null,
override val textSources: TextSourcesList = emptyList()
) : VisualMediaGroupContent {
) : VisualMediaGroupPartContent {
override fun createResend(
chatId: ChatIdentifier,
messageThreadId: MessageThreadId?,

View File

@ -7,4 +7,6 @@ import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
data class ChannelPostUpdate(
override val updateId: UpdateIdentifier,
override val data: Message
) : BaseSentMessageUpdate
) : BaseSentMessageUpdate {
override fun copy(newData: Message): BaseSentMessageUpdate = copy(updateId, newData)
}

View File

@ -7,4 +7,6 @@ import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
data class MessageUpdate(
override val updateId: UpdateIdentifier,
override val data: Message
) : BaseSentMessageUpdate
) : BaseSentMessageUpdate {
override fun copy(newData: Message) = copy(updateId, newData)
}

View File

@ -1,3 +1,7 @@
package dev.inmo.tgbotapi.types.update.abstracts
interface BaseSentMessageUpdate : BaseMessageUpdate
import dev.inmo.tgbotapi.types.message.abstracts.Message
interface BaseSentMessageUpdate : BaseMessageUpdate {
fun copy(newData: Message): BaseSentMessageUpdate
}

View File

@ -1,13 +0,0 @@
package dev.inmo.tgbotapi.types.update.media_group
import dev.inmo.tgbotapi.types.UpdateIdentifier
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate
data class ChannelPostMediaGroupUpdate(
override val origins: List<BaseMessageUpdate>
) : SentMediaGroupUpdate {
override val updateId: UpdateIdentifier = origins.last().updateId
override val data: List<MediaGroupMessage<MediaGroupContent>> = origins.mapNotNull { it.data as? MediaGroupMessage<MediaGroupContent> }
}

View File

@ -1,13 +0,0 @@
package dev.inmo.tgbotapi.types.update.media_group
import dev.inmo.tgbotapi.types.UpdateIdentifier
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
import dev.inmo.tgbotapi.types.update.EditChannelPostUpdate
data class EditChannelPostMediaGroupUpdate(
override val origin: EditChannelPostUpdate
) : EditMediaGroupUpdate {
override val updateId: UpdateIdentifier = origin.updateId
override val data: MediaGroupMessage<MediaGroupContent> = origin.data as MediaGroupMessage<MediaGroupContent>
}

View File

@ -1,13 +0,0 @@
package dev.inmo.tgbotapi.types.update.media_group
import dev.inmo.tgbotapi.types.UpdateIdentifier
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
import dev.inmo.tgbotapi.types.update.EditMessageUpdate
data class EditMessageMediaGroupUpdate(
override val origin: EditMessageUpdate
) : EditMediaGroupUpdate {
override val updateId: UpdateIdentifier = origin.updateId
override val data: MediaGroupMessage<MediaGroupContent> = origin.data as MediaGroupMessage<MediaGroupContent>
}

View File

@ -1,24 +0,0 @@
package dev.inmo.tgbotapi.types.update.media_group
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
import dev.inmo.tgbotapi.types.update.abstracts.*
/**
* By default there is no instances of objects which could be deserialized from raw updates. If you want to get objects
* with this type, you should use something like [dev.inmo.tgbotapi.extensions.api.SetWebhookKt.includeWebhookInRoute]
*
* @see dev.inmo.tgbotapi.extensions.api.SetWebhookKt.includeWebhookInRoute
* @see dev.inmo.tgbotapi.extensions.api.updates.UpdatesPollingKt.startGettingOfUpdates
*/
sealed interface MediaGroupUpdate : Update
sealed interface SentMediaGroupUpdate: MediaGroupUpdate {
override val data: List<MediaGroupMessage<MediaGroupContent>>
val origins: List<BaseMessageUpdate>
}
sealed interface EditMediaGroupUpdate : BaseEditMessageUpdate, MediaGroupUpdate {
override val data: MediaGroupMessage<MediaGroupContent>
val origin: BaseMessageUpdate
}

View File

@ -1,13 +0,0 @@
package dev.inmo.tgbotapi.types.update.media_group
import dev.inmo.tgbotapi.types.UpdateIdentifier
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate
data class MessageMediaGroupUpdate(
override val origins: List<BaseMessageUpdate>
) : SentMediaGroupUpdate {
override val updateId: UpdateIdentifier = origins.last().updateId
override val data: List<MediaGroupMessage<MediaGroupContent>> = origins.mapNotNull { it.data as? MediaGroupMessage<MediaGroupContent> }
}

View File

@ -2,10 +2,11 @@ package dev.inmo.tgbotapi.updateshandlers
import dev.inmo.micro_utils.coroutines.plus
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.abstracts.BaseSentMessageUpdate
import dev.inmo.tgbotapi.types.update.abstracts.UnknownUpdate
import dev.inmo.tgbotapi.types.update.abstracts.Update
import dev.inmo.tgbotapi.types.update.media_group.*
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.flow.*
@ -13,16 +14,22 @@ interface FlowsUpdatesFilter : UpdatesFilter {
override val allowedUpdates: List<String>
get() = ALL_UPDATES_LIST
val allUpdatesFlow: Flow<Update>
@Deprecated("Since 4.0.0 is not actual", ReplaceWith("allUpdatesFlow"))
val allUpdatesWithoutMediaGroupsGroupingFlow: Flow<Update>
get() = allUpdatesFlow
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 editedMessageMediaGroupsFlow: Flow<EditMessageMediaGroupUpdate>
val editedMessageMediaGroupsFlow: Flow<EditMessageUpdate>
get() = editedMessagesFlow.filter { (it.data as? PossiblySentViaBotCommonMessage<*>) ?.mediaGroupId != null }
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 editedChannelPostMediaGroupsFlow: Flow<EditChannelPostMediaGroupUpdate>
val editedChannelPostMediaGroupsFlow: Flow<EditChannelPostUpdate>
get() = editedChannelPostsFlow.filter { (it.data as? PossiblySentViaBotCommonMessage<*>) ?.mediaGroupId != null }
val chosenInlineResultsFlow: Flow<ChosenInlineResultUpdate>
val inlineQueriesFlow: Flow<InlineQueryUpdate>
val callbackQueriesFlow: Flow<CallbackQueryUpdate>
@ -37,23 +44,10 @@ interface FlowsUpdatesFilter : UpdatesFilter {
}
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 messageMediaGroupsFlow: Flow<MessageMediaGroupUpdate> 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 channelPostMediaGroupsFlow: Flow<ChannelPostMediaGroupUpdate> 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 inlineQueriesFlow: Flow<InlineQueryUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
override val callbackQueriesFlow: Flow<CallbackQueryUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
@ -92,14 +86,6 @@ class DefaultFlowsUpdatesFilter(
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
}

View File

@ -1,10 +1,6 @@
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.media_group.*
typealias UpdateReceiver<T> = suspend (T) -> Unit
@ -12,111 +8,3 @@ interface UpdatesFilter {
val asUpdateReceiver: UpdateReceiver<Update>
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
)

View File

@ -0,0 +1,170 @@
package dev.inmo.tgbotapi.utils.extensions
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
import dev.inmo.tgbotapi.types.message.AnonymousForumContentMessageImpl
import dev.inmo.tgbotapi.types.message.AnonymousGroupContentMessageImpl
import dev.inmo.tgbotapi.types.message.ChannelContentMessageImpl
import dev.inmo.tgbotapi.types.message.CommonForumContentMessageImpl
import dev.inmo.tgbotapi.types.message.CommonGroupContentMessageImpl
import dev.inmo.tgbotapi.types.message.ConnectedFromChannelGroupContentMessageImpl
import dev.inmo.tgbotapi.types.message.FromChannelForumContentMessageImpl
import dev.inmo.tgbotapi.types.message.PrivateContentMessageImpl
import dev.inmo.tgbotapi.types.message.UnconnectedFromChannelGroupContentMessageImpl
import dev.inmo.tgbotapi.types.message.abstracts.AnonymousForumContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.AnonymousGroupContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.ChannelContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.CommonForumContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.CommonGroupContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
import dev.inmo.tgbotapi.types.message.abstracts.ConnectedFromChannelGroupContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.FromChannelForumContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage
import dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.UnconnectedFromChannelGroupContentMessage
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.utils.RiskFeature
@RiskFeature("This API is experimental and can be changed without any notice, use with caution")
fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMediaGroupMessage(): PossiblySentViaBotCommonMessage<MediaGroupContent<T>> {
val sourceMessage = first()
val content = MediaGroupContent(
map { MediaGroupCollectionContent.PartWrapper(it.messageId, it.content, it) },
sourceMessage.mediaGroupId ?: error("Can't create media group message with the first message without media group id")
)
return when (sourceMessage) {
is ChannelContentMessage -> ChannelContentMessageImpl(
sourceMessage.messageId,
sourceMessage.chat,
content,
sourceMessage.date,
sourceMessage.editDate,
sourceMessage.hasProtectedContent,
sourceMessage.forwardInfo,
sourceMessage.replyTo,
sourceMessage.replyMarkup,
sourceMessage.senderBot,
sourceMessage.authorSignature,
sourceMessage.mediaGroupId
)
is PrivateContentMessage -> PrivateContentMessageImpl(
sourceMessage.messageId,
sourceMessage.user,
sourceMessage.chat,
content,
sourceMessage.date,
sourceMessage.editDate,
sourceMessage.hasProtectedContent,
sourceMessage.forwardInfo,
sourceMessage.replyTo,
sourceMessage.replyMarkup,
sourceMessage.senderBot,
sourceMessage.mediaGroupId
)
is AnonymousGroupContentMessage -> AnonymousGroupContentMessageImpl(
sourceMessage.chat,
sourceMessage.messageId,
sourceMessage.date,
sourceMessage.forwardInfo,
sourceMessage.editDate,
sourceMessage.hasProtectedContent,
sourceMessage.replyTo,
sourceMessage.replyMarkup,
content,
sourceMessage.senderBot,
sourceMessage.authorSignature,
sourceMessage.mediaGroupId
)
is CommonGroupContentMessage -> CommonGroupContentMessageImpl(
sourceMessage.chat,
sourceMessage.messageId,
sourceMessage.user,
sourceMessage.date,
sourceMessage.forwardInfo,
sourceMessage.editDate,
sourceMessage.hasProtectedContent,
sourceMessage.replyTo,
sourceMessage.replyMarkup,
content,
sourceMessage.senderBot,
sourceMessage.mediaGroupId
)
is ConnectedFromChannelGroupContentMessage -> ConnectedFromChannelGroupContentMessageImpl(
sourceMessage.chat,
sourceMessage.channel,
sourceMessage.messageId,
sourceMessage.date,
sourceMessage.forwardInfo,
sourceMessage.editDate,
sourceMessage.hasProtectedContent,
sourceMessage.replyTo,
sourceMessage.replyMarkup,
content,
sourceMessage.senderBot,
sourceMessage.authorSignature,
sourceMessage.mediaGroupId
)
is UnconnectedFromChannelGroupContentMessage -> UnconnectedFromChannelGroupContentMessageImpl(
sourceMessage.chat,
sourceMessage.channel,
sourceMessage.messageId,
sourceMessage.date,
sourceMessage.forwardInfo,
sourceMessage.editDate,
sourceMessage.hasProtectedContent,
sourceMessage.replyTo,
sourceMessage.replyMarkup,
content,
sourceMessage.senderBot,
sourceMessage.authorSignature,
sourceMessage.mediaGroupId
)
is AnonymousForumContentMessage -> AnonymousForumContentMessageImpl(
sourceMessage.chat,
sourceMessage.messageId,
sourceMessage.threadId,
sourceMessage.date,
sourceMessage.forwardInfo,
sourceMessage.editDate,
sourceMessage.hasProtectedContent,
sourceMessage.replyTo,
sourceMessage.replyMarkup,
content,
sourceMessage.senderBot,
sourceMessage.authorSignature,
sourceMessage.mediaGroupId
)
is CommonForumContentMessage -> CommonForumContentMessageImpl(
sourceMessage.chat,
sourceMessage.messageId,
sourceMessage.threadId,
sourceMessage.user,
sourceMessage.date,
sourceMessage.forwardInfo,
sourceMessage.editDate,
sourceMessage.hasProtectedContent,
sourceMessage.replyTo,
sourceMessage.replyMarkup,
content,
sourceMessage.senderBot,
sourceMessage.mediaGroupId
)
is FromChannelForumContentMessage -> FromChannelForumContentMessageImpl(
sourceMessage.chat,
sourceMessage.channel,
sourceMessage.messageId,
sourceMessage.threadId,
sourceMessage.date,
sourceMessage.forwardInfo,
sourceMessage.editDate,
sourceMessage.hasProtectedContent,
sourceMessage.replyTo,
sourceMessage.replyMarkup,
content,
sourceMessage.senderBot,
sourceMessage.authorSignature,
sourceMessage.mediaGroupId
)
}
}

View File

@ -34,7 +34,6 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.LeftChatMember
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
import dev.inmo.tgbotapi.types.message.abstracts.*
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.content.*
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
import dev.inmo.tgbotapi.types.message.textsources.*
@ -47,7 +46,6 @@ import dev.inmo.tgbotapi.types.polls.*
import dev.inmo.tgbotapi.types.queries.callback.*
import dev.inmo.tgbotapi.types.update.*
import dev.inmo.tgbotapi.types.update.abstracts.*
import dev.inmo.tgbotapi.types.update.media_group.*
import dev.inmo.tgbotapi.utils.PreviewFeature
@PreviewFeature
@ -1037,18 +1035,6 @@ inline fun Message.asChannelEventMessage(): ChannelEventMessage<ChannelEvent>? =
inline fun Message.requireChannelEventMessage(): ChannelEventMessage<ChannelEvent> =
this as ChannelEventMessage<ChannelEvent>
@PreviewFeature
inline fun <T> Message.whenChannelMediaGroupMessage(block: (ChannelMediaGroupMessage<MediaGroupContent>) -> T) =
asChannelMediaGroupMessage()?.let(block)
@PreviewFeature
inline fun Message.asChannelMediaGroupMessage(): ChannelMediaGroupMessage<MediaGroupContent>? =
this as? ChannelMediaGroupMessage<MediaGroupContent>
@PreviewFeature
inline fun Message.requireChannelMediaGroupMessage(): ChannelMediaGroupMessage<MediaGroupContent> =
this as ChannelMediaGroupMessage<MediaGroupContent>
@PreviewFeature
inline fun <T> Message.whenCommonGroupEventMessage(block: (CommonGroupEventMessage<GroupEvent>) -> T) =
asCommonGroupEventMessage()?.let(block)
@ -1061,18 +1047,6 @@ inline fun Message.asCommonGroupEventMessage(): CommonGroupEventMessage<GroupEve
inline fun Message.requireCommonGroupEventMessage(): CommonGroupEventMessage<GroupEvent> =
this as CommonGroupEventMessage<GroupEvent>
@PreviewFeature
inline fun <T> Message.whenCommonMediaGroupMessage(block: (CommonMediaGroupMessage<MediaGroupContent>) -> T) =
asCommonMediaGroupMessage()?.let(block)
@PreviewFeature
inline fun Message.asCommonMediaGroupMessage(): CommonMediaGroupMessage<MediaGroupContent>? =
this as? CommonMediaGroupMessage<MediaGroupContent>
@PreviewFeature
inline fun Message.requireCommonMediaGroupMessage(): CommonMediaGroupMessage<MediaGroupContent> =
this as CommonMediaGroupMessage<MediaGroupContent>
@PreviewFeature
inline fun <T> Message.whenCommonSupergroupEventMessage(block: (CommonSupergroupEventMessage<SupergroupEvent>) -> T) =
asCommonSupergroupEventMessage()?.let(block)
@ -1220,16 +1194,16 @@ inline fun Message.requireGroupContentMessage(): GroupContentMessage<MessageCont
this as GroupContentMessage<MessageContent>
@PreviewFeature
inline fun <T> Message.whenMediaGroupMessage(block: (MediaGroupMessage<MediaGroupContent>) -> T) =
inline fun <T> Message.whenMediaGroupMessage(block: (MediaGroupMessage<MediaGroupPartContent>) -> T) =
asMediaGroupMessage()?.let(block)
@PreviewFeature
inline fun Message.asMediaGroupMessage(): MediaGroupMessage<MediaGroupContent>? =
this as? MediaGroupMessage<MediaGroupContent>
inline fun Message.asMediaGroupMessage(): MediaGroupMessage<MediaGroupPartContent>? =
this as? MediaGroupMessage<MediaGroupPartContent>
@PreviewFeature
inline fun Message.requireMediaGroupMessage(): MediaGroupMessage<MediaGroupContent> =
this as MediaGroupMessage<MediaGroupContent>
inline fun Message.requireMediaGroupMessage(): MediaGroupMessage<MediaGroupPartContent> =
this as MediaGroupMessage<MediaGroupPartContent>
@PreviewFeature
inline fun <T> Message.whenPossiblyEditedMessage(block: (PossiblyEditedMessage) -> T) =
@ -2219,79 +2193,6 @@ inline fun Update.asInlineQueryUpdate(): InlineQueryUpdate? = this as? InlineQue
@PreviewFeature
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
inline fun <T> Update.whenMessageUpdate(block: (MessageUpdate) -> T) = asMessageUpdate()?.let(block)
@ -2836,26 +2737,26 @@ inline fun ResendableContent.asVenueContent(): VenueContent? = this as? VenueCon
inline fun ResendableContent.requireVenueContent(): VenueContent = this as VenueContent
@PreviewFeature
inline fun <T> ResendableContent.whenAudioMediaGroupContent(block: (AudioMediaGroupContent) -> T) =
inline fun <T> ResendableContent.whenAudioMediaGroupContent(block: (AudioMediaGroupPartContent) -> T) =
asAudioMediaGroupContent()?.let(block)
@PreviewFeature
inline fun ResendableContent.asAudioMediaGroupContent(): AudioMediaGroupContent? = this as? AudioMediaGroupContent
inline fun ResendableContent.asAudioMediaGroupContent(): AudioMediaGroupPartContent? = this as? AudioMediaGroupPartContent
@PreviewFeature
inline fun ResendableContent.requireAudioMediaGroupContent(): AudioMediaGroupContent = this as AudioMediaGroupContent
inline fun ResendableContent.requireAudioMediaGroupContent(): AudioMediaGroupPartContent = this as AudioMediaGroupPartContent
@PreviewFeature
inline fun <T> ResendableContent.whenDocumentMediaGroupContent(block: (DocumentMediaGroupContent) -> T) =
inline fun <T> ResendableContent.whenDocumentMediaGroupContent(block: (DocumentMediaGroupPartContent) -> T) =
asDocumentMediaGroupContent()?.let(block)
@PreviewFeature
inline fun ResendableContent.asDocumentMediaGroupContent(): DocumentMediaGroupContent? =
this as? DocumentMediaGroupContent
inline fun ResendableContent.asDocumentMediaGroupContent(): DocumentMediaGroupPartContent? =
this as? DocumentMediaGroupPartContent
@PreviewFeature
inline fun ResendableContent.requireDocumentMediaGroupContent(): DocumentMediaGroupContent =
this as DocumentMediaGroupContent
inline fun ResendableContent.requireDocumentMediaGroupContent(): DocumentMediaGroupPartContent =
this as DocumentMediaGroupPartContent
@PreviewFeature
inline fun <T> ResendableContent.whenMediaCollectionContent(block: (MediaCollectionContent<TelegramMediaFile>) -> T) =
@ -2891,14 +2792,14 @@ inline fun ResendableContent.asMediaContent(): MediaContent? = this as? MediaCon
inline fun ResendableContent.requireMediaContent(): MediaContent = this as MediaContent
@PreviewFeature
inline fun <T> ResendableContent.whenMediaGroupContent(block: (MediaGroupContent) -> T) =
inline fun <T> ResendableContent.whenMediaGroupContent(block: (MediaGroupPartContent) -> T) =
asMediaGroupContent()?.let(block)
@PreviewFeature
inline fun ResendableContent.asMediaGroupContent(): MediaGroupContent? = this as? MediaGroupContent
inline fun ResendableContent.asMediaGroupContent(): MediaGroupPartContent? = this as? MediaGroupPartContent
@PreviewFeature
inline fun ResendableContent.requireMediaGroupContent(): MediaGroupContent = this as MediaGroupContent
inline fun ResendableContent.requireMediaGroupContent(): MediaGroupPartContent = this as MediaGroupPartContent
@PreviewFeature
inline fun <T> ResendableContent.whenMessageContent(block: (MessageContent) -> T) = asMessageContent()?.let(block)
@ -2910,14 +2811,14 @@ inline fun ResendableContent.asMessageContent(): MessageContent? = this as? Mess
inline fun ResendableContent.requireMessageContent(): MessageContent = this as MessageContent
@PreviewFeature
inline fun <T> ResendableContent.whenVisualMediaGroupContent(block: (VisualMediaGroupContent) -> T) =
inline fun <T> ResendableContent.whenVisualMediaGroupContent(block: (VisualMediaGroupPartContent) -> T) =
asVisualMediaGroupContent()?.let(block)
@PreviewFeature
inline fun ResendableContent.asVisualMediaGroupContent(): VisualMediaGroupContent? = this as? VisualMediaGroupContent
inline fun ResendableContent.asVisualMediaGroupContent(): VisualMediaGroupPartContent? = this as? VisualMediaGroupPartContent
@PreviewFeature
inline fun ResendableContent.requireVisualMediaGroupContent(): VisualMediaGroupContent = this as VisualMediaGroupContent
inline fun ResendableContent.requireVisualMediaGroupContent(): VisualMediaGroupPartContent = this as VisualMediaGroupPartContent
@PreviewFeature
inline fun <T> ResendableContent.whenAnimationContent(block: (AnimationContent) -> T) = asAnimationContent()?.let(block)

View File

@ -221,7 +221,6 @@ import dev.inmo.tgbotapi.types.message.AnonymousForumContentMessageImpl
import dev.inmo.tgbotapi.types.message.AnonymousGroupContentMessageImpl
import dev.inmo.tgbotapi.types.message.ChannelContentMessageImpl
import dev.inmo.tgbotapi.types.message.ChannelEventMessage
import dev.inmo.tgbotapi.types.message.ChannelMediaGroupMessage
import dev.inmo.tgbotapi.types.message.ChatEvents.ChannelChatCreated
import dev.inmo.tgbotapi.types.message.ChatEvents.DeleteChatPhoto
import dev.inmo.tgbotapi.types.message.ChatEvents.GroupChatCreated
@ -255,7 +254,6 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.voice.VideoChatStarted
import dev.inmo.tgbotapi.types.message.CommonForumContentMessageImpl
import dev.inmo.tgbotapi.types.message.CommonGroupContentMessageImpl
import dev.inmo.tgbotapi.types.message.CommonGroupEventMessage
import dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage
import dev.inmo.tgbotapi.types.message.CommonSupergroupEventMessage
import dev.inmo.tgbotapi.types.message.ConnectedFromChannelGroupContentMessageImpl
import dev.inmo.tgbotapi.types.message.ForwardInfo
@ -279,12 +277,13 @@ import dev.inmo.tgbotapi.types.message.abstracts.FromChannelGroupContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.FromUserMessage
import dev.inmo.tgbotapi.types.message.abstracts.GroupContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.GroupEventMessage
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyEditedMessage
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.PossiblySentViaBotCommonMessage
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyTopicMessage
import dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.PublicContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.SignedMessage
@ -293,18 +292,20 @@ import dev.inmo.tgbotapi.types.message.abstracts.UnconnectedFromChannelGroupCont
import dev.inmo.tgbotapi.types.message.abstracts.UnknownMessageType
import dev.inmo.tgbotapi.types.message.content.AnimationContent
import dev.inmo.tgbotapi.types.message.content.AudioContent
import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent
import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupPartContent
import dev.inmo.tgbotapi.types.message.content.ContactContent
import dev.inmo.tgbotapi.types.message.content.DiceContent
import dev.inmo.tgbotapi.types.message.content.DocumentContent
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupPartContent
import dev.inmo.tgbotapi.types.message.content.GameContent
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
import dev.inmo.tgbotapi.types.message.content.LiveLocationContent
import dev.inmo.tgbotapi.types.message.content.LocationContent
import dev.inmo.tgbotapi.types.message.content.MediaCollectionContent
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.MessageContent
import dev.inmo.tgbotapi.types.message.content.PhotoContent
import dev.inmo.tgbotapi.types.message.content.PollContent
@ -316,7 +317,7 @@ import dev.inmo.tgbotapi.types.message.content.TextedMediaContent
import dev.inmo.tgbotapi.types.message.content.VenueContent
import dev.inmo.tgbotapi.types.message.content.VideoContent
import dev.inmo.tgbotapi.types.message.content.VideoNoteContent
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupPartContent
import dev.inmo.tgbotapi.types.message.content.VoiceContent
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
import dev.inmo.tgbotapi.types.message.textsources.BoldTextSource
@ -441,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.UnknownUpdate
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
public inline fun CommonSendInvoiceData.createInvoiceLinkOrNull(): CreateInvoiceLink? = this as?
@ -741,18 +735,6 @@ public inline fun <T>
WithUser.ifCommonGroupEventMessage(block: (CommonGroupEventMessage<GroupEvent>) -> T): T? =
commonGroupEventMessageOrNull() ?.let(block)
public inline fun WithUser.commonMediaGroupMessageOrNull():
CommonMediaGroupMessage<MediaGroupContent>? = this as?
dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupContent>
public inline fun WithUser.commonMediaGroupMessageOrThrow():
CommonMediaGroupMessage<MediaGroupContent> = this as
dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupContent>
public inline fun <T>
WithUser.ifCommonMediaGroupMessage(block: (CommonMediaGroupMessage<MediaGroupContent>) -> T): T?
= commonMediaGroupMessageOrNull() ?.let(block)
public inline fun WithUser.commonSupergroupEventMessageOrNull():
CommonSupergroupEventMessage<SupergroupEvent>? = this as?
dev.inmo.tgbotapi.types.message.CommonSupergroupEventMessage<dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent>
@ -3035,18 +3017,6 @@ public inline fun <T>
Message.ifChannelEventMessage(block: (ChannelEventMessage<ChannelEvent>) -> T): T? =
channelEventMessageOrNull() ?.let(block)
public inline fun Message.channelMediaGroupMessageOrNull():
ChannelMediaGroupMessage<MediaGroupContent>? = this as?
dev.inmo.tgbotapi.types.message.ChannelMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupContent>
public inline fun Message.channelMediaGroupMessageOrThrow():
ChannelMediaGroupMessage<MediaGroupContent> = this as
dev.inmo.tgbotapi.types.message.ChannelMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupContent>
public inline fun <T>
Message.ifChannelMediaGroupMessage(block: (ChannelMediaGroupMessage<MediaGroupContent>) -> T):
T? = channelMediaGroupMessageOrNull() ?.let(block)
public inline fun Message.commonGroupEventMessageOrNull(): CommonGroupEventMessage<GroupEvent>? =
this as?
dev.inmo.tgbotapi.types.message.CommonGroupEventMessage<dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent>
@ -3059,18 +3029,6 @@ public inline fun <T>
Message.ifCommonGroupEventMessage(block: (CommonGroupEventMessage<GroupEvent>) -> T): T? =
commonGroupEventMessageOrNull() ?.let(block)
public inline fun Message.commonMediaGroupMessageOrNull():
CommonMediaGroupMessage<MediaGroupContent>? = this as?
dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupContent>
public inline fun Message.commonMediaGroupMessageOrThrow():
CommonMediaGroupMessage<MediaGroupContent> = this as
dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupContent>
public inline fun <T>
Message.ifCommonMediaGroupMessage(block: (CommonMediaGroupMessage<MediaGroupContent>) -> T): T?
= commonMediaGroupMessageOrNull() ?.let(block)
public inline fun Message.commonSupergroupEventMessageOrNull():
CommonSupergroupEventMessage<SupergroupEvent>? = this as?
dev.inmo.tgbotapi.types.message.CommonSupergroupEventMessage<dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent>
@ -3375,17 +3333,6 @@ public inline fun <T>
Message.ifCommonForumContentMessage(block: (CommonForumContentMessage<MessageContent>) -> T): T?
= commonForumContentMessageOrNull() ?.let(block)
public inline fun Message.mediaGroupMessageOrNull(): MediaGroupMessage<MediaGroupContent>? = this
as?
dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupContent>
public inline fun Message.mediaGroupMessageOrThrow(): MediaGroupMessage<MediaGroupContent> = this as
dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupContent>
public inline fun <T>
Message.ifMediaGroupMessage(block: (MediaGroupMessage<MediaGroupContent>) -> T): T? =
mediaGroupMessageOrNull() ?.let(block)
public inline fun Message.unknownMessageTypeOrNull(): UnknownMessageType? = this as?
dev.inmo.tgbotapi.types.message.abstracts.UnknownMessageType
@ -3413,6 +3360,18 @@ public inline fun Message.possiblyForwardedMessageOrThrow(): PossiblyForwardedMe
public inline fun <T> Message.ifPossiblyForwardedMessage(block: (PossiblyForwardedMessage) -> T): T?
= 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?
dev.inmo.tgbotapi.types.message.abstracts.PossiblyPaymentMessage
@ -3434,6 +3393,15 @@ public inline fun <T>
Message.ifPossiblySentViaBotCommonMessage(block: (PossiblySentViaBotCommonMessage<MessageContent>) -> T):
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>? =
this as?
dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage<dev.inmo.tgbotapi.types.message.content.MessageContent>
@ -3509,34 +3477,27 @@ public inline fun ResendableContent.mediaContentOrThrow(): MediaContent = this a
public inline fun <T> ResendableContent.ifMediaContent(block: (MediaContent) -> T): T? =
mediaContentOrNull() ?.let(block)
public inline fun ResendableContent.audioMediaGroupContentOrNull(): AudioMediaGroupContent? = this
as? dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent
public inline fun ResendableContent.audioMediaGroupPartContentOrNull(): AudioMediaGroupPartContent?
= this as? dev.inmo.tgbotapi.types.message.content.AudioMediaGroupPartContent
public inline fun ResendableContent.audioMediaGroupContentOrThrow(): AudioMediaGroupContent = this
as dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent
public inline fun ResendableContent.audioMediaGroupPartContentOrThrow(): AudioMediaGroupPartContent
= this as dev.inmo.tgbotapi.types.message.content.AudioMediaGroupPartContent
public inline fun <T>
ResendableContent.ifAudioMediaGroupContent(block: (AudioMediaGroupContent) -> T): T? =
audioMediaGroupContentOrNull() ?.let(block)
ResendableContent.ifAudioMediaGroupPartContent(block: (AudioMediaGroupPartContent) -> T): T? =
audioMediaGroupPartContentOrNull() ?.let(block)
public inline fun ResendableContent.documentMediaGroupContentOrNull(): DocumentMediaGroupContent? =
this as? dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
public inline fun ResendableContent.documentMediaGroupPartContentOrNull():
DocumentMediaGroupPartContent? = this as?
dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupPartContent
public inline fun ResendableContent.documentMediaGroupContentOrThrow(): DocumentMediaGroupContent =
this as dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
public inline fun ResendableContent.documentMediaGroupPartContentOrThrow():
DocumentMediaGroupPartContent = this as
dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupPartContent
public inline fun <T>
ResendableContent.ifDocumentMediaGroupContent(block: (DocumentMediaGroupContent) -> T): T? =
documentMediaGroupContentOrNull() ?.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)
ResendableContent.ifDocumentMediaGroupPartContent(block: (DocumentMediaGroupPartContent) -> T):
T? = documentMediaGroupPartContentOrNull() ?.let(block)
public inline fun ResendableContent.textedMediaContentOrNull(): TextedMediaContent? = this as?
dev.inmo.tgbotapi.types.message.content.TextedMediaContent
@ -3547,15 +3508,39 @@ public inline fun ResendableContent.textedMediaContentOrThrow(): TextedMediaCont
public inline fun <T> ResendableContent.ifTextedMediaContent(block: (TextedMediaContent) -> T): T? =
textedMediaContentOrNull() ?.let(block)
public inline fun ResendableContent.visualMediaGroupContentOrNull(): VisualMediaGroupContent? = this
as? dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
public inline fun ResendableContent.mediaGroupCollectionContentOrNull():
MediaGroupCollectionContent<MediaGroupPartContent>? = this as?
dev.inmo.tgbotapi.types.message.content.MediaGroupCollectionContent<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
public inline fun ResendableContent.visualMediaGroupContentOrThrow(): VisualMediaGroupContent = this
as dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
public inline fun ResendableContent.mediaGroupCollectionContentOrThrow():
MediaGroupCollectionContent<MediaGroupPartContent> = this as
dev.inmo.tgbotapi.types.message.content.MediaGroupCollectionContent<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
public inline fun <T>
ResendableContent.ifVisualMediaGroupContent(block: (VisualMediaGroupContent) -> T): T? =
visualMediaGroupContentOrNull() ?.let(block)
ResendableContent.ifMediaGroupCollectionContent(block: (MediaGroupCollectionContent<MediaGroupPartContent>) -> T):
T? = 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?
dev.inmo.tgbotapi.types.message.content.AnimationContent
@ -3648,6 +3633,18 @@ public inline fun <T>
ResendableContent.ifStaticLocationContent(block: (StaticLocationContent) -> T): T? =
staticLocationContentOrNull() ?.let(block)
public inline fun ResendableContent.mediaGroupContentOrNull():
MediaGroupContent<MediaGroupPartContent>? = this as?
dev.inmo.tgbotapi.types.message.content.MediaGroupContent<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
public inline fun ResendableContent.mediaGroupContentOrThrow():
MediaGroupContent<MediaGroupPartContent> = this as
dev.inmo.tgbotapi.types.message.content.MediaGroupContent<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
public inline fun <T>
ResendableContent.ifMediaGroupContent(block: (MediaGroupContent<MediaGroupPartContent>) -> T):
T? = mediaGroupContentOrNull() ?.let(block)
public inline fun ResendableContent.photoContentOrNull(): PhotoContent? = this as?
dev.inmo.tgbotapi.types.message.content.PhotoContent
@ -4731,69 +4728,3 @@ public inline fun Update.unknownUpdateOrThrow(): UnknownUpdate = this as
public inline fun <T> Update.ifUnknownUpdate(block: (UnknownUpdate) -> T): T? =
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)

View File

@ -3,7 +3,7 @@
package dev.inmo.tgbotapi.extensions.utils
import dev.inmo.tgbotapi.types.message.abstracts.*
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
import dev.inmo.tgbotapi.types.message.content.MessageContent
inline fun <reified T : MessageContent> ContentMessage<*>.withContentOrNull() = if (content is T) { this as ContentMessage<T> } else { null }
@ -36,6 +36,3 @@ inline fun <reified T : MessageContent> AnonymousGroupContentMessage<*>.withCont
inline fun <reified T : MessageContent> CommonGroupContentMessage<*>.withContentOrNull() = if (content is T) { this as CommonGroupContentMessage<T> } else { null }
inline fun <reified T : MessageContent> CommonGroupContentMessage<*>.withContentOrThrow() = withContentOrNull<T>()!!
inline fun <reified T : MediaGroupContent> MediaGroupMessage<*>.withContentOrNull() = if (content is T) { this as MediaGroupMessage<T> } else { null }
inline fun <reified T : MediaGroupContent> MediaGroupMessage<*>.withContentOrThrow() = withContentOrNull<T>()!!

View File

@ -3,7 +3,8 @@
package dev.inmo.tgbotapi.extensions.utils
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.message.content.MediaGroupPartContent
import dev.inmo.tgbotapi.types.message.content.MessageContent
inline fun <reified T : MessageContent> ContentMessage<*>.withContent() = if (content is T) { this as ContentMessage<T> } else { null }
@ -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<*>.requireWithContent() = withContent<T>()!!
inline fun <reified T : MediaGroupContent> MediaGroupMessage<*>.withContent() = if (content is T) { this as MediaGroupMessage<T> } else { null }
inline fun <reified T : MediaGroupContent> MediaGroupMessage<*>.requireWithContent() = withContent<T>()!!

View File

@ -3,21 +3,15 @@ package dev.inmo.tgbotapi.extensions.utils.extensions
import dev.inmo.tgbotapi.abstracts.FromUser
import dev.inmo.tgbotapi.abstracts.WithUser
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.User
import dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate
import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate
import dev.inmo.tgbotapi.types.update.abstracts.Update
import dev.inmo.tgbotapi.types.update.media_group.*
import dev.inmo.tgbotapi.utils.PreviewFeature
@PreviewFeature
fun Update.sourceChat(): Chat? = when (this) {
is MediaGroupUpdate -> when (this) {
is SentMediaGroupUpdate -> data.chat
is EditMediaGroupUpdate -> data.chat
}
is BaseMessageUpdate -> data.chat
is ChatJoinRequestUpdate -> data.chat
else -> {

View File

@ -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.content.*
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.utils.RiskFeature
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(
): Flow<ContentMessage<T>> = asContentMessagesFlow().mapNotNull(filterForContentMessage())
@RiskFeature("This method is low-level")
inline fun <reified T : MediaGroupContent> 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.
* 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()
}
/**
* @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: MediaGroupContent> FlowsUpdatesFilter.filterMediaGroupMessages(
scopeToIncludeChannels: CoroutineScope? = null
): Flow<List<CommonMessage<T>>> {
return (scopeToIncludeChannels ?.let { scope ->
aggregateFlows(
scope,
messageMediaGroupsFlow,
channelPostMediaGroupsFlow
)
} ?: messageMediaGroupsFlow).filterMediaGroupMessages()
}
fun FlowsUpdatesFilter.sentMessages(
scopeToIncludeChannels: CoroutineScope? = null
): 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 FlowsUpdatesFilter.animationMessages(
@ -105,12 +61,6 @@ fun Flow<BaseSentMessageUpdate>.audioMessages() = filterContentMessages<AudioCon
fun FlowsUpdatesFilter.audioMessages(
scopeToIncludeChannels: CoroutineScope? = null
) = filterContentMessages<AudioContent>(scopeToIncludeChannels)
fun FlowsUpdatesFilter.audioMessagesWithMediaGroups(
scopeToIncludeChannels: CoroutineScope? = null
) = merge(
filterContentMessages<AudioContent>(scopeToIncludeChannels),
mediaGroupAudioMessages(scopeToIncludeChannels).flatten()
)
fun Flow<BaseSentMessageUpdate>.contactMessages() = filterContentMessages<ContactContent>()
fun FlowsUpdatesFilter.contactMessages(
@ -126,12 +76,6 @@ fun Flow<BaseSentMessageUpdate>.documentMessages() = filterContentMessages<Docum
fun FlowsUpdatesFilter.documentMessages(
scopeToIncludeChannels: CoroutineScope? = null
) = filterContentMessages<DocumentContent>(scopeToIncludeChannels)
fun FlowsUpdatesFilter.documentMessagesWithMediaGroups(
scopeToIncludeChannels: CoroutineScope? = null
) = merge(
filterContentMessages<DocumentContent>(scopeToIncludeChannels),
mediaGroupDocumentMessages(scopeToIncludeChannels).flatten()
)
fun Flow<BaseSentMessageUpdate>.gameMessages() = filterContentMessages<GameContent>()
fun FlowsUpdatesFilter.gameMessages(
@ -153,12 +97,6 @@ fun Flow<BaseSentMessageUpdate>.imageMessages() = photoMessages()
fun FlowsUpdatesFilter.photoMessages(
scopeToIncludeChannels: CoroutineScope? = null
) = filterContentMessages<PhotoContent>(scopeToIncludeChannels)
fun FlowsUpdatesFilter.photoMessagesWithMediaGroups(
scopeToIncludeChannels: CoroutineScope? = null
) = merge(
filterContentMessages<PhotoContent>(scopeToIncludeChannels),
mediaGroupPhotosMessages(scopeToIncludeChannels).flatten()
)
/**
* Shortcut for [photoMessages]
*/
@ -166,9 +104,6 @@ fun FlowsUpdatesFilter.photoMessagesWithMediaGroups(
inline fun FlowsUpdatesFilter.imageMessages(
scopeToIncludeChannels: CoroutineScope? = null
) = photoMessages(scopeToIncludeChannels)
fun FlowsUpdatesFilter.imageMessagesWithMediaGroups(
scopeToIncludeChannels: CoroutineScope? = null
) = photoMessagesWithMediaGroups(scopeToIncludeChannels)
fun Flow<BaseSentMessageUpdate>.pollMessages() = filterContentMessages<PollContent>()
fun FlowsUpdatesFilter.pollMessages(
@ -194,12 +129,6 @@ fun Flow<BaseSentMessageUpdate>.videoMessages() = filterContentMessages<VideoCon
fun FlowsUpdatesFilter.videoMessages(
scopeToIncludeChannels: CoroutineScope? = null
) = filterContentMessages<VideoContent>(scopeToIncludeChannels)
fun FlowsUpdatesFilter.videoMessagesWithMediaGroups(
scopeToIncludeChannels: CoroutineScope? = null
) = merge(
filterContentMessages<VideoContent>(scopeToIncludeChannels),
mediaGroupVideosMessages(scopeToIncludeChannels).flatten()
)
fun Flow<BaseSentMessageUpdate>.videoNoteMessages() = filterContentMessages<VideoNoteContent>()
fun FlowsUpdatesFilter.videoNoteMessages(
@ -210,34 +139,3 @@ fun Flow<BaseSentMessageUpdate>.voiceMessages() = filterContentMessages<VoiceCon
fun FlowsUpdatesFilter.voiceMessages(
scopeToIncludeChannels: CoroutineScope? = null
) = filterContentMessages<VoiceContent>(scopeToIncludeChannels)
fun Flow<SentMediaGroupUpdate>.mediaGroupMessages() = filterMediaGroupMessages<MediaGroupContent>()
fun FlowsUpdatesFilter.mediaGroupMessages(
scopeToIncludeChannels: CoroutineScope? = null
) = filterMediaGroupMessages<MediaGroupContent>(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<VisualMediaGroupContent>()
fun FlowsUpdatesFilter.mediaGroupVisualMessages(
scopeToIncludeChannels: CoroutineScope? = null
) = filterMediaGroupMessages<VisualMediaGroupContent>(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)

View File

@ -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.MediaGroupContent
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
val List<CommonMessage<out MediaGroupContent>>.forwardInfo: ForwardInfo?
get() = firstOrNull() ?.forwardInfo
val List<CommonMessage<out MediaGroupContent>>.replyTo: Message?
get() = firstOrNull() ?.replyTo
val List<CommonMessage<out MediaGroupContent>>.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<MediaGroupContent>>.createResend(
chatId: ChatId,
threadId: MessageThreadId? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyTo: MessageId? = null
) = SendMediaGroup<MediaGroupContent>(
chatId,
map { it.content.toMediaGroupMemberTelegramMedia() },
threadId,
disableNotification,
protectContent,
replyTo
)
fun List<CommonMessage<MediaGroupContent>>.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
)

View File

@ -1,7 +1,6 @@
package dev.inmo.tgbotapi.extensions.utils.updates
import dev.inmo.tgbotapi.types.update.abstracts.*
import dev.inmo.tgbotapi.types.update.media_group.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filterIsInstance
@ -16,22 +15,3 @@ fun Flow<BaseMessageUpdate>.onlySentMessageUpdates(): Flow<BaseSentMessageUpdate
* Converts flow to [Flow] of [BaseSentMessageUpdate]
*/
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()

View File

@ -3,7 +3,6 @@ package dev.inmo.tgbotapi.extensions.utils.updates
import dev.inmo.tgbotapi.types.ChatId
import dev.inmo.tgbotapi.types.chat.Chat
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.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]
*/
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)

View File

@ -1,21 +1,20 @@
package dev.inmo.tgbotapi.extensions.utils.updates
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
import dev.inmo.tgbotapi.types.UpdateIdentifier
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
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.abstracts.*
import dev.inmo.tgbotapi.types.update.media_group.*
import dev.inmo.tgbotapi.utils.extensions.asMediaGroupMessage
/**
* @return If [this] is [SentMediaGroupUpdate] - [Update.updateId] of [last] element, or its own [Update.updateId]
*/
@Deprecated("Redundant", ReplaceWith("updateId"))
fun Update.lastUpdateIdentifier(): UpdateIdentifier {
return if (this is SentMediaGroupUpdate) {
origins.last().updateId
} else {
updateId
}
return updateId
}
/**
@ -24,7 +23,7 @@ fun Update.lastUpdateIdentifier(): UpdateIdentifier {
* @see [Update.lastUpdateIdentifier]
*/
fun List<Update>.lastUpdateIdentifier(): UpdateIdentifier? {
return maxByOrNull { it.updateId } ?.lastUpdateIdentifier()
return maxByOrNull { it.updateId } ?.updateId
}
/**
@ -32,62 +31,40 @@ fun List<Update>.lastUpdateIdentifier(): UpdateIdentifier? {
*/
fun List<Update>.convertWithMediaGroupUpdates(): List<Update> {
val resultUpdates = mutableListOf<Update>()
val mediaGroups = mutableMapOf<MediaGroupIdentifier, MutableList<BaseSentMessageUpdate>>()
val mediaGroups = mutableMapOf<MediaGroupIdentifier, MutableList<Pair<BaseSentMessageUpdate, PossiblySentViaBotCommonMessage<MediaGroupPartContent>>>>()
for (update in this) {
val data = (update.data as? MediaGroupMessage<*>)
if (data == null) {
val message = (update.data as? PossiblySentViaBotCommonMessage<*>) ?.withContentOrNull<MediaGroupPartContent>()
val mediaGroupId = message ?.mediaGroupId
if (message == null || mediaGroupId == null) {
resultUpdates.add(update)
continue
}
when (update) {
is BaseEditMessageUpdate -> resultUpdates.add(
update.toEditMediaGroupUpdate()
)
is BaseSentMessageUpdate -> {
mediaGroups.getOrPut(data.mediaGroupId) {
mediaGroups.getOrPut(mediaGroupId) {
mutableListOf()
}.add(update)
}.add(update to message)
}
else -> resultUpdates.add(update)
}
}
mediaGroups.values.map {
it.toSentMediaGroupUpdate() ?.let { mediaGroupUpdate ->
resultUpdates.add(mediaGroupUpdate)
}
mediaGroups.map { (_, updatesWithMessages) ->
val update = updatesWithMessages.maxBy { it.first.updateId }.first
resultUpdates.add(
update.copy(updatesWithMessages.map { it.second }.asMediaGroupMessage())
)
}
resultUpdates.sortBy { it.updateId }
return resultUpdates
}
/**
* @receiver List of [BaseSentMessageUpdate] where [BaseSentMessageUpdate.data] is [MediaGroupMessage] and all messages
* have the same [MediaGroupMessage.mediaGroupId]
* @return [MessageMediaGroupUpdate] in case if [first] object of [this] is [MessageUpdate]. When [first] object is
* [ChannelPostUpdate] instance - will return [ChannelPostMediaGroupUpdate]. Otherwise will be returned null
*/
fun List<BaseSentMessageUpdate>.toSentMediaGroupUpdate(): SentMediaGroupUpdate? = (this as? SentMediaGroupUpdate) ?: let {
if (isEmpty()) {
return@let null
}
val resultList = sortedBy { it.updateId }
when (first()) {
is MessageUpdate -> MessageMediaGroupUpdate(resultList)
is ChannelPostUpdate -> ChannelPostMediaGroupUpdate(resultList)
else -> null
}
}
/**
* @return [EditMessageMediaGroupUpdate] in case if [this] is [EditMessageUpdate]. When [this] object is
* [EditChannelPostUpdate] instance - will return [EditChannelPostMediaGroupUpdate]
*
* @throws IllegalStateException
*/
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}")
}
}
fun BaseEditMessageUpdate.toEditMediaGroupUpdate() = this

View File

@ -8,9 +8,11 @@ import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates
import dev.inmo.tgbotapi.extensions.utils.updates.lastUpdateIdentifier
import dev.inmo.tgbotapi.requests.GetUpdates
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.abstracts.BaseSentMessageUpdate
import dev.inmo.tgbotapi.types.update.abstracts.Update
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
import dev.inmo.tgbotapi.updateshandlers.*
import io.ktor.client.plugins.HttpRequestTimeoutException
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
* 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()
} else {
converted
@ -67,7 +72,7 @@ fun TelegramBot.longPollingFlow(
for (update in updates) {
send(update)
lastUpdateIdentifier = update.lastUpdateIdentifier()
lastUpdateIdentifier = update.updateId
}
}.onFailure {
cancel(it as? CancellationException ?: return@onFailure)

View File

@ -1,7 +1,7 @@
package dev.inmo.tgbotapi.extensions.utils.updates.retrieving
import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyMediaGroupMessage
import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate
import dev.inmo.tgbotapi.types.update.abstracts.Update
import dev.inmo.tgbotapi.updateshandlers.UpdateReceiver
@ -32,7 +32,7 @@ fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation(
launch {
for (update in updatesChannel) {
when (val data = update.data) {
is MediaGroupMessage<*> -> mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate)
is PossiblyMediaGroupMessage<*> -> mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate)
else -> output(update)
}
}
@ -57,4 +57,4 @@ fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation(
*/
fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation(
output: UpdateReceiver<Update>
) = updateHandlerWithMediaGroupsAdaptation(output, 1000L)
) = updateHandlerWithMediaGroupsAdaptation(output, 1000L)