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

start rework

This commit is contained in:
InsanusMokrassar 2022-11-06 14:07:31 +06:00
parent 867a46d397
commit 541e00fa03
42 changed files with 495 additions and 227 deletions

View File

@ -2,7 +2,31 @@ 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.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.ContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.FromChannelForumContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
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.types.update.*
import dev.inmo.tgbotapi.types.update.abstracts.*
import dev.inmo.tgbotapi.types.update.media_group.*

View File

@ -9,7 +9,7 @@ import dev.inmo.tgbotapi.types.MessageId
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.message.content.MediaGroupPartContent
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
/**
@ -18,14 +18,14 @@ import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
*/
suspend inline fun TelegramBot.copyMessages(
toChatId: ChatIdentifier,
messages: List<MediaGroupMessage<MediaGroupContent>>,
messages: List<MediaGroupMessage<MediaGroupPartContent>>,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null
): List<MediaGroupMessage<MediaGroupContent>> {
): List<MediaGroupMessage<MediaGroupPartContent>> {
val first = messages.first().content.toMediaGroupMemberTelegramMedia().let {
if (text != null) {
when (it) {
@ -57,7 +57,7 @@ suspend inline fun TelegramBot.copyMessages(
*/
suspend inline fun TelegramBot.copyMessages(
toChat: Chat,
messages: List<MediaGroupMessage<MediaGroupContent>>,
messages: List<MediaGroupMessage<MediaGroupPartContent>>,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
@ -102,13 +102,13 @@ suspend inline fun TelegramBot.copyMessages(
*/
suspend inline fun TelegramBot.copyMessages(
toChatId: ChatIdentifier,
messages: List<MediaGroupMessage<MediaGroupContent>>,
messages: List<MediaGroupMessage<MediaGroupPartContent>>,
entities: TextSourcesList,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null
): List<MediaGroupMessage<MediaGroupContent>> {
): List<MediaGroupMessage<MediaGroupPartContent>> {
val first = messages.first().content.toMediaGroupMemberTelegramMedia().let {
when (it) {
is TelegramMediaAudio -> TelegramMediaAudio(it.file, entities, it.duration, it.performer, it.title, it.thumb)
@ -136,7 +136,7 @@ suspend inline fun TelegramBot.copyMessages(
*/
suspend inline fun TelegramBot.copyMessages(
toChat: Chat,
messages: List<MediaGroupMessage<MediaGroupContent>>,
messages: List<MediaGroupMessage<MediaGroupPartContent>>,
entities: TextSourcesList,
disableNotification: Boolean = false,
protectContent: Boolean = false,

View File

@ -1027,8 +1027,7 @@ suspend fun TelegramBot.reply(
protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) {
execute(
) = execute(
content.createResend(
to.chat.id,
disableNotification,
@ -1037,8 +1036,7 @@ suspend fun TelegramBot.reply(
allowSendingWithoutReply,
replyMarkup
)
)
}
)
/**
* Will use [handleLiveLocation] with replying to [message] each time new message will be sent by live location update
@ -1219,7 +1217,7 @@ suspend fun TelegramBot.reply(
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
is AudioMediaGroupContent -> reply(
is AudioMediaGroupPartContent -> reply(
to = to,
audio = content.media,
text = text,
@ -1291,7 +1289,7 @@ suspend fun TelegramBot.reply(
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
is AudioMediaGroupContent -> reply(
is AudioMediaGroupPartContent -> reply(
to = to,
audio = content.media,
entities = entities,

View File

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

View File

@ -1379,7 +1379,7 @@ suspend fun TelegramBot.send(
@JvmName("sendMedaGroupByContent")
suspend fun TelegramBot.send(
chatId: ChatIdentifier,
media: List<MediaGroupContent>,
media: List<MediaGroupPartContent>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
@ -1393,7 +1393,7 @@ suspend fun TelegramBot.send(
@JvmName("sendMedaGroupByContent")
suspend fun TelegramBot.send(
chat: Chat,
media: List<MediaGroupContent>,
media: List<MediaGroupPartContent>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
@ -1536,7 +1536,7 @@ suspend fun TelegramBot.send(
@JvmName("sendVisualMediaGroupByContent")
suspend fun TelegramBot.send(
chatId: ChatIdentifier,
media: List<VisualMediaGroupContent>,
media: List<VisualMediaGroupPartContent>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
@ -1549,7 +1549,7 @@ suspend fun TelegramBot.send(
@JvmName("sendVisualMediaGroupByContent")
suspend fun TelegramBot.send(
chat: Chat,
media: List<VisualMediaGroupContent>,
media: List<VisualMediaGroupPartContent>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,

View File

@ -6,8 +6,8 @@ import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.media.*
import dev.inmo.tgbotapi.types.MessageId
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
@ -25,7 +25,7 @@ suspend fun TelegramBot.sendMediaGroup(
replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null
) = execute(
SendMediaGroup<MediaGroupContent>(
SendMediaGroup<MediaGroupPartContent>(
chatId, media, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply
)
)
@ -52,7 +52,7 @@ suspend fun TelegramBot.sendMediaGroup(
@JvmName("sendMedaGroupByContent")
suspend fun TelegramBot.sendMediaGroup(
chatId: ChatIdentifier,
media: List<MediaGroupContent>,
media: List<MediaGroupPartContent>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
@ -68,7 +68,7 @@ suspend fun TelegramBot.sendMediaGroup(
@JvmName("sendMedaGroupByContent")
suspend fun TelegramBot.sendMediaGroup(
chat: Chat,
media: List<MediaGroupContent>,
media: List<MediaGroupPartContent>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
@ -233,7 +233,7 @@ suspend fun TelegramBot.sendVisualMediaGroup(
@JvmName("sendVisualMediaGroupByContent")
suspend fun TelegramBot.sendVisualMediaGroup(
chatId: ChatIdentifier,
media: List<VisualMediaGroupContent>,
media: List<VisualMediaGroupPartContent>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
@ -248,7 +248,7 @@ suspend fun TelegramBot.sendVisualMediaGroup(
@JvmName("sendVisualMediaGroupByContent")
suspend fun TelegramBot.sendVisualMediaGroup(
chat: Chat,
media: List<VisualMediaGroupContent>,
media: List<VisualMediaGroupPartContent>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,

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

@ -103,12 +103,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 +118,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

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

@ -81,12 +81,12 @@ suspend fun BehaviourContext.waitEditedAudioMediaGroupContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitEditedContentMessage<AudioMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
) = waitEditedContentMessage<AudioMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
suspend fun BehaviourContext.waitEditedDocumentMediaGroupContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitEditedContentMessage<DocumentMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
) = waitEditedContentMessage<DocumentMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
suspend fun BehaviourContext.waitEditedMediaMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
@ -96,12 +96,12 @@ suspend fun BehaviourContext.waitEditedAnyMediaGroupContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitEditedContentMessage<MediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
) = waitEditedContentMessage<MediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
suspend fun BehaviourContext.waitEditedVisualMediaGroupContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true
) = waitEditedContentMessage<VisualMediaGroupContent>(initRequest, includeMediaGroups, errorFactory)
) = waitEditedContentMessage<VisualMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory)
suspend fun BehaviourContext.waitEditedTextedMediaContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },

View File

@ -14,7 +14,7 @@ typealias MediaGroupFilter<T> = SimpleFilter<List<MediaGroupMessage<T>>>
@RiskFeature(lowLevelRiskFeatureMessage)
suspend inline fun <reified O : MediaGroupContent> BehaviourContext.buildMediaGroupWaiter(
suspend inline fun <reified O : MediaGroupPartContent> BehaviourContext.buildMediaGroupWaiter(
initRequest: Request<*>? = null,
noinline errorFactory: NullableRequestBuilder<*> = { null }
): Flow<List<O>> = buildMediaGroupMessagesWaiter<O>(initRequest, errorFactory).map { it.map { it.content } }
@ -22,19 +22,19 @@ suspend inline fun <reified O : MediaGroupContent> BehaviourContext.buildMediaGr
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

@ -11,7 +11,7 @@ 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 ->
@ -26,19 +26,19 @@ suspend inline fun <reified T : MediaGroupContent> BehaviourContext.buildMediaGr
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

@ -287,7 +287,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 +311,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

@ -14,7 +14,7 @@ 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(
internal suspend inline fun <BC : BehaviourContext, reified T : MediaGroupPartContent> BC.buildMediaGroupTrigger(
initialFilter: SimpleFilter<List<MediaGroupMessage<T>>>? = null,
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<T>>, Update>? = MessagesFilterByChat,
markerFactory: MarkerFactory<in List<MediaGroupMessage<T>>, Any> = ByChatMediaGroupMarkerFactory,
@ -40,10 +40,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<List<MediaGroupMessage<MediaGroupPartContent>>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<MediaGroupPartContent>>, Update>? = MessagesFilterByChat,
markerFactory: MarkerFactory<in List<MediaGroupMessage<MediaGroupPartContent>>, Any> = ByChatMediaGroupMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<MediaGroupPartContent>>>
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
@ -59,10 +59,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<List<MediaGroupMessage<AudioMediaGroupPartContent>>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<AudioMediaGroupPartContent>>, Update>? = MessagesFilterByChat,
markerFactory: MarkerFactory<in List<MediaGroupMessage<AudioMediaGroupPartContent>>, Any> = ByChatMediaGroupMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<AudioMediaGroupPartContent>>>
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
@ -78,10 +78,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<List<MediaGroupMessage<DocumentMediaGroupPartContent>>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<DocumentMediaGroupPartContent>>, Update>? = MessagesFilterByChat,
markerFactory: MarkerFactory<in List<MediaGroupMessage<DocumentMediaGroupPartContent>>, Any> = ByChatMediaGroupMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<DocumentMediaGroupPartContent>>>
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
@ -97,10 +97,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<List<MediaGroupMessage<VisualMediaGroupPartContent>>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<VisualMediaGroupPartContent>>, Update>? = MessagesFilterByChat,
markerFactory: MarkerFactory<in List<MediaGroupMessage<VisualMediaGroupPartContent>>, Any> = ByChatMediaGroupMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<VisualMediaGroupPartContent>>>
) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
@ -116,10 +116,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<List<MediaGroupMessage<VisualMediaGroupPartContent>>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, List<MediaGroupMessage<VisualMediaGroupPartContent>>, Update>? = MessagesFilterByChat,
markerFactory: MarkerFactory<in List<MediaGroupMessage<VisualMediaGroupPartContent>>, Any> = ByChatMediaGroupMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<VisualMediaGroupPartContent>>>
) = onVisualGallery(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**

View File

@ -7,21 +7,27 @@ 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.asMediaGroupContent
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.buildJsonArray
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>,
disableNotification: Boolean = false,
@ -107,10 +113,22 @@ inline fun SendVisualMediaGroup(
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null
) = SendMediaGroup<VisualMediaGroupContent>(chatId, media, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply)
) = SendMediaGroup<VisualMediaGroupPartContent>(chatId, media, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply)
private val messagesListSerializer: KSerializer<List<MediaGroupMessage<MediaGroupContent>>>
= ListSerializer(TelegramBotAPIMessageDeserializeOnlySerializerClass())
private object MessagesListSerializer: KSerializer<PossiblySentViaBotCommonMessage<MediaGroupContent>> {
private val serializer = ListSerializer(TelegramBotAPIMessageDeserializeOnlySerializerClass<PossiblySentViaBotCommonMessage<MediaGroupPartContent>>())
override val descriptor: SerialDescriptor = serializer.descriptor
override fun deserialize(decoder: Decoder): PossiblySentViaBotCommonMessage<MediaGroupContent> {
val messages = serializer.deserialize(decoder)
return messages.asMediaGroupContent()
}
override fun serialize(encoder: Encoder, value: PossiblySentViaBotCommonMessage<MediaGroupContent>) {
serializer.serialize(encoder, value.content.group.map { it.sourceMessage })
}
}
@Serializable
data class SendMediaGroupData internal constructor(
@ -125,7 +143,7 @@ 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<List<MediaGroupMessage<MediaGroupPartContent>>>, SendMessageRequest<List<MediaGroupMessage<MediaGroupPartContent>>> {
@SerialName(mediaField)
private val convertedMedia: String
get() = buildJsonArray {
@ -138,7 +156,7 @@ data class SendMediaGroupData internal constructor(
override fun method(): String = "sendMediaGroup"
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override val resultDeserializer: DeserializationStrategy<List<MediaGroupMessage<MediaGroupContent>>>
override val resultDeserializer: DeserializationStrategy<List<MediaGroupMessage<MediaGroupPartContent>>>
get() = messagesListSerializer
}

View File

@ -7,9 +7,9 @@ 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
import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
data class ChannelMediaGroupMessage<T : MediaGroupContent>(
data class ChannelMediaGroupMessage<T : MediaGroupPartContent>(
override val messageId: MessageId,
override val chat: Chat,
override val date: DateTime,

View File

@ -6,9 +6,9 @@ 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
import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
data class CommonMediaGroupMessage<T : MediaGroupContent>(
data class CommonMediaGroupMessage<T : MediaGroupPartContent>(
override val messageId: MessageId,
override val from: User,
override val chat: Chat,

View File

@ -2,7 +2,7 @@ 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,

View File

@ -1,8 +1,8 @@
package dev.inmo.tgbotapi.types.message.abstracts
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
interface MediaGroupMessage<T : MediaGroupContent> : CommonMessage<T> {
interface MediaGroupMessage<T : MediaGroupPartContent> : CommonMessage<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

@ -15,10 +15,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 = {},
@ -73,24 +73,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 : TextedMediaContent {
@Serializable
data class PartWrapper(
val messageId: MessageId,
val content: MediaGroupPartContent,
val sourceMessage: PossiblySentViaBotCommonMessage<MediaGroupPartContent>
)
val group: List<PartWrapper>
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

@ -17,7 +17,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,
disableNotification: Boolean,

View File

@ -19,7 +19,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,
disableNotification: Boolean,

View File

@ -0,0 +1,48 @@
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.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(
override val group: List<MediaGroupCollectionContent.PartWrapper>,
override val mediaGroupId: MediaGroupIdentifier
) : MediaGroupCollectionContent {
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,
disableNotification: Boolean,
protectContent: Boolean,
replyToMessageId: MessageId?,
allowSendingWithoutReply: Boolean?,
replyMarkup: KeyboardMarkup?
): Request<out Message> = SendMediaGroup<MediaGroupPartContent>(
chatId,
group.map { it.content.toMediaGroupMemberTelegramMedia() },
disableNotification,
protectContent,
replyToMessageId,
allowSendingWithoutReply,
replyMarkup
)
}

View File

@ -17,7 +17,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 = CommonMessage<MediaGroupPartContent>
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

@ -17,7 +17,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,
disableNotification: Boolean,

View File

@ -2,12 +2,12 @@ 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.message.content.MediaGroupPartContent
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> }
override val data: List<MediaGroupMessage<MediaGroupPartContent>> = origins.mapNotNull { it.data as? MediaGroupMessage<MediaGroupPartContent> }
}

View File

@ -2,12 +2,12 @@ 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.message.content.MediaGroupPartContent
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>
override val data: MediaGroupMessage<MediaGroupPartContent> = origin.data as MediaGroupMessage<MediaGroupPartContent>
}

View File

@ -2,12 +2,12 @@ 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.message.content.MediaGroupPartContent
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>
override val data: MediaGroupMessage<MediaGroupPartContent> = origin.data as MediaGroupMessage<MediaGroupPartContent>
}

View File

@ -1,7 +1,7 @@
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.message.content.MediaGroupPartContent
import dev.inmo.tgbotapi.types.update.abstracts.*
/**
@ -14,11 +14,11 @@ import dev.inmo.tgbotapi.types.update.abstracts.*
sealed interface MediaGroupUpdate : Update
sealed interface SentMediaGroupUpdate: MediaGroupUpdate {
override val data: List<MediaGroupMessage<MediaGroupContent>>
override val data: List<MediaGroupMessage<MediaGroupPartContent>>
val origins: List<BaseMessageUpdate>
}
sealed interface EditMediaGroupUpdate : BaseEditMessageUpdate, MediaGroupUpdate {
override val data: MediaGroupMessage<MediaGroupContent>
override val data: MediaGroupMessage<MediaGroupPartContent>
val origin: BaseMessageUpdate
}

View File

@ -2,12 +2,12 @@ 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.message.content.MediaGroupPartContent
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> }
override val data: List<MediaGroupMessage<MediaGroupPartContent>> = origins.mapNotNull { it.data as? MediaGroupMessage<MediaGroupPartContent> }
}

View File

@ -0,0 +1,164 @@
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.MediaGroupMessage
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 List<CommonMessage<MediaGroupPartContent>>.asMediaGroupContent(
mediaGroupIdentifier: MediaGroupIdentifier
): PossiblySentViaBotCommonMessage<MediaGroupContent> {
val content = MediaGroupContent(
map { MediaGroupCollectionContent.PartWrapper(it.messageId, it.content, it) },
mediaGroupIdentifier
)
return when (val sourceMessage = first()) {
is MediaGroupMessage -> TODO()
is ChannelContentMessage -> ChannelContentMessageImpl(
sourceMessage.messageId,
sourceMessage.chat,
content,
sourceMessage.date,
sourceMessage.editDate,
sourceMessage.hasProtectedContent,
sourceMessage.forwardInfo,
sourceMessage.replyTo,
sourceMessage.replyMarkup,
sourceMessage.senderBot,
sourceMessage.authorSignature
)
is PrivateContentMessage -> PrivateContentMessageImpl(
sourceMessage.messageId,
sourceMessage.user,
sourceMessage.chat,
content,
sourceMessage.date,
sourceMessage.editDate,
sourceMessage.hasProtectedContent,
sourceMessage.forwardInfo,
sourceMessage.replyTo,
sourceMessage.replyMarkup,
sourceMessage.senderBot
)
is AnonymousGroupContentMessage -> AnonymousGroupContentMessageImpl(
sourceMessage.chat,
sourceMessage.messageId,
sourceMessage.date,
sourceMessage.forwardInfo,
sourceMessage.editDate,
sourceMessage.hasProtectedContent,
sourceMessage.replyTo,
sourceMessage.replyMarkup,
content,
sourceMessage.senderBot,
sourceMessage.authorSignature
)
is CommonGroupContentMessage -> CommonGroupContentMessageImpl(
sourceMessage.chat,
sourceMessage.messageId,
sourceMessage.user,
sourceMessage.date,
sourceMessage.forwardInfo,
sourceMessage.editDate,
sourceMessage.hasProtectedContent,
sourceMessage.replyTo,
sourceMessage.replyMarkup,
content,
sourceMessage.senderBot
)
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
)
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
)
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
)
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
)
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
)
}
}

View File

@ -1038,16 +1038,16 @@ inline fun Message.requireChannelEventMessage(): ChannelEventMessage<ChannelEven
this as ChannelEventMessage<ChannelEvent>
@PreviewFeature
inline fun <T> Message.whenChannelMediaGroupMessage(block: (ChannelMediaGroupMessage<MediaGroupContent>) -> T) =
inline fun <T> Message.whenChannelMediaGroupMessage(block: (ChannelMediaGroupMessage<MediaGroupPartContent>) -> T) =
asChannelMediaGroupMessage()?.let(block)
@PreviewFeature
inline fun Message.asChannelMediaGroupMessage(): ChannelMediaGroupMessage<MediaGroupContent>? =
this as? ChannelMediaGroupMessage<MediaGroupContent>
inline fun Message.asChannelMediaGroupMessage(): ChannelMediaGroupMessage<MediaGroupPartContent>? =
this as? ChannelMediaGroupMessage<MediaGroupPartContent>
@PreviewFeature
inline fun Message.requireChannelMediaGroupMessage(): ChannelMediaGroupMessage<MediaGroupContent> =
this as ChannelMediaGroupMessage<MediaGroupContent>
inline fun Message.requireChannelMediaGroupMessage(): ChannelMediaGroupMessage<MediaGroupPartContent> =
this as ChannelMediaGroupMessage<MediaGroupPartContent>
@PreviewFeature
inline fun <T> Message.whenCommonGroupEventMessage(block: (CommonGroupEventMessage<GroupEvent>) -> T) =
@ -1062,16 +1062,16 @@ inline fun Message.requireCommonGroupEventMessage(): CommonGroupEventMessage<Gro
this as CommonGroupEventMessage<GroupEvent>
@PreviewFeature
inline fun <T> Message.whenCommonMediaGroupMessage(block: (CommonMediaGroupMessage<MediaGroupContent>) -> T) =
inline fun <T> Message.whenCommonMediaGroupMessage(block: (CommonMediaGroupMessage<MediaGroupPartContent>) -> T) =
asCommonMediaGroupMessage()?.let(block)
@PreviewFeature
inline fun Message.asCommonMediaGroupMessage(): CommonMediaGroupMessage<MediaGroupContent>? =
this as? CommonMediaGroupMessage<MediaGroupContent>
inline fun Message.asCommonMediaGroupMessage(): CommonMediaGroupMessage<MediaGroupPartContent>? =
this as? CommonMediaGroupMessage<MediaGroupPartContent>
@PreviewFeature
inline fun Message.requireCommonMediaGroupMessage(): CommonMediaGroupMessage<MediaGroupContent> =
this as CommonMediaGroupMessage<MediaGroupContent>
inline fun Message.requireCommonMediaGroupMessage(): CommonMediaGroupMessage<MediaGroupPartContent> =
this as CommonMediaGroupMessage<MediaGroupPartContent>
@PreviewFeature
inline fun <T> Message.whenCommonSupergroupEventMessage(block: (CommonSupergroupEventMessage<SupergroupEvent>) -> T) =
@ -1220,16 +1220,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) =
@ -2836,26 +2836,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 +2891,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 +2910,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

@ -288,18 +288,18 @@ 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.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
@ -311,7 +311,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
@ -737,15 +737,15 @@ public inline fun <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>
CommonMediaGroupMessage<MediaGroupPartContent>? = this as?
dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
public inline fun WithUser.commonMediaGroupMessageOrThrow():
CommonMediaGroupMessage<MediaGroupContent> = this as
dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupContent>
CommonMediaGroupMessage<MediaGroupPartContent> = this as
dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
public inline fun <T>
WithUser.ifCommonMediaGroupMessage(block: (CommonMediaGroupMessage<MediaGroupContent>) -> T): T?
WithUser.ifCommonMediaGroupMessage(block: (CommonMediaGroupMessage<MediaGroupPartContent>) -> T): T?
= commonMediaGroupMessageOrNull() ?.let(block)
public inline fun WithUser.commonSupergroupEventMessageOrNull():
@ -2986,15 +2986,15 @@ public inline fun <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>
ChannelMediaGroupMessage<MediaGroupPartContent>? = this as?
dev.inmo.tgbotapi.types.message.ChannelMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
public inline fun Message.channelMediaGroupMessageOrThrow():
ChannelMediaGroupMessage<MediaGroupContent> = this as
dev.inmo.tgbotapi.types.message.ChannelMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupContent>
ChannelMediaGroupMessage<MediaGroupPartContent> = this as
dev.inmo.tgbotapi.types.message.ChannelMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
public inline fun <T>
Message.ifChannelMediaGroupMessage(block: (ChannelMediaGroupMessage<MediaGroupContent>) -> T):
Message.ifChannelMediaGroupMessage(block: (ChannelMediaGroupMessage<MediaGroupPartContent>) -> T):
T? = channelMediaGroupMessageOrNull() ?.let(block)
public inline fun Message.commonGroupEventMessageOrNull(): CommonGroupEventMessage<GroupEvent>? =
@ -3010,15 +3010,15 @@ public inline fun <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>
CommonMediaGroupMessage<MediaGroupPartContent>? = this as?
dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
public inline fun Message.commonMediaGroupMessageOrThrow():
CommonMediaGroupMessage<MediaGroupContent> = this as
dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupContent>
CommonMediaGroupMessage<MediaGroupPartContent> = this as
dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
public inline fun <T>
Message.ifCommonMediaGroupMessage(block: (CommonMediaGroupMessage<MediaGroupContent>) -> T): T?
Message.ifCommonMediaGroupMessage(block: (CommonMediaGroupMessage<MediaGroupPartContent>) -> T): T?
= commonMediaGroupMessageOrNull() ?.let(block)
public inline fun Message.commonSupergroupEventMessageOrNull():
@ -3325,15 +3325,15 @@ public inline fun <T>
Message.ifCommonForumContentMessage(block: (CommonForumContentMessage<MessageContent>) -> T): T?
= commonForumContentMessageOrNull() ?.let(block)
public inline fun Message.mediaGroupMessageOrNull(): MediaGroupMessage<MediaGroupContent>? = this
public inline fun Message.mediaGroupMessageOrNull(): MediaGroupMessage<MediaGroupPartContent>? = this
as?
dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupContent>
dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
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 Message.mediaGroupMessageOrThrow(): MediaGroupMessage<MediaGroupPartContent> = this as
dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage<dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent>
public inline fun <T>
Message.ifMediaGroupMessage(block: (MediaGroupMessage<MediaGroupContent>) -> T): T? =
Message.ifMediaGroupMessage(block: (MediaGroupMessage<MediaGroupPartContent>) -> T): T? =
mediaGroupMessageOrNull() ?.let(block)
public inline fun Message.unknownMessageTypeOrNull(): UnknownMessageType? = this as?
@ -3459,33 +3459,33 @@ 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.audioMediaGroupContentOrNull(): 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.audioMediaGroupContentOrThrow(): AudioMediaGroupPartContent = this
as dev.inmo.tgbotapi.types.message.content.AudioMediaGroupPartContent
public inline fun <T>
ResendableContent.ifAudioMediaGroupContent(block: (AudioMediaGroupContent) -> T): T? =
ResendableContent.ifAudioMediaGroupContent(block: (AudioMediaGroupPartContent) -> T): T? =
audioMediaGroupContentOrNull() ?.let(block)
public inline fun ResendableContent.documentMediaGroupContentOrNull(): DocumentMediaGroupContent? =
this as? dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
public inline fun ResendableContent.documentMediaGroupContentOrNull(): 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.documentMediaGroupContentOrThrow(): DocumentMediaGroupPartContent =
this as dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupPartContent
public inline fun <T>
ResendableContent.ifDocumentMediaGroupContent(block: (DocumentMediaGroupContent) -> T): T? =
ResendableContent.ifDocumentMediaGroupContent(block: (DocumentMediaGroupPartContent) -> T): T? =
documentMediaGroupContentOrNull() ?.let(block)
public inline fun ResendableContent.mediaGroupContentOrNull(): MediaGroupContent? = this as?
dev.inmo.tgbotapi.types.message.content.MediaGroupContent
public inline fun ResendableContent.mediaGroupContentOrNull(): MediaGroupPartContent? = this as?
dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
public inline fun ResendableContent.mediaGroupContentOrThrow(): MediaGroupContent = this as
dev.inmo.tgbotapi.types.message.content.MediaGroupContent
public inline fun ResendableContent.mediaGroupContentOrThrow(): MediaGroupPartContent = this as
dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
public inline fun <T> ResendableContent.ifMediaGroupContent(block: (MediaGroupContent) -> T): T? =
public inline fun <T> ResendableContent.ifMediaGroupContent(block: (MediaGroupPartContent) -> T): T? =
mediaGroupContentOrNull() ?.let(block)
public inline fun ResendableContent.textedMediaContentOrNull(): TextedMediaContent? = this as?
@ -3497,14 +3497,14 @@ 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.visualMediaGroupContentOrNull(): VisualMediaGroupPartContent? = this
as? dev.inmo.tgbotapi.types.message.content.VisualMediaGroupPartContent
public inline fun ResendableContent.visualMediaGroupContentOrThrow(): VisualMediaGroupContent = this
as dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
public inline fun ResendableContent.visualMediaGroupContentOrThrow(): VisualMediaGroupPartContent = this
as dev.inmo.tgbotapi.types.message.content.VisualMediaGroupPartContent
public inline fun <T>
ResendableContent.ifVisualMediaGroupContent(block: (VisualMediaGroupContent) -> T): T? =
ResendableContent.ifVisualMediaGroupContent(block: (VisualMediaGroupPartContent) -> T): T? =
visualMediaGroupContentOrNull() ?.let(block)
public inline fun ResendableContent.animationContentOrNull(): AnimationContent? = this as?

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 }
@ -37,5 +37,5 @@ 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>()!!
inline fun <reified T : MediaGroupPartContent> MediaGroupMessage<*>.withContentOrNull() = if (content is T) { this as MediaGroupMessage<T> } else { null }
inline fun <reified T : MediaGroupPartContent> MediaGroupMessage<*>.withContentOrThrow() = withContentOrNull<T>()!!

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<*>.withContent() = if (content is T) { this as ContentMessage<T> } else { null }
@ -37,5 +37,5 @@ 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>()!!
inline fun <reified T : MediaGroupPartContent> MediaGroupMessage<*>.withContent() = if (content is T) { this as MediaGroupMessage<T> } else { null }
inline fun <reified T : MediaGroupPartContent> MediaGroupMessage<*>.requireWithContent() = withContent<T>()!!

View File

@ -31,7 +31,7 @@ inline fun <reified T: MessageContent> Flow<BaseSentMessageUpdate>.filterContent
): Flow<ContentMessage<T>> = asContentMessagesFlow().mapNotNull(filterForContentMessage())
@RiskFeature("This method is low-level")
inline fun <reified T : MediaGroupContent> Flow<SentMediaGroupUpdate>.filterMediaGroupMessages(
inline fun <reified T : MediaGroupPartContent> Flow<SentMediaGroupUpdate>.filterMediaGroupMessages(
): Flow<List<CommonMessage<T>>> = map {
it.data.mapNotNull { message ->
if (message.content is T) {
@ -69,7 +69,7 @@ inline fun <reified T: MessageContent> FlowsUpdatesFilter.filterContentMessages(
*/
@Suppress("UNCHECKED_CAST")
@RiskFeature(lowLevelRiskFeatureMessage)
inline fun <reified T: MediaGroupContent> FlowsUpdatesFilter.filterMediaGroupMessages(
inline fun <reified T: MediaGroupPartContent> FlowsUpdatesFilter.filterMediaGroupMessages(
scopeToIncludeChannels: CoroutineScope? = null
): Flow<List<CommonMessage<T>>> {
return (scopeToIncludeChannels ?.let { scope ->
@ -212,10 +212,10 @@ fun FlowsUpdatesFilter.voiceMessages(
) = filterContentMessages<VoiceContent>(scopeToIncludeChannels)
fun Flow<SentMediaGroupUpdate>.mediaGroupMessages() = filterMediaGroupMessages<MediaGroupContent>()
fun Flow<SentMediaGroupUpdate>.mediaGroupMessages() = filterMediaGroupMessages<MediaGroupPartContent>()
fun FlowsUpdatesFilter.mediaGroupMessages(
scopeToIncludeChannels: CoroutineScope? = null
) = filterMediaGroupMessages<MediaGroupContent>(scopeToIncludeChannels)
) = filterMediaGroupMessages<MediaGroupPartContent>(scopeToIncludeChannels)
fun Flow<SentMediaGroupUpdate>.mediaGroupPhotosMessages() = filterMediaGroupMessages<PhotoContent>()
fun FlowsUpdatesFilter.mediaGroupPhotosMessages(
@ -227,10 +227,10 @@ fun FlowsUpdatesFilter.mediaGroupVideosMessages(
scopeToIncludeChannels: CoroutineScope? = null
) = filterMediaGroupMessages<VideoContent>(scopeToIncludeChannels)
fun Flow<SentMediaGroupUpdate>.mediaGroupVisualMessages() = filterMediaGroupMessages<VisualMediaGroupContent>()
fun Flow<SentMediaGroupUpdate>.mediaGroupVisualMessages() = filterMediaGroupMessages<VisualMediaGroupPartContent>()
fun FlowsUpdatesFilter.mediaGroupVisualMessages(
scopeToIncludeChannels: CoroutineScope? = null
) = filterMediaGroupMessages<VisualMediaGroupContent>(scopeToIncludeChannels)
) = filterMediaGroupMessages<VisualMediaGroupPartContent>(scopeToIncludeChannels)
fun Flow<SentMediaGroupUpdate>.mediaGroupAudioMessages() = filterMediaGroupMessages<AudioContent>()
fun FlowsUpdatesFilter.mediaGroupAudioMessages(

View File

@ -5,14 +5,14 @@ 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.message.content.MediaGroupPartContent
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
val List<CommonMessage<out MediaGroupContent>>.forwardInfo: ForwardInfo?
val List<CommonMessage<out MediaGroupPartContent>>.forwardInfo: ForwardInfo?
get() = firstOrNull() ?.forwardInfo
val List<CommonMessage<out MediaGroupContent>>.replyTo: Message?
val List<CommonMessage<out MediaGroupPartContent>>.replyTo: Message?
get() = firstOrNull() ?.replyTo
val List<CommonMessage<out MediaGroupContent>>.chat: Chat?
val List<CommonMessage<out MediaGroupPartContent>>.chat: Chat?
get() = firstOrNull() ?.chat
val List<MediaGroupMessage<*>>.mediaGroupId: MediaGroupIdentifier?
get() = firstOrNull() ?.mediaGroupId
@ -26,12 +26,12 @@ val SentMediaGroupUpdate.chat: Chat
val SentMediaGroupUpdate.mediaGroupId: MediaGroupIdentifier
get() = data.mediaGroupId!!
fun List<CommonMessage<MediaGroupContent>>.createResend(
fun List<CommonMessage<MediaGroupPartContent>>.createResend(
chatId: ChatId,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyTo: MessageId? = null
) = SendMediaGroup<MediaGroupContent>(
) = SendMediaGroup<MediaGroupPartContent>(
chatId,
map { it.content.toMediaGroupMemberTelegramMedia() },
disableNotification,
@ -39,7 +39,7 @@ fun List<CommonMessage<MediaGroupContent>>.createResend(
replyTo
)
fun List<CommonMessage<MediaGroupContent>>.createResend(
fun List<CommonMessage<MediaGroupPartContent>>.createResend(
chat: Chat,
disableNotification: Boolean = false,
protectContent: Boolean = false,