diff --git a/CHANGELOG.md b/CHANGELOG.md index fefe59271c..4615bb46f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ __All the `tgbotapi.extensions.*` packages have been removed__ * `dev.inmo.tgbotapi.types.CommonBot` -> `dev.inmo.tgbotapi.types.chat.CommonBot` * `dev.inmo.tgbotapi.types.ExtendedBot` -> `dev.inmo.tgbotapi.types.chat.ExtendedBot` * `dev.inmo.tgbotapi.types.UserSerializer` -> `dev.inmo.tgbotapi.types.chat.UserSerializer` + * **All `InputMedia` has been renamed as `TelegramMedia`. Migration:** `InputMedia` -> `TelegramMedia` + * `dev.inmo.tgbotapi.types.InputMedia` -> `dev.inmo.tgbotapi.types.media` * Constructor of `UnknownInlineKeyboardButton` is not internal and can be created with any `json` ([#563](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/563)) * All the interfaces from `dev.inmo.tgbotapi.types.files.abstracts` have been replaced to `dev.inmo.tgbotapi.types.files` and converted to sealed ([#550](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/550)) * `PassportFile` has been replaced to `dev.inmo.tgbotapi.types.files` diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/media/EditChatMessageMedia.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/media/EditChatMessageMedia.kt index 6b01d92ce7..c4d399d6ee 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/media/EditChatMessageMedia.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/media/EditChatMessageMedia.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.extensions.api.edit.media import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.edit.media.EditChatMessageMedia import dev.inmo.tgbotapi.types.ChatIdentifier -import dev.inmo.tgbotapi.types.InputMedia.InputMedia +import dev.inmo.tgbotapi.types.media.TelegramMedia import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.Chat @@ -17,7 +17,7 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent suspend fun TelegramBot.editMessageMedia( chatId: ChatIdentifier, messageId: MessageIdentifier, - media: InputMedia, + media: TelegramMedia, replyMarkup: InlineKeyboardMarkup? = null ) = execute( EditChatMessageMedia(chatId, messageId, media, replyMarkup) @@ -30,7 +30,7 @@ suspend fun TelegramBot.editMessageMedia( suspend fun TelegramBot.editMessageMedia( chat: Chat, messageId: MessageIdentifier, - media: InputMedia, + media: TelegramMedia, replyMarkup: InlineKeyboardMarkup? = null ) = editMessageMedia(chat.id, messageId, media, replyMarkup) @@ -40,6 +40,6 @@ suspend fun TelegramBot.editMessageMedia( */ suspend fun TelegramBot.editMessageMedia( message: ContentMessage, - media: InputMedia, + media: TelegramMedia, replyMarkup: InlineKeyboardMarkup? = null ) = editMessageMedia(message.chat.id, message.messageId, media, replyMarkup) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/media/EditInlineMessageMedia.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/media/EditInlineMessageMedia.kt index dec47763cc..660e62bfcc 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/media/EditInlineMessageMedia.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/media/EditInlineMessageMedia.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.extensions.api.edit.media import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.edit.media.EditInlineMessageMedia import dev.inmo.tgbotapi.types.InlineMessageIdentifier -import dev.inmo.tgbotapi.types.InputMedia.InputMedia +import dev.inmo.tgbotapi.types.media.TelegramMedia import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup /** @@ -12,6 +12,6 @@ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup */ suspend fun TelegramBot.editMessageCaption( inlineMessageId: InlineMessageIdentifier, - media: InputMedia, + media: TelegramMedia, replyMarkup: InlineKeyboardMarkup? = null ) = execute(EditInlineMessageMedia(inlineMessageId, media, replyMarkup)) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt index 814c1334c5..822226ff41 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt @@ -3,7 +3,7 @@ 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.InputMedia.* +import dev.inmo.tgbotapi.types.media.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.ParseMode.ParseMode @@ -26,13 +26,13 @@ suspend inline fun TelegramBot.copyMessages( replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null ): List> { - val first = messages.first().content.toMediaGroupMemberInputMedia().let { + val first = messages.first().content.toMediaGroupMemberTelegramMedia().let { if (text != null) { when (it) { - is InputMediaAudio -> it.copy(text = text, parseMode = parseMode) - is InputMediaDocument -> it.copy(text = text, parseMode = parseMode) - is InputMediaPhoto -> it.copy(text = text, parseMode = parseMode) - is InputMediaVideo -> it.copy(text = text, parseMode = parseMode) + 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 @@ -42,7 +42,7 @@ suspend inline fun TelegramBot.copyMessages( return sendMediaGroup( toChatId, listOf(first) + messages.drop(1).map { - it.content.toMediaGroupMemberInputMedia() + it.content.toMediaGroupMemberTelegramMedia() }, disableNotification, protectContent, @@ -109,19 +109,19 @@ suspend inline fun TelegramBot.copyMessages( replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null ): List> { - val first = messages.first().content.toMediaGroupMemberInputMedia().let { + val first = messages.first().content.toMediaGroupMemberTelegramMedia().let { when (it) { - is InputMediaAudio -> InputMediaAudio(it.file, entities, it.duration, it.performer, it.title, it.thumb) - is InputMediaDocument -> InputMediaDocument(it.file, entities, it.thumb, it.disableContentTypeDetection) - is InputMediaPhoto -> InputMediaPhoto(it.file, entities) - is InputMediaVideo -> InputMediaVideo(it.file, entities, it.width, it.height, it.duration, it.thumb) + 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.toMediaGroupMemberInputMedia() + it.content.toMediaGroupMemberTelegramMedia() }, disableNotification, protectContent, diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt index f672bd6007..e33972ae93 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt @@ -9,7 +9,7 @@ import dev.inmo.tgbotapi.extensions.api.send.polls.sendRegularPoll import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.rawSendingMediaGroupsWarning import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.InputMedia.* +import dev.inmo.tgbotapi.types.media.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList import dev.inmo.tgbotapi.types.ParseMode.ParseMode @@ -524,7 +524,7 @@ suspend inline fun TelegramBot.reply( @RiskFeature(rawSendingMediaGroupsWarning) suspend inline fun TelegramBot.replyWithMediaGroup( to: Message, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null @@ -532,7 +532,7 @@ suspend inline fun TelegramBot.replyWithMediaGroup( suspend inline fun TelegramBot.replyWithPlaylist( to: Message, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null @@ -540,7 +540,7 @@ suspend inline fun TelegramBot.replyWithPlaylist( suspend inline fun TelegramBot.replyWithDocuments( to: Message, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null @@ -548,7 +548,7 @@ suspend inline fun TelegramBot.replyWithDocuments( suspend inline fun TelegramBot.replyWithGallery( to: Message, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt index 31c0770ec5..f227a81491 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.extensions.api.send.media import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.send.media.* import dev.inmo.tgbotapi.types.ChatIdentifier -import dev.inmo.tgbotapi.types.InputMedia.* +import dev.inmo.tgbotapi.types.media.* import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.message.content.media.MediaGroupContent @@ -19,7 +19,7 @@ import kotlin.jvm.JvmName @RiskFeature(rawSendingMediaGroupsWarning) suspend fun TelegramBot.sendMediaGroup( chatId: ChatIdentifier, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageIdentifier? = null, @@ -36,7 +36,7 @@ suspend fun TelegramBot.sendMediaGroup( @RiskFeature(rawSendingMediaGroupsWarning) suspend fun TelegramBot.sendMediaGroup( chat: Chat, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageIdentifier? = null, @@ -58,7 +58,7 @@ suspend fun TelegramBot.sendMediaGroup( replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null ) = sendMediaGroup( - chatId, media.map { it.toMediaGroupMemberInputMedia() }, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply + chatId, media.map { it.toMediaGroupMemberTelegramMedia() }, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply ) /** @@ -82,7 +82,7 @@ suspend fun TelegramBot.sendMediaGroup( */ suspend fun TelegramBot.sendPlaylist( chatId: ChatIdentifier, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageIdentifier? = null, @@ -98,7 +98,7 @@ suspend fun TelegramBot.sendPlaylist( */ suspend fun TelegramBot.sendPlaylist( chat: Chat, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageIdentifier? = null, @@ -119,7 +119,7 @@ suspend fun TelegramBot.sendPlaylist( replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null ) = sendPlaylist( - chatId, media.map { it.toMediaGroupMemberInputMedia() }, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply + chatId, media.map { it.toMediaGroupMemberTelegramMedia() }, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply ) /** @@ -142,7 +142,7 @@ suspend fun TelegramBot.sendPlaylist( */ suspend fun TelegramBot.sendDocumentsGroup( chatId: ChatIdentifier, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageIdentifier? = null, @@ -158,7 +158,7 @@ suspend fun TelegramBot.sendDocumentsGroup( */ suspend fun TelegramBot.sendDocumentsGroup( chat: Chat, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageIdentifier? = null, @@ -179,7 +179,7 @@ suspend fun TelegramBot.sendDocumentsGroup( replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null ) = sendDocumentsGroup( - chatId, media.map { it.toMediaGroupMemberInputMedia() }, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply + chatId, media.map { it.toMediaGroupMemberTelegramMedia() }, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply ) /** @@ -202,7 +202,7 @@ suspend fun TelegramBot.sendDocumentsGroup( */ suspend fun TelegramBot.sendVisualMediaGroup( chatId: ChatIdentifier, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageIdentifier? = null, @@ -218,7 +218,7 @@ suspend fun TelegramBot.sendVisualMediaGroup( */ suspend fun TelegramBot.sendVisualMediaGroup( chat: Chat, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageIdentifier? = null, @@ -239,7 +239,7 @@ suspend fun TelegramBot.sendVisualMediaGroup( replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null ) = sendVisualMediaGroup( - chatId, media.map { it.toMediaGroupMemberInputMedia() }, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply + chatId, media.map { it.toMediaGroupMemberTelegramMedia() }, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply ) /** diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditMediaMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditMediaMessage.kt index aaaceea53e..ec68b4aff0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditMediaMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditMediaMessage.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.requests.edit.abstracts -import dev.inmo.tgbotapi.types.InputMedia.InputMedia +import dev.inmo.tgbotapi.types.media.TelegramMedia interface EditMediaMessage { - val media: InputMedia -} \ No newline at end of file + val media: TelegramMedia +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/media/EditChatMessageMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/media/EditChatMessageMedia.kt index 4516afdfd3..f3b6fd3362 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/media/EditChatMessageMedia.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/media/EditChatMessageMedia.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.requests.edit.media import dev.inmo.tgbotapi.requests.abstracts.MultipartFile import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.InputMedia.InputMedia +import dev.inmo.tgbotapi.types.media.TelegramMedia import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass @@ -21,7 +21,7 @@ data class EditChatMessageMedia( @SerialName(messageIdField) override val messageId: MessageIdentifier, @SerialName(mediaField) - override val media: InputMedia, + override val media: TelegramMedia, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : EditChatMessage, EditReplyMessage, EditMediaMessage { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/media/EditInlineMessageMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/media/EditInlineMessageMedia.kt index 1a9246cb06..166b032477 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/media/EditInlineMessageMedia.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/media/EditInlineMessageMedia.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.requests.edit.media import dev.inmo.tgbotapi.requests.abstracts.MultipartFile import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.InputMedia.InputMedia +import dev.inmo.tgbotapi.types.media.TelegramMedia import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.* @@ -12,7 +12,7 @@ data class EditInlineMessageMedia( @SerialName(inlineMessageIdField) override val inlineMessageId: InlineMessageIdentifier, @SerialName(mediaField) - override val media: InputMedia, + override val media: TelegramMedia, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : EditInlineMessage, EditReplyMessage, EditMediaMessage { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt index 794a054f34..38d089e0be 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt @@ -5,7 +5,7 @@ import dev.inmo.tgbotapi.requests.abstracts.Request 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.InputMedia.* +import dev.inmo.tgbotapi.types.media.* import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializerClass import dev.inmo.tgbotapi.types.message.content.media.MediaGroupContent @@ -23,7 +23,7 @@ const val rawSendingMediaGroupsWarning = "Media groups contains restrictions rel @RiskFeature(rawSendingMediaGroupsWarning) fun SendMediaGroup( chatId: ChatIdentifier, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageIdentifier? = null, @@ -36,7 +36,7 @@ fun SendMediaGroup( val files: List = media.flatMap { listOfNotNull( it.file as? MultipartFile, - if (it is ThumbedInputMedia) { + if (it is ThumbedTelegramMedia) { it.thumb as? MultipartFile } else { null @@ -66,12 +66,12 @@ fun SendMediaGroup( /** * Use this method to be sure that you are correctly sending playlist with audios * - * @see InputMediaAudio + * @see TelegramMediaAudio */ @Suppress("NOTHING_TO_INLINE") inline fun SendPlaylist( chatId: ChatIdentifier, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageIdentifier? = null, @@ -81,12 +81,12 @@ inline fun SendPlaylist( /** * Use this method to be sure that you are correctly sending documents media group * - * @see InputMediaDocument + * @see TelegramMediaDocument */ @Suppress("NOTHING_TO_INLINE") inline fun SendDocumentsGroup( chatId: ChatIdentifier, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageIdentifier? = null, @@ -96,13 +96,13 @@ inline fun SendDocumentsGroup( /** * Use this method to be sure that you are correctly sending visual media group * - * @see InputMediaPhoto - * @see InputMediaVideo + * @see TelegramMediaPhoto + * @see TelegramMediaVideo */ @Suppress("NOTHING_TO_INLINE") inline fun SendVisualMediaGroup( chatId: ChatIdentifier, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageIdentifier? = null, @@ -116,7 +116,7 @@ private val messagesListSerializer: KSerializer = emptyList(), + val media: List = emptyList(), @SerialName(disableNotificationField) override val disableNotification: Boolean = false, @SerialName(protectContentField) @@ -130,7 +130,7 @@ data class SendMediaGroupData internal constructor( private val convertedMedia: String get() = buildJsonArray { media.forEach { - add(it.toJsonWithoutNulls(MediaGroupMemberInputMediaSerializer)) + add(it.toJsonWithoutNulls(MediaGroupMemberTelegramMediaSerializer)) } }.toString() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/DuratedInputMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/DuratedInputMedia.kt deleted file mode 100644 index ed7af3d902..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/DuratedInputMedia.kt +++ /dev/null @@ -1,5 +0,0 @@ -package dev.inmo.tgbotapi.types.InputMedia - -sealed interface DuratedInputMedia : InputMedia { - val duration: Long? -} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt index e038e9fef1..d6876a575f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt @@ -1,17 +1,13 @@ package dev.inmo.tgbotapi.types.InputMedia -import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput import dev.inmo.tgbotapi.requests.abstracts.InputFile -import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend -import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList +import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.types.ParseMode.parseModeField +import dev.inmo.tgbotapi.types.media.TelegramMediaAnimation import dev.inmo.tgbotapi.utils.extensions.makeString -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable +@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaAnimation", "dev.inmo.tgbotapi.types.media.TelegramMediaAnimation")) fun InputMediaAnimation( file: InputFile, text: String? = null, @@ -20,8 +16,9 @@ fun InputMediaAnimation( height: Int? = null, duration: Long? = null, thumb: InputFile? = null -) = InputMediaAnimation(file, text, parseMode, null, width, height, duration, thumb) +) = TelegramMediaAnimation(file, text, parseMode, null, width, height, duration, thumb) +@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaAnimation", "dev.inmo.tgbotapi.types.media.TelegramMediaAnimation")) fun InputMediaAnimation( file: InputFile, entities: TextSourcesList, @@ -29,7 +26,7 @@ fun InputMediaAnimation( height: Int? = null, duration: Long? = null, thumb: InputFile? = null -) = InputMediaAnimation( +) = TelegramMediaAnimation( file, entities.makeString(), null, @@ -40,26 +37,3 @@ fun InputMediaAnimation( thumb ) -@Serializable -data class InputMediaAnimation internal constructor( - override val file: InputFile, - @SerialName(captionField) - override val text: String? = null, - @SerialName(parseModeField) - override val parseMode: ParseMode? = null, - @SerialName(captionEntitiesField) - private val rawEntities: List? = null, - override val width: Int? = null, - override val height: Int? = null, - override val duration: Long? = null, - override val thumb: InputFile? = null -) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, TextedOutput { - override val type: String = "animation" - override val textSources: TextSourcesList? by lazy { - rawEntities ?.asTextSources(text ?: return@lazy null) - } - - @SerialName(mediaField) - override val media: String - init { media = file.fileIdToSend } // crutch until js compiling will be fixed -} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt index 74ec4d15cf..95a9ab738a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt @@ -1,19 +1,14 @@ package dev.inmo.tgbotapi.types.InputMedia -import dev.inmo.tgbotapi.CommonAbstracts.Performerable import dev.inmo.tgbotapi.requests.abstracts.InputFile -import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend -import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList +import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.files.AudioFile +import dev.inmo.tgbotapi.types.media.TelegramMediaAudio import dev.inmo.tgbotapi.utils.extensions.makeString -import kotlinx.serialization.* - -internal const val audioInputMediaType = "audio" +@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaAudio", "dev.inmo.tgbotapi.types.media.TelegramMediaAudio")) fun InputMediaAudio( file: InputFile, entities: TextSourcesList, @@ -21,10 +16,11 @@ fun InputMediaAudio( performer: String? = null, title: String? = null, thumb: InputFile? = null -) = InputMediaAudio( +) = TelegramMediaAudio( file, entities.makeString(), null, entities.toRawMessageEntities(), duration, performer, title, thumb ) +@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaAudio", "dev.inmo.tgbotapi.types.media.TelegramMediaAudio")) fun InputMediaAudio( file: InputFile, text: String? = null, @@ -33,41 +29,16 @@ fun InputMediaAudio( performer: String? = null, title: String? = null, thumb: InputFile? = null -) = InputMediaAudio( +) = TelegramMediaAudio( file, text, parseMode, null, duration, performer, title, thumb ) -@Serializable -data class InputMediaAudio internal constructor( - override val file: InputFile, - @SerialName(captionField) - override val text: String? = null, - @SerialName(parseModeField) - override val parseMode: ParseMode? = null, - @SerialName(captionEntitiesField) - private val rawEntities: List? = null, - override val duration: Long? = null, - override val performer: String? = null, - override val title: String? = null, - override val thumb: InputFile? = null -) : InputMedia, AudioMediaGroupMemberInputMedia, DuratedInputMedia, ThumbedInputMedia, TitledInputMedia, Performerable { - override val type: String = audioInputMediaType - override val textSources: TextSourcesList? by lazy { - rawEntities ?.asTextSources(text ?: return@lazy null) - } - - override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) - - @SerialName(mediaField) - override val media: String - init { media = file.fileIdToSend } // crutch until js compiling will be fixed -} - +@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaAudio", "dev.inmo.tgbotapi.types.media.TelegramMediaAudio")) fun AudioFile.toInputMediaAudio( text: String? = null, parseMode: ParseMode? = null, title: String? = this.title -): InputMediaAudio = InputMediaAudio( +): InputMediaAudio = TelegramMediaAudio( fileId, text, parseMode, @@ -77,10 +48,11 @@ fun AudioFile.toInputMediaAudio( thumb ?.fileId ) +@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaAudio", "dev.inmo.tgbotapi.types.media.TelegramMediaAudio")) fun AudioFile.toInputMediaAudio( textSources: TextSourcesList = emptyList(), title: String? = this.title -): InputMediaAudio = InputMediaAudio( +): InputMediaAudio = TelegramMediaAudio( fileId, textSources, duration, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt index 7c503c4431..889d165fd4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt @@ -1,31 +1,29 @@ package dev.inmo.tgbotapi.types.InputMedia -import dev.inmo.tgbotapi.requests.abstracts.* -import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList +import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.files.DocumentFile +import dev.inmo.tgbotapi.types.media.TelegramMediaDocument import dev.inmo.tgbotapi.utils.extensions.makeString -import kotlinx.serialization.* - -internal const val documentInputMediaType = "document" +@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaDocument", "dev.inmo.tgbotapi.types.media.TelegramMediaDocument")) fun InputMediaDocument( file: InputFile, text: String? = null, parseMode: ParseMode? = null, thumb: InputFile? = null, disableContentTypeDetection: Boolean? = null -) = InputMediaDocument(file, text, parseMode, null, thumb, disableContentTypeDetection) +) = TelegramMediaDocument(file, text, parseMode, null, thumb, disableContentTypeDetection) +@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaDocument", "dev.inmo.tgbotapi.types.media.TelegramMediaDocument")) fun InputMediaDocument( file: InputFile, entities: TextSourcesList, thumb: InputFile? = null, disableContentTypeDetection: Boolean? = null -) = InputMediaDocument( +) = TelegramMediaDocument( file, entities.makeString(), null, @@ -34,54 +32,21 @@ fun InputMediaDocument( disableContentTypeDetection ) -/** - * Represents a general file to be sent. See https://core.telegram.org/bots/api#inputmediadocument - * - * @param disableContentTypeDetection Disables automatic server-side content type detection for files uploaded using - * multipart/form-data. Always used by Telegram system as true, if the document is sent as part of an album. - * - * @see InputFile - * @see MultipartFile - * @see FileId - */ -@Serializable -data class InputMediaDocument internal constructor( - override val file: InputFile, - @SerialName(captionField) - override val text: String? = null, - @SerialName(parseModeField) - override val parseMode: ParseMode? = null, - @SerialName(captionEntitiesField) - private val rawEntities: List? = null, - override val thumb: InputFile? = null, - @SerialName(disableContentTypeDetectionField) - val disableContentTypeDetection: Boolean? = null -) : InputMedia, DocumentMediaGroupMemberInputMedia, ThumbedInputMedia { - override val type: String = documentInputMediaType - override val textSources: TextSourcesList? by lazy { - rawEntities ?.asTextSources(text ?: return@lazy null) - } - - override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) - - @SerialName(mediaField) - override val media: String - init { media = file.fileIdToSend } // crutch until js compiling will be fixed -} - +@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaDocument", "dev.inmo.tgbotapi.types.media.TelegramMediaDocument")) fun DocumentFile.toInputMediaDocument( text: String? = null, parseMode: ParseMode? = null -) = InputMediaDocument( +) = TelegramMediaDocument( fileId, text, parseMode, thumb ?.fileId ) +@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaDocument", "dev.inmo.tgbotapi.types.media.TelegramMediaDocument")) fun DocumentFile.toInputMediaDocument( textSources: TextSourcesList = emptyList() -) = InputMediaDocument( +) = TelegramMediaDocument( fileId, textSources, thumb ?.fileId diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt index 1e74d24566..6ddce73949 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt @@ -1,63 +1,40 @@ package dev.inmo.tgbotapi.types.InputMedia import dev.inmo.tgbotapi.requests.abstracts.InputFile -import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend -import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList +import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.files.PhotoSize +import dev.inmo.tgbotapi.types.media.TelegramMediaPhoto import dev.inmo.tgbotapi.utils.extensions.makeString -import kotlinx.serialization.* - -internal const val photoInputMediaType = "photo" +@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaPhoto", "dev.inmo.tgbotapi.types.media.TelegramMediaPhoto")) fun InputMediaPhoto( file: InputFile, text: String? = null, parseMode: ParseMode? = null -) = InputMediaPhoto(file, text, parseMode, null) +) = TelegramMediaPhoto(file, text, parseMode, null) +@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaPhoto", "dev.inmo.tgbotapi.types.media.TelegramMediaPhoto")) fun InputMediaPhoto( file: InputFile, entities: TextSourcesList -) = InputMediaPhoto(file, entities.makeString(), null, entities.toRawMessageEntities()) - -@Serializable -data class InputMediaPhoto internal constructor( - override val file: InputFile, - @SerialName(captionField) - override val text: String? = null, - @SerialName(parseModeField) - override val parseMode: ParseMode? = null, - @SerialName(captionEntitiesField) - private val rawEntities: List? = null -) : InputMedia, VisualMediaGroupMemberInputMedia { - override val type: String = photoInputMediaType - override val textSources: TextSourcesList? by lazy { - rawEntities ?.asTextSources(text ?: return@lazy null) - } - - override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) - - @SerialName(mediaField) - override val media: String - init { media = file.fileIdToSend } // crutch until js compiling will be fixed -} +) = TelegramMediaPhoto(file, entities.makeString(), null, entities.toRawMessageEntities()) +@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaPhoto", "dev.inmo.tgbotapi.types.media.TelegramMediaPhoto")) fun PhotoSize.toInputMediaPhoto( text: String? = null, parseMode: ParseMode? = null -): InputMediaPhoto = InputMediaPhoto( +): InputMediaPhoto = TelegramMediaPhoto( fileId, text, parseMode ) +@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaPhoto", "dev.inmo.tgbotapi.types.media.TelegramMediaPhoto")) fun PhotoSize.toInputMediaPhoto( textSources: TextSourcesList = emptyList() -): InputMediaPhoto = InputMediaPhoto( +): InputMediaPhoto = TelegramMediaPhoto( fileId, textSources ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaSerializer.kt deleted file mode 100644 index 5a6bf23735..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaSerializer.kt +++ /dev/null @@ -1,28 +0,0 @@ -package dev.inmo.tgbotapi.types.InputMedia - -import dev.inmo.tgbotapi.utils.RiskFeature -import kotlinx.serialization.InternalSerializationApi -import kotlinx.serialization.KSerializer -import kotlinx.serialization.descriptors.* -import kotlinx.serialization.encoding.Decoder -import kotlinx.serialization.encoding.Encoder - -@RiskFeature -object InputMediaSerializer : KSerializer { - @OptIn(InternalSerializationApi::class) - override val descriptor: SerialDescriptor = buildSerialDescriptor(InputMedia::class.toString(), PolymorphicKind.OPEN) - override fun serialize(encoder: Encoder, value: InputMedia) { - when (value) { - is InputMediaVideo -> InputMediaVideo.serializer().serialize(encoder, value) - is InputMediaAudio -> InputMediaAudio.serializer().serialize(encoder, value) - is InputMediaPhoto -> InputMediaPhoto.serializer().serialize(encoder, value) - is InputMediaAnimation -> InputMediaAnimation.serializer().serialize(encoder, value) - is InputMediaDocument -> InputMediaDocument.serializer().serialize(encoder, value) - else -> throw IllegalArgumentException("Can't perform and serialize $value") - } - } - - override fun deserialize(decoder: Decoder): InputMedia { - throw IllegalStateException("Object can't be deserialized") - } -} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt index 243f14131a..28459ba9d6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt @@ -1,17 +1,13 @@ package dev.inmo.tgbotapi.types.InputMedia import dev.inmo.tgbotapi.requests.abstracts.InputFile -import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend -import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList +import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.types.ParseMode.parseModeField +import dev.inmo.tgbotapi.types.media.TelegramMediaVideo import dev.inmo.tgbotapi.utils.extensions.makeString -import kotlinx.serialization.* - -internal const val videoInputMediaType = "video" +@Deprecated("Replaced and renamed", ReplaceWith("TelegramMediaVideo", "dev.inmo.tgbotapi.types.media.TelegramMediaVideo")) fun InputMediaVideo( file: InputFile, text: String? = null, @@ -20,7 +16,7 @@ fun InputMediaVideo( height: Int? = null, duration: Long? = null, thumb: InputFile? = null -) = InputMediaVideo(file, text, parseMode, null, width, height, duration, thumb) +) = TelegramMediaVideo(file, text, parseMode, null, width, height, duration, thumb) fun InputMediaVideo( file: InputFile, @@ -29,30 +25,4 @@ fun InputMediaVideo( height: Int? = null, duration: Long? = null, thumb: InputFile? = null -) = InputMediaVideo(file, entities.makeString(), null, entities.toRawMessageEntities(), width, height, duration, thumb) - -@Serializable -data class InputMediaVideo internal constructor ( - override val file: InputFile, - @SerialName(captionField) - override val text: String? = null, - @SerialName(parseModeField) - override val parseMode: ParseMode? = null, - @SerialName(captionEntitiesField) - private val rawEntities: List? = null, - override val width: Int? = null, - override val height: Int? = null, - override val duration: Long? = null, - override val thumb: InputFile? = null -) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, VisualMediaGroupMemberInputMedia { - override val type: String = videoInputMediaType - override val textSources: TextSourcesList? by lazy { - rawEntities ?.asTextSources(text ?: return@lazy null) - } - - override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) - - @SerialName(mediaField) - override val media: String - init { media = file.fileIdToSend } // crutch until js compiling will be fixed -} +) = TelegramMediaVideo(file, entities.makeString(), null, entities.toRawMessageEntities(), width, height, duration, thumb) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMedia.kt deleted file mode 100644 index 21b30e4e02..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMedia.kt +++ /dev/null @@ -1,26 +0,0 @@ -package dev.inmo.tgbotapi.types.InputMedia - -import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput -import kotlinx.serialization.* -import kotlinx.serialization.json.Json - -internal val argumentsFormatter by lazy { - Json { - encodeDefaults = true - } -} -internal fun T.buildArguments(withSerializer: SerializationStrategy) = argumentsFormatter.encodeToJsonElement( - withSerializer, - this -) - -@Serializable(MediaGroupMemberInputMediaSerializer::class) -sealed interface MediaGroupMemberInputMedia : InputMedia, TextedOutput { - fun serialize(format: StringFormat): String -} - -sealed interface AudioMediaGroupMemberInputMedia: MediaGroupMemberInputMedia -sealed interface DocumentMediaGroupMemberInputMedia: MediaGroupMemberInputMedia - -@Serializable(MediaGroupMemberInputMediaSerializer::class) -sealed interface VisualMediaGroupMemberInputMedia : MediaGroupMemberInputMedia diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMediaSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMediaSerializer.kt deleted file mode 100644 index 9c1f4bca79..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMediaSerializer.kt +++ /dev/null @@ -1,37 +0,0 @@ -package dev.inmo.tgbotapi.types.InputMedia - -import dev.inmo.tgbotapi.types.typeField -import dev.inmo.tgbotapi.utils.RiskFeature -import dev.inmo.tgbotapi.utils.nonstrictJsonFormat -import kotlinx.serialization.InternalSerializationApi -import kotlinx.serialization.KSerializer -import kotlinx.serialization.descriptors.* -import kotlinx.serialization.encoding.Decoder -import kotlinx.serialization.encoding.Encoder -import kotlinx.serialization.json.* - -@RiskFeature -object MediaGroupMemberInputMediaSerializer : KSerializer { - @OptIn(InternalSerializationApi::class) - override val descriptor: SerialDescriptor = buildSerialDescriptor(MediaGroupMemberInputMedia::class.toString(), PolymorphicKind.OPEN) - override fun serialize(encoder: Encoder, value: MediaGroupMemberInputMedia) { - when (value) { - is InputMediaPhoto -> InputMediaPhoto.serializer().serialize(encoder, value) - is InputMediaVideo -> InputMediaVideo.serializer().serialize(encoder, value) - is InputMediaAudio -> InputMediaAudio.serializer().serialize(encoder, value) - is InputMediaDocument -> InputMediaDocument.serializer().serialize(encoder, value) - } - } - - override fun deserialize(decoder: Decoder): MediaGroupMemberInputMedia { - val json = JsonObject.serializer().deserialize(decoder) - - return when (json[typeField] ?.jsonPrimitive ?.contentOrNull) { - photoInputMediaType -> nonstrictJsonFormat.decodeFromJsonElement(InputMediaPhoto.serializer(), json) - videoInputMediaType -> nonstrictJsonFormat.decodeFromJsonElement(InputMediaVideo.serializer(), json) - audioInputMediaType -> nonstrictJsonFormat.decodeFromJsonElement(InputMediaAudio.serializer(), json) - documentInputMediaType -> nonstrictJsonFormat.decodeFromJsonElement(InputMediaDocument.serializer(), json) - else -> error("Illegal type of incoming MediaGroupMemberInputMedia") - } - } -} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/SizedInputMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/SizedInputMedia.kt deleted file mode 100644 index 2af7a352d4..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/SizedInputMedia.kt +++ /dev/null @@ -1,6 +0,0 @@ -package dev.inmo.tgbotapi.types.InputMedia - -sealed interface SizedInputMedia : InputMedia { - val width: Int? - val height: Int? -} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/ThumbedInputMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/ThumbedInputMedia.kt deleted file mode 100644 index a377adb1cf..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/ThumbedInputMedia.kt +++ /dev/null @@ -1,7 +0,0 @@ -package dev.inmo.tgbotapi.types.InputMedia - -import dev.inmo.tgbotapi.requests.abstracts.InputFile - -sealed interface ThumbedInputMedia : InputMedia { - val thumb: InputFile? -} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/TitledInputMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/TitledInputMedia.kt deleted file mode 100644 index 95a4b9ccc8..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/TitledInputMedia.kt +++ /dev/null @@ -1,5 +0,0 @@ -package dev.inmo.tgbotapi.types.InputMedia - -sealed interface TitledInputMedia : InputMedia { - val title: String? -} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/Typealiases.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/Typealiases.kt new file mode 100644 index 0000000000..dee16d09fa --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/Typealiases.kt @@ -0,0 +1,34 @@ +package dev.inmo.tgbotapi.types.InputMedia + +@Deprecated("Replaced and renamed", ReplaceWith("DuratedInputMedia", "dev.inmo.tgbotapi.types.media.DuratedInputMedia")) +typealias DuratedInputMedia = dev.inmo.tgbotapi.types.media.DuratedTelegramMedia +@Deprecated("Replaced and renamed", ReplaceWith("InputMedia", "dev.inmo.tgbotapi.types.media.InputMedia")) +typealias InputMedia = dev.inmo.tgbotapi.types.media.TelegramMedia +@Deprecated("Replaced and renamed", ReplaceWith("InputMediaAnimation", "dev.inmo.tgbotapi.types.media.InputMediaAnimation")) +typealias InputMediaAnimation = dev.inmo.tgbotapi.types.media.TelegramMediaAnimation +@Deprecated("Replaced and renamed", ReplaceWith("InputMediaAudio", "dev.inmo.tgbotapi.types.media.InputMediaAudio")) +typealias InputMediaAudio = dev.inmo.tgbotapi.types.media.TelegramMediaAudio +@Deprecated("Replaced and renamed", ReplaceWith("InputMediaDocument", "dev.inmo.tgbotapi.types.media.InputMediaDocument")) +typealias InputMediaDocument = dev.inmo.tgbotapi.types.media.TelegramMediaDocument +@Deprecated("Replaced and renamed", ReplaceWith("InputMediaPhoto", "dev.inmo.tgbotapi.types.media.InputMediaPhoto")) +typealias InputMediaPhoto = dev.inmo.tgbotapi.types.media.TelegramMediaPhoto +@Deprecated("Replaced and renamed", ReplaceWith("InputMediaSerializer", "dev.inmo.tgbotapi.types.media.InputMediaSerializer")) +typealias InputMediaSerializer = dev.inmo.tgbotapi.types.media.TelegramMediaSerializer +@Deprecated("Replaced and renamed", ReplaceWith("InputMediaVideo", "dev.inmo.tgbotapi.types.media.InputMediaVideo")) +typealias InputMediaVideo = dev.inmo.tgbotapi.types.media.TelegramMediaVideo +@Deprecated("Replaced and renamed", ReplaceWith("MediaGroupMemberInputMedia", "dev.inmo.tgbotapi.types.media.MediaGroupMemberInputMedia")) +typealias MediaGroupMemberInputMedia = dev.inmo.tgbotapi.types.media.MediaGroupMemberTelegramMedia +@Deprecated("Replaced and renamed", ReplaceWith("AudioMediaGroupMemberInputMedia", "dev.inmo.tgbotapi.types.media.AudioMediaGroupMemberInputMedia")) +typealias AudioMediaGroupMemberInputMedia = dev.inmo.tgbotapi.types.media.AudioMediaGroupMemberTelegramMedia +@Deprecated("Replaced and renamed", ReplaceWith("DocumentMediaGroupMemberInputMedia", "dev.inmo.tgbotapi.types.media.DocumentMediaGroupMemberInputMedia")) +typealias DocumentMediaGroupMemberInputMedia = dev.inmo.tgbotapi.types.media.DocumentMediaGroupMemberTelegramMedia +@Deprecated("Replaced and renamed", ReplaceWith("VisualMediaGroupMemberInputMedia", "dev.inmo.tgbotapi.types.media.VisualMediaGroupMemberInputMedia")) +typealias VisualMediaGroupMemberInputMedia = dev.inmo.tgbotapi.types.media.VisualMediaGroupMemberTelegramMedia +@Deprecated("Replaced and renamed", ReplaceWith("MediaGroupMemberInputMediaSerializer", "dev.inmo.tgbotapi.types.media.MediaGroupMemberInputMediaSerializer")) +typealias MediaGroupMemberInputMediaSerializer = dev.inmo.tgbotapi.types.media.MediaGroupMemberTelegramMediaSerializer +@Deprecated("Replaced and renamed", ReplaceWith("ThumbedInputMedia", "dev.inmo.tgbotapi.types.media.ThumbedInputMedia")) +typealias ThumbedInputMedia = dev.inmo.tgbotapi.types.media.ThumbedTelegramMedia +@Deprecated("Replaced and renamed", ReplaceWith("SizedInputMedia", "dev.inmo.tgbotapi.types.media.SizedInputMedia")) +typealias SizedInputMedia = dev.inmo.tgbotapi.types.media.SizedTelegramMedia +@Deprecated("Replaced and renamed", ReplaceWith("TitledInputMedia", "dev.inmo.tgbotapi.types.media.TitledInputMedia")) +typealias TitledInputMedia = dev.inmo.tgbotapi.types.media.TitledTelegramMedia diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt index eb654d1851..a18fbdc490 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt @@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.files import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.InputMedia.InputMediaVideo +import dev.inmo.tgbotapi.types.media.TelegramMediaVideo import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.utils.MimeType @@ -32,10 +32,10 @@ data class VideoFile( ) : TelegramMediaFile, CustomNamedMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile @Suppress("NOTHING_TO_INLINE") -inline fun VideoFile.toInputMediaVideo( +inline fun VideoFile.toTelegramMediaVideo( text: String? = null, parseMode: ParseMode? = null -) = InputMediaVideo( +) = TelegramMediaVideo( fileId, text, parseMode, @@ -46,9 +46,9 @@ inline fun VideoFile.toInputMediaVideo( ) @Suppress("NOTHING_TO_INLINE") -inline fun VideoFile.toInputMediaVideo( +inline fun VideoFile.toTelegramMediaVideo( textSources: TextSourcesList -) = InputMediaVideo( +) = TelegramMediaVideo( fileId, textSources, width, @@ -56,3 +56,16 @@ inline fun VideoFile.toInputMediaVideo( duration, thumb ?.fileId ) + +@Suppress("NOTHING_TO_INLINE") +@Deprecated("Renamed", ReplaceWith("toTelegramMediaVideo", "dev.inmo.tgbotapi.types.files.toTelegramMediaVideo")) +inline fun VideoFile.toInputMediaVideo( + text: String? = null, + parseMode: ParseMode? = null +) = toTelegramMediaVideo(text, parseMode) + +@Suppress("NOTHING_TO_INLINE") +@Deprecated("Renamed", ReplaceWith("toTelegramMediaVideo", "dev.inmo.tgbotapi.types.files.toTelegramMediaVideo")) +inline fun VideoFile.toInputMediaVideo( + textSources: TextSourcesList +) = toTelegramMediaVideo(textSources) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/DuratedTelegramMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/DuratedTelegramMedia.kt new file mode 100644 index 0000000000..5cfcc2b1ba --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/DuratedTelegramMedia.kt @@ -0,0 +1,5 @@ +package dev.inmo.tgbotapi.types.media + +sealed interface DuratedTelegramMedia : TelegramMedia { + val duration: Long? +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/MediaGroupMemberTelegramMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/MediaGroupMemberTelegramMedia.kt new file mode 100644 index 0000000000..b0cef046ca --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/MediaGroupMemberTelegramMedia.kt @@ -0,0 +1,23 @@ +package dev.inmo.tgbotapi.types.media + +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput +import kotlinx.serialization.Serializable +import kotlinx.serialization.StringFormat +import kotlinx.serialization.json.Json + +internal val argumentsFormatter by lazy { + Json { + encodeDefaults = true + } +} + +@Serializable(MediaGroupMemberTelegramMediaSerializer::class) +sealed interface MediaGroupMemberTelegramMedia : TelegramMedia, TextedOutput { + fun serialize(format: StringFormat): String +} + +sealed interface AudioMediaGroupMemberTelegramMedia: MediaGroupMemberTelegramMedia +sealed interface DocumentMediaGroupMemberTelegramMedia: MediaGroupMemberTelegramMedia + +@Serializable(MediaGroupMemberTelegramMediaSerializer::class) +sealed interface VisualMediaGroupMemberTelegramMedia : MediaGroupMemberTelegramMedia diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/MediaGroupMemberTelegramMediaSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/MediaGroupMemberTelegramMediaSerializer.kt new file mode 100644 index 0000000000..19c9124d52 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/MediaGroupMemberTelegramMediaSerializer.kt @@ -0,0 +1,37 @@ +package dev.inmo.tgbotapi.types.media + +import dev.inmo.tgbotapi.types.typeField +import dev.inmo.tgbotapi.utils.RiskFeature +import dev.inmo.tgbotapi.utils.nonstrictJsonFormat +import kotlinx.serialization.InternalSerializationApi +import kotlinx.serialization.KSerializer +import kotlinx.serialization.descriptors.* +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.* + +@RiskFeature +object MediaGroupMemberTelegramMediaSerializer : KSerializer { + @OptIn(InternalSerializationApi::class) + override val descriptor: SerialDescriptor = buildSerialDescriptor(MediaGroupMemberTelegramMedia::class.toString(), PolymorphicKind.OPEN) + override fun serialize(encoder: Encoder, value: MediaGroupMemberTelegramMedia) { + when (value) { + is TelegramMediaPhoto -> TelegramMediaPhoto.serializer().serialize(encoder, value) + is TelegramMediaVideo -> TelegramMediaVideo.serializer().serialize(encoder, value) + is TelegramMediaAudio -> TelegramMediaAudio.serializer().serialize(encoder, value) + is TelegramMediaDocument -> TelegramMediaDocument.serializer().serialize(encoder, value) + } + } + + override fun deserialize(decoder: Decoder): MediaGroupMemberTelegramMedia { + val json = JsonObject.serializer().deserialize(decoder) + + return when (json[typeField] ?.jsonPrimitive ?.contentOrNull) { + photoTelegramMediaType -> nonstrictJsonFormat.decodeFromJsonElement(TelegramMediaPhoto.serializer(), json) + videoTelegramMediaType -> nonstrictJsonFormat.decodeFromJsonElement(TelegramMediaVideo.serializer(), json) + audioTelegramMediaType -> nonstrictJsonFormat.decodeFromJsonElement(TelegramMediaAudio.serializer(), json) + documentTelegramMediaType -> nonstrictJsonFormat.decodeFromJsonElement(TelegramMediaDocument.serializer(), json) + else -> error("Illegal type of incoming MediaGroupMemberTelegramMedia") + } + } +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/SizedTelegramMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/SizedTelegramMedia.kt new file mode 100644 index 0000000000..f079212f23 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/SizedTelegramMedia.kt @@ -0,0 +1,6 @@ +package dev.inmo.tgbotapi.types.media + +sealed interface SizedTelegramMedia : TelegramMedia { + val width: Int? + val height: Int? +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMedia.kt similarity index 58% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMedia.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMedia.kt index 5013f33f9c..2ae7932ede 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMedia.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMedia.kt @@ -1,10 +1,10 @@ -package dev.inmo.tgbotapi.types.InputMedia +package dev.inmo.tgbotapi.types.media import dev.inmo.tgbotapi.requests.abstracts.InputFile import kotlinx.serialization.Serializable -@Serializable(InputMediaSerializer::class) -sealed interface InputMedia { +@Serializable(TelegramMediaSerializer::class) +sealed interface TelegramMedia { val type: String val file: InputFile val media: String diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaAnimation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaAnimation.kt new file mode 100644 index 0000000000..f240e28c92 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaAnimation.kt @@ -0,0 +1,65 @@ +package dev.inmo.tgbotapi.types.media + +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput +import dev.inmo.tgbotapi.requests.abstracts.InputFile +import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList +import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.types.ParseMode.parseModeField +import dev.inmo.tgbotapi.utils.extensions.makeString +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +fun TelegramMediaAnimation( + file: InputFile, + text: String? = null, + parseMode: ParseMode? = null, + width: Int? = null, + height: Int? = null, + duration: Long? = null, + thumb: InputFile? = null +) = TelegramMediaAnimation(file, text, parseMode, null, width, height, duration, thumb) + +fun TelegramMediaAnimation( + file: InputFile, + entities: TextSourcesList, + width: Int? = null, + height: Int? = null, + duration: Long? = null, + thumb: InputFile? = null +) = TelegramMediaAnimation( + file, + entities.makeString(), + null, + entities.toRawMessageEntities(), + width, + height, + duration, + thumb +) + +@Serializable +data class TelegramMediaAnimation internal constructor( + override val file: InputFile, + @SerialName(captionField) + override val text: String? = null, + @SerialName(parseModeField) + override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, + override val width: Int? = null, + override val height: Int? = null, + override val duration: Long? = null, + override val thumb: InputFile? = null +) : TelegramMedia, SizedTelegramMedia, DuratedTelegramMedia, ThumbedTelegramMedia, TextedOutput { + override val type: String = "animation" + override val textSources: TextSourcesList? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) + } + + @SerialName(mediaField) + override val media: String + init { media = file.fileIdToSend } // crutch until js compiling will be fixed +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaAudio.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaAudio.kt new file mode 100644 index 0000000000..6c56088e31 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaAudio.kt @@ -0,0 +1,90 @@ +package dev.inmo.tgbotapi.types.media + +import dev.inmo.tgbotapi.CommonAbstracts.Performerable +import dev.inmo.tgbotapi.requests.abstracts.InputFile +import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList +import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.types.ParseMode.parseModeField +import dev.inmo.tgbotapi.types.files.AudioFile +import dev.inmo.tgbotapi.utils.extensions.makeString +import kotlinx.serialization.* + +internal const val audioTelegramMediaType = "audio" + +fun TelegramMediaAudio( + file: InputFile, + entities: TextSourcesList, + duration: Long? = null, + performer: String? = null, + title: String? = null, + thumb: InputFile? = null +) = TelegramMediaAudio( + file, entities.makeString(), null, entities.toRawMessageEntities(), duration, performer, title, thumb +) + +fun TelegramMediaAudio( + file: InputFile, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + performer: String? = null, + title: String? = null, + thumb: InputFile? = null +) = TelegramMediaAudio( + file, text, parseMode, null, duration, performer, title, thumb +) + +@Serializable +data class TelegramMediaAudio internal constructor( + override val file: InputFile, + @SerialName(captionField) + override val text: String? = null, + @SerialName(parseModeField) + override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, + override val duration: Long? = null, + override val performer: String? = null, + override val title: String? = null, + override val thumb: InputFile? = null +) : TelegramMedia, AudioMediaGroupMemberTelegramMedia, DuratedTelegramMedia, ThumbedTelegramMedia, TitledTelegramMedia, Performerable { + override val type: String = audioTelegramMediaType + override val textSources: TextSourcesList? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) + } + + override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) + + @SerialName(mediaField) + override val media: String + init { media = file.fileIdToSend } // crutch until js compiling will be fixed +} + +fun AudioFile.toTelegramMediaAudio( + text: String? = null, + parseMode: ParseMode? = null, + title: String? = this.title +): TelegramMediaAudio = TelegramMediaAudio( + fileId, + text, + parseMode, + duration, + performer, + title, + thumb ?.fileId +) + +fun AudioFile.toTelegramMediaAudio( + textSources: TextSourcesList = emptyList(), + title: String? = this.title +): TelegramMediaAudio = TelegramMediaAudio( + fileId, + textSources, + duration, + performer, + title, + thumb ?.fileId +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaDocument.kt new file mode 100644 index 0000000000..193513a9a4 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaDocument.kt @@ -0,0 +1,88 @@ +package dev.inmo.tgbotapi.types.media + +import dev.inmo.tgbotapi.requests.abstracts.* +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList +import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.types.ParseMode.parseModeField +import dev.inmo.tgbotapi.types.files.DocumentFile +import dev.inmo.tgbotapi.utils.extensions.makeString +import kotlinx.serialization.* + +internal const val documentTelegramMediaType = "document" + +fun TelegramMediaDocument( + file: InputFile, + text: String? = null, + parseMode: ParseMode? = null, + thumb: InputFile? = null, + disableContentTypeDetection: Boolean? = null +) = TelegramMediaDocument(file, text, parseMode, null, thumb, disableContentTypeDetection) + +fun TelegramMediaDocument( + file: InputFile, + entities: TextSourcesList, + thumb: InputFile? = null, + disableContentTypeDetection: Boolean? = null +) = TelegramMediaDocument( + file, + entities.makeString(), + null, + entities.toRawMessageEntities(), + thumb, + disableContentTypeDetection +) + +/** + * Represents a general file to be sent. See https://core.telegram.org/bots/api#inputmediadocument + * + * @param disableContentTypeDetection Disables automatic server-side content type detection for files uploaded using + * multipart/form-data. Always used by Telegram system as true, if the document is sent as part of an album. + * + * @see InputFile + * @see MultipartFile + * @see FileId + */ +@Serializable +data class TelegramMediaDocument internal constructor( + override val file: InputFile, + @SerialName(captionField) + override val text: String? = null, + @SerialName(parseModeField) + override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, + override val thumb: InputFile? = null, + @SerialName(disableContentTypeDetectionField) + val disableContentTypeDetection: Boolean? = null +) : TelegramMedia, DocumentMediaGroupMemberTelegramMedia, ThumbedTelegramMedia { + override val type: String = documentTelegramMediaType + override val textSources: TextSourcesList? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) + } + + override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) + + @SerialName(mediaField) + override val media: String + init { media = file.fileIdToSend } // crutch until js compiling will be fixed +} + +fun DocumentFile.toTelegramMediaDocument( + text: String? = null, + parseMode: ParseMode? = null +) = TelegramMediaDocument( + fileId, + text, + parseMode, + thumb ?.fileId +) + +fun DocumentFile.toTelegramMediaDocument( + textSources: TextSourcesList = emptyList() +) = TelegramMediaDocument( + fileId, + textSources, + thumb ?.fileId +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaPhoto.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaPhoto.kt new file mode 100644 index 0000000000..0896b748e2 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaPhoto.kt @@ -0,0 +1,63 @@ +package dev.inmo.tgbotapi.types.media + +import dev.inmo.tgbotapi.requests.abstracts.InputFile +import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList +import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.types.ParseMode.parseModeField +import dev.inmo.tgbotapi.types.files.PhotoSize +import dev.inmo.tgbotapi.utils.extensions.makeString +import kotlinx.serialization.* + +internal const val photoTelegramMediaType = "photo" + +fun TelegramMediaPhoto( + file: InputFile, + text: String? = null, + parseMode: ParseMode? = null +) = TelegramMediaPhoto(file, text, parseMode, null) + +fun TelegramMediaPhoto( + file: InputFile, + entities: TextSourcesList +) = TelegramMediaPhoto(file, entities.makeString(), null, entities.toRawMessageEntities()) + +@Serializable +data class TelegramMediaPhoto internal constructor( + override val file: InputFile, + @SerialName(captionField) + override val text: String? = null, + @SerialName(parseModeField) + override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null +) : TelegramMedia, VisualMediaGroupMemberTelegramMedia { + override val type: String = photoTelegramMediaType + override val textSources: TextSourcesList? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) + } + + override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) + + @SerialName(mediaField) + override val media: String + init { media = file.fileIdToSend } // crutch until js compiling will be fixed +} + +fun PhotoSize.toTelegramMediaPhoto( + text: String? = null, + parseMode: ParseMode? = null +): TelegramMediaPhoto = TelegramMediaPhoto( + fileId, + text, + parseMode +) + +fun PhotoSize.toTelegramMediaPhoto( + textSources: TextSourcesList = emptyList() +): TelegramMediaPhoto = TelegramMediaPhoto( + fileId, + textSources +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaSerializer.kt new file mode 100644 index 0000000000..989f5bbb9a --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaSerializer.kt @@ -0,0 +1,27 @@ +package dev.inmo.tgbotapi.types.media + +import dev.inmo.tgbotapi.utils.RiskFeature +import kotlinx.serialization.InternalSerializationApi +import kotlinx.serialization.KSerializer +import kotlinx.serialization.descriptors.* +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@RiskFeature +object TelegramMediaSerializer : KSerializer { + @OptIn(InternalSerializationApi::class) + override val descriptor: SerialDescriptor = buildSerialDescriptor(TelegramMedia::class.toString(), PolymorphicKind.OPEN) + override fun serialize(encoder: Encoder, value: TelegramMedia) { + when (value) { + is TelegramMediaVideo -> TelegramMediaVideo.serializer().serialize(encoder, value) + is TelegramMediaAudio -> TelegramMediaAudio.serializer().serialize(encoder, value) + is TelegramMediaPhoto -> TelegramMediaPhoto.serializer().serialize(encoder, value) + is TelegramMediaAnimation -> TelegramMediaAnimation.serializer().serialize(encoder, value) + is TelegramMediaDocument -> TelegramMediaDocument.serializer().serialize(encoder, value) + } + } + + override fun deserialize(decoder: Decoder): TelegramMedia { + throw IllegalStateException("Object can't be deserialized") + } +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaVideo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaVideo.kt new file mode 100644 index 0000000000..8164864572 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaVideo.kt @@ -0,0 +1,58 @@ +package dev.inmo.tgbotapi.types.media + +import dev.inmo.tgbotapi.requests.abstracts.InputFile +import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList +import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.types.ParseMode.parseModeField +import dev.inmo.tgbotapi.utils.extensions.makeString +import kotlinx.serialization.* + +internal const val videoTelegramMediaType = "video" + +fun TelegramMediaVideo( + file: InputFile, + text: String? = null, + parseMode: ParseMode? = null, + width: Int? = null, + height: Int? = null, + duration: Long? = null, + thumb: InputFile? = null +) = TelegramMediaVideo(file, text, parseMode, null, width, height, duration, thumb) + +fun TelegramMediaVideo( + file: InputFile, + entities: TextSourcesList, + width: Int? = null, + height: Int? = null, + duration: Long? = null, + thumb: InputFile? = null +) = TelegramMediaVideo(file, entities.makeString(), null, entities.toRawMessageEntities(), width, height, duration, thumb) + +@Serializable +data class TelegramMediaVideo internal constructor ( + override val file: InputFile, + @SerialName(captionField) + override val text: String? = null, + @SerialName(parseModeField) + override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, + override val width: Int? = null, + override val height: Int? = null, + override val duration: Long? = null, + override val thumb: InputFile? = null +) : TelegramMedia, SizedTelegramMedia, DuratedTelegramMedia, ThumbedTelegramMedia, VisualMediaGroupMemberTelegramMedia { + override val type: String = videoTelegramMediaType + override val textSources: TextSourcesList? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) + } + + override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) + + @SerialName(mediaField) + override val media: String + init { media = file.fileIdToSend } // crutch until js compiling will be fixed +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/ThumbedTelegramMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/ThumbedTelegramMedia.kt new file mode 100644 index 0000000000..eac1120206 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/ThumbedTelegramMedia.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.types.media + +import dev.inmo.tgbotapi.requests.abstracts.InputFile + +sealed interface ThumbedTelegramMedia : TelegramMedia { + val thumb: InputFile? +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TitledTelegramMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TitledTelegramMedia.kt new file mode 100644 index 0000000000..94fb737daf --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TitledTelegramMedia.kt @@ -0,0 +1,5 @@ +package dev.inmo.tgbotapi.types.media + +sealed interface TitledTelegramMedia : TelegramMedia { + val title: String? +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/MediaContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/MediaContent.kt index 219893ebcb..57d293be1c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/MediaContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/MediaContent.kt @@ -1,9 +1,11 @@ package dev.inmo.tgbotapi.types.message.content.abstracts -import dev.inmo.tgbotapi.types.InputMedia.InputMedia +import dev.inmo.tgbotapi.types.media.TelegramMedia import dev.inmo.tgbotapi.types.files.TelegramMediaFile interface MediaContent: MessageContent { val media: TelegramMediaFile - fun asInputMedia(): InputMedia + fun asTelegramMedia(): TelegramMedia + @Deprecated("Renamed", ReplaceWith("asTelegramMedia()")) + fun asInputMedia(): TelegramMedia = asTelegramMedia() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt index 1812450b8e..28ead67598 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt @@ -1,17 +1,15 @@ package dev.inmo.tgbotapi.types.message.content.media -import dev.inmo.tgbotapi.CommonAbstracts.TextedInput import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendAnimation import dev.inmo.tgbotapi.types.ChatIdentifier -import dev.inmo.tgbotapi.types.InputMedia.InputMediaAnimation +import dev.inmo.tgbotapi.types.media.TelegramMediaAnimation import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.AnimationFile import dev.inmo.tgbotapi.types.files.DocumentFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage -import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent import kotlinx.serialization.Serializable @Serializable @@ -43,7 +41,7 @@ data class AnimationContent( replyMarkup ) - override fun asInputMedia(): InputMediaAnimation = InputMediaAnimation( + override fun asTelegramMedia(): TelegramMediaAnimation = TelegramMediaAnimation( media.fileId, textSources, media.width, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt index 67c3c138e7..1461bdc1a9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt @@ -3,8 +3,8 @@ package dev.inmo.tgbotapi.types.message.content.media import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendAudio import dev.inmo.tgbotapi.types.ChatIdentifier -import dev.inmo.tgbotapi.types.InputMedia.InputMediaAudio -import dev.inmo.tgbotapi.types.InputMedia.toInputMediaAudio +import dev.inmo.tgbotapi.types.media.TelegramMediaAudio +import dev.inmo.tgbotapi.types.media.toTelegramMediaAudio import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup @@ -40,7 +40,7 @@ data class AudioContent( replyMarkup ) - override fun toMediaGroupMemberInputMedia(): InputMediaAudio = asInputMedia() + override fun toMediaGroupMemberTelegramMedia(): TelegramMediaAudio = asTelegramMedia() - override fun asInputMedia(): InputMediaAudio = media.toInputMediaAudio(textSources) + override fun asTelegramMedia(): TelegramMediaAudio = media.toTelegramMediaAudio(textSources) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioMediaGroupContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioMediaGroupContent.kt index adc46e7b42..aa35d19316 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioMediaGroupContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioMediaGroupContent.kt @@ -1,10 +1,10 @@ package dev.inmo.tgbotapi.types.message.content.media -import dev.inmo.tgbotapi.types.InputMedia.AudioMediaGroupMemberInputMedia +import dev.inmo.tgbotapi.types.media.AudioMediaGroupMemberTelegramMedia import dev.inmo.tgbotapi.types.files.AudioFile interface AudioMediaGroupContent : MediaGroupContent { override val media: AudioFile - override fun toMediaGroupMemberInputMedia(): AudioMediaGroupMemberInputMedia + override fun toMediaGroupMemberTelegramMedia(): AudioMediaGroupMemberTelegramMedia } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt index 865d8b814f..a5baf6e5c5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt @@ -4,8 +4,8 @@ import dev.inmo.tgbotapi.CommonAbstracts.TextedInput import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendDocument import dev.inmo.tgbotapi.types.ChatIdentifier -import dev.inmo.tgbotapi.types.InputMedia.InputMediaDocument -import dev.inmo.tgbotapi.types.InputMedia.toInputMediaDocument +import dev.inmo.tgbotapi.types.media.TelegramMediaDocument +import dev.inmo.tgbotapi.types.media.toTelegramMediaDocument import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup @@ -40,9 +40,9 @@ data class DocumentContent( replyMarkup ) - override fun toMediaGroupMemberInputMedia(): InputMediaDocument = asInputMedia() + override fun toMediaGroupMemberTelegramMedia(): TelegramMediaDocument = asTelegramMedia() - override fun asInputMedia(): InputMediaDocument = media.toInputMediaDocument(textSources) + override fun asTelegramMedia(): TelegramMediaDocument = media.toTelegramMediaDocument(textSources) } @Suppress("NOTHING_TO_INLINE") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentMediaGroupContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentMediaGroupContent.kt index 8319c3dc16..b37060f095 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentMediaGroupContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentMediaGroupContent.kt @@ -1,10 +1,10 @@ package dev.inmo.tgbotapi.types.message.content.media -import dev.inmo.tgbotapi.types.InputMedia.* +import dev.inmo.tgbotapi.types.media.* import dev.inmo.tgbotapi.types.files.DocumentFile interface DocumentMediaGroupContent : MediaGroupContent { override val media: DocumentFile - override fun toMediaGroupMemberInputMedia(): DocumentMediaGroupMemberInputMedia + override fun toMediaGroupMemberTelegramMedia(): DocumentMediaGroupMemberTelegramMedia } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/MediaGroupContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/MediaGroupContent.kt index 0052cfe362..ccc1d68efc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/MediaGroupContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/MediaGroupContent.kt @@ -1,7 +1,9 @@ package dev.inmo.tgbotapi.types.message.content.media -import dev.inmo.tgbotapi.types.InputMedia.MediaGroupMemberInputMedia +import dev.inmo.tgbotapi.types.media.MediaGroupMemberTelegramMedia interface MediaGroupContent : TextedMediaContent { - fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia + fun toMediaGroupMemberTelegramMedia(): MediaGroupMemberTelegramMedia + @Deprecated("Renamed", ReplaceWith("toMediaGroupMemberTelegramMedia()")) + fun toMediaGroupMemberInputMedia(): MediaGroupMemberTelegramMedia = toMediaGroupMemberTelegramMedia() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt index c56826a5e1..d405e96b7e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt @@ -3,8 +3,8 @@ package dev.inmo.tgbotapi.types.message.content.media import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendPhoto import dev.inmo.tgbotapi.types.ChatIdentifier -import dev.inmo.tgbotapi.types.InputMedia.InputMediaPhoto -import dev.inmo.tgbotapi.types.InputMedia.toInputMediaPhoto +import dev.inmo.tgbotapi.types.media.TelegramMediaPhoto +import dev.inmo.tgbotapi.types.media.toTelegramMediaPhoto import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup @@ -39,7 +39,7 @@ data class PhotoContent( replyMarkup ) - override fun toMediaGroupMemberInputMedia(): InputMediaPhoto = asInputMedia() + override fun toMediaGroupMemberTelegramMedia(): TelegramMediaPhoto = asTelegramMedia() - override fun asInputMedia(): InputMediaPhoto = media.toInputMediaPhoto(textSources) + override fun asTelegramMedia(): TelegramMediaPhoto = media.toTelegramMediaPhoto(textSources) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt index 16a81b62ad..0d47b8616b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.types.message.content.media import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendSticker import dev.inmo.tgbotapi.types.ChatIdentifier -import dev.inmo.tgbotapi.types.InputMedia.InputMediaDocument +import dev.inmo.tgbotapi.types.media.TelegramMediaDocument import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.Sticker @@ -32,7 +32,7 @@ data class StickerContent( replyMarkup ) - override fun asInputMedia(): InputMediaDocument = InputMediaDocument( + override fun asTelegramMedia(): TelegramMediaDocument = TelegramMediaDocument( media.fileId, null, thumb = media.thumb ?.fileId diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt index 1de12b940e..b2abd7deb3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt @@ -3,12 +3,12 @@ package dev.inmo.tgbotapi.types.message.content.media import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendVideo import dev.inmo.tgbotapi.types.ChatIdentifier -import dev.inmo.tgbotapi.types.InputMedia.InputMediaVideo +import dev.inmo.tgbotapi.types.media.TelegramMediaVideo import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.VideoFile -import dev.inmo.tgbotapi.types.files.toInputMediaVideo +import dev.inmo.tgbotapi.types.files.toTelegramMediaVideo import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import kotlinx.serialization.Serializable @@ -41,7 +41,7 @@ data class VideoContent( replyMarkup ) - override fun toMediaGroupMemberInputMedia(): InputMediaVideo = asInputMedia() + override fun toMediaGroupMemberTelegramMedia(): TelegramMediaVideo = asTelegramMedia() - override fun asInputMedia(): InputMediaVideo = media.toInputMediaVideo(textSources) + override fun asTelegramMedia(): TelegramMediaVideo = media.toTelegramMediaVideo(textSources) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt index 8cd74d80b8..2fecfe91d6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.types.message.content.media import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendVideoNote import dev.inmo.tgbotapi.types.ChatIdentifier -import dev.inmo.tgbotapi.types.InputMedia.InputMediaVideo +import dev.inmo.tgbotapi.types.media.TelegramMediaVideo import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.VideoNoteFile @@ -35,7 +35,7 @@ data class VideoNoteContent( replyMarkup ) - override fun asInputMedia(): InputMediaVideo = InputMediaVideo( + override fun asTelegramMedia(): TelegramMediaVideo = TelegramMediaVideo( media.fileId, width = media.width, height = media.height, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VisualMediaGroupContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VisualMediaGroupContent.kt index 5402b716a2..d1a34bdfb5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VisualMediaGroupContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VisualMediaGroupContent.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.types.message.content.media -import dev.inmo.tgbotapi.types.InputMedia.VisualMediaGroupMemberInputMedia +import dev.inmo.tgbotapi.types.media.VisualMediaGroupMemberTelegramMedia interface VisualMediaGroupContent : MediaGroupContent { - override fun toMediaGroupMemberInputMedia(): VisualMediaGroupMemberInputMedia + override fun toMediaGroupMemberTelegramMedia(): VisualMediaGroupMemberTelegramMedia } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt index 9f069902c8..d61b816f34 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt @@ -1,16 +1,14 @@ package dev.inmo.tgbotapi.types.message.content.media -import dev.inmo.tgbotapi.CommonAbstracts.TextedInput import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendVoice import dev.inmo.tgbotapi.types.ChatIdentifier -import dev.inmo.tgbotapi.types.InputMedia.InputMediaAudio +import dev.inmo.tgbotapi.types.media.TelegramMediaAudio import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.VoiceFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage -import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent import kotlinx.serialization.Serializable @Serializable @@ -38,7 +36,7 @@ data class VoiceContent( replyMarkup ) - override fun asInputMedia(): InputMediaAudio = InputMediaAudio( + override fun asTelegramMedia(): TelegramMediaAudio = TelegramMediaAudio( media.fileId, textSources, media.duration diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/SimpleInputFilesTest.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/SimpleInputFilesTest.kt index e86186f9e4..fa27b4ebd3 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/SimpleInputFilesTest.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/SimpleInputFilesTest.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi import dev.inmo.tgbotapi.requests.abstracts.toInputFile -import dev.inmo.tgbotapi.types.InputMedia.MediaGroupMemberInputMediaSerializer +import dev.inmo.tgbotapi.types.media.MediaGroupMemberTelegramMediaSerializer import dev.inmo.tgbotapi.types.files.PhotoSize import dev.inmo.tgbotapi.types.message.content.media.PhotoContent import kotlinx.serialization.json.Json @@ -24,16 +24,16 @@ class SimpleInputFilesTest { PhotoSize("example_file_id".toInputFile(), "example_unique_file_id", 100, 100, 100) ) ) - val inputMedia = photoContent.toMediaGroupMemberInputMedia() + val inputMedia = photoContent.toMediaGroupMemberTelegramMedia() assertEquals(photoContent.media.fileId, inputMedia.file) val encoded = nonstrictJsonFormat.encodeToString( - MediaGroupMemberInputMediaSerializer, + MediaGroupMemberTelegramMediaSerializer, inputMedia ) assertEquals( inputMedia, nonstrictJsonFormat.decodeFromString( - MediaGroupMemberInputMediaSerializer, + MediaGroupMemberTelegramMediaSerializer, encoded ) ) diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index 4c9a0e6160..a2d98f0f17 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -19,7 +19,7 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.* import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.* import dev.inmo.tgbotapi.types.InlineQueries.query.* -import dev.inmo.tgbotapi.types.InputMedia.* +import dev.inmo.tgbotapi.types.media.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.* import dev.inmo.tgbotapi.types.abstracts.WithOptionalLanguageCode import dev.inmo.tgbotapi.types.actions.* @@ -1895,128 +1895,284 @@ inline fun ChatMember.asSpecialRightsChatMember(): SpecialRightsChatMember? = th inline fun ChatMember.requireSpecialRightsChatMember(): SpecialRightsChatMember = this as SpecialRightsChatMember @PreviewFeature -inline fun InputMedia.whenAudioMediaGroupMemberInputMedia(block: (AudioMediaGroupMemberInputMedia) -> T) = asAudioMediaGroupMemberInputMedia() ?.let(block) +@Deprecated("Renamed", ReplaceWith("whenAudioMediaGroupMemberTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.whenAudioMediaGroupMemberTelegramMedia")) +inline fun TelegramMedia.whenAudioMediaGroupMemberInputMedia(block: (AudioMediaGroupMemberTelegramMedia) -> T) = whenAudioMediaGroupMemberTelegramMedia(block) @PreviewFeature -inline fun InputMedia.asAudioMediaGroupMemberInputMedia(): AudioMediaGroupMemberInputMedia? = - this as? AudioMediaGroupMemberInputMedia +@Deprecated("Renamed", ReplaceWith("asAudioMediaGroupMemberTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.asAudioMediaGroupMemberTelegramMedia")) +inline fun TelegramMedia.asAudioMediaGroupMemberInputMedia(): AudioMediaGroupMemberTelegramMedia? = asAudioMediaGroupMemberTelegramMedia() @PreviewFeature -inline fun InputMedia.requireAudioMediaGroupMemberInputMedia(): AudioMediaGroupMemberInputMedia = - this as AudioMediaGroupMemberInputMedia +@Deprecated("Renamed", ReplaceWith("requireAudioMediaGroupMemberTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.requireAudioMediaGroupMemberTelegramMedia")) +inline fun TelegramMedia.requireAudioMediaGroupMemberInputMedia(): AudioMediaGroupMemberTelegramMedia = requireAudioMediaGroupMemberTelegramMedia() @PreviewFeature -inline fun InputMedia.whenDocumentMediaGroupMemberInputMedia(block: (DocumentMediaGroupMemberInputMedia) -> T) = asDocumentMediaGroupMemberInputMedia() ?.let(block) +@Deprecated("Renamed", ReplaceWith("whenDocumentMediaGroupMemberTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.whenDocumentMediaGroupMemberTelegramMedia")) +inline fun TelegramMedia.whenDocumentMediaGroupMemberInputMedia(block: (DocumentMediaGroupMemberTelegramMedia) -> T) = whenDocumentMediaGroupMemberTelegramMedia(block) @PreviewFeature -inline fun InputMedia.asDocumentMediaGroupMemberInputMedia(): DocumentMediaGroupMemberInputMedia? = - this as? DocumentMediaGroupMemberInputMedia +@Deprecated("Renamed", ReplaceWith("asDocumentMediaGroupMemberTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.asDocumentMediaGroupMemberTelegramMedia")) +inline fun TelegramMedia.asDocumentMediaGroupMemberInputMedia(): DocumentMediaGroupMemberTelegramMedia? = asDocumentMediaGroupMemberTelegramMedia() @PreviewFeature -inline fun InputMedia.requireDocumentMediaGroupMemberInputMedia(): DocumentMediaGroupMemberInputMedia = - this as DocumentMediaGroupMemberInputMedia +@Deprecated("Renamed", ReplaceWith("requireDocumentMediaGroupMemberTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.requireDocumentMediaGroupMemberTelegramMedia")) +inline fun TelegramMedia.requireDocumentMediaGroupMemberInputMedia(): DocumentMediaGroupMemberTelegramMedia = requireDocumentMediaGroupMemberTelegramMedia() @PreviewFeature -inline fun InputMedia.whenDuratedInputMedia(block: (DuratedInputMedia) -> T) = asDuratedInputMedia() ?.let(block) +@Deprecated("Renamed", ReplaceWith("whenDuratedTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.whenDuratedTelegramMedia")) +inline fun TelegramMedia.whenDuratedInputMedia(block: (DuratedTelegramMedia) -> T) = whenDuratedTelegramMedia(block) @PreviewFeature -inline fun InputMedia.asDuratedInputMedia(): DuratedInputMedia? = this as? DuratedInputMedia +@Deprecated("Renamed", ReplaceWith("asDuratedTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.asDuratedTelegramMedia")) +inline fun TelegramMedia.asDuratedInputMedia(): DuratedTelegramMedia? = asDuratedTelegramMedia() @PreviewFeature -inline fun InputMedia.requireDuratedInputMedia(): DuratedInputMedia = this as DuratedInputMedia +@Deprecated("Renamed", ReplaceWith("requireDuratedTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.requireDuratedTelegramMedia")) +inline fun TelegramMedia.requireDuratedInputMedia(): DuratedTelegramMedia = requireDuratedTelegramMedia() @PreviewFeature -inline fun InputMedia.whenInputMediaAnimation(block: (InputMediaAnimation) -> T) = asInputMediaAnimation() ?.let(block) +@Deprecated("Renamed", ReplaceWith("whenTelegramMediaAnimation", "dev.inmo.tgbotapi.extensions.utils.whenTelegramMediaAnimation")) +inline fun TelegramMedia.whenInputMediaAnimation(block: (TelegramMediaAnimation) -> T) = whenTelegramMediaAnimation(block) @PreviewFeature -inline fun InputMedia.asInputMediaAnimation(): InputMediaAnimation? = this as? InputMediaAnimation +@Deprecated("Renamed", ReplaceWith("asTelegramMediaAnimation", "dev.inmo.tgbotapi.extensions.utils.asTelegramMediaAnimation")) +inline fun TelegramMedia.asInputMediaAnimation(): TelegramMediaAnimation? = asTelegramMediaAnimation() @PreviewFeature -inline fun InputMedia.requireInputMediaAnimation(): InputMediaAnimation = this as InputMediaAnimation +@Deprecated("Renamed", ReplaceWith("requireTelegramMediaAnimation", "dev.inmo.tgbotapi.extensions.utils.requireTelegramMediaAnimation")) +inline fun TelegramMedia.requireInputMediaAnimation(): TelegramMediaAnimation = requireTelegramMediaAnimation() @PreviewFeature -inline fun InputMedia.whenInputMediaAudio(block: (InputMediaAudio) -> T) = asInputMediaAudio() ?.let(block) +@Deprecated("Renamed", ReplaceWith("whenTelegramMediaAudio", "dev.inmo.tgbotapi.extensions.utils.whenTelegramMediaAudio")) +inline fun TelegramMedia.whenInputMediaAudio(block: (TelegramMediaAudio) -> T) = whenTelegramMediaAudio(block) @PreviewFeature -inline fun InputMedia.asInputMediaAudio(): InputMediaAudio? = this as? InputMediaAudio +@Deprecated("Renamed", ReplaceWith("asTelegramMediaAudio", "dev.inmo.tgbotapi.extensions.utils.asTelegramMediaAudio")) +inline fun TelegramMedia.asInputMediaAudio(): TelegramMediaAudio? = asTelegramMediaAudio() @PreviewFeature -inline fun InputMedia.requireInputMediaAudio(): InputMediaAudio = this as InputMediaAudio +@Deprecated("Renamed", ReplaceWith("requireTelegramMediaAudio", "dev.inmo.tgbotapi.extensions.utils.requireTelegramMediaAudio")) +inline fun TelegramMedia.requireInputMediaAudio(): TelegramMediaAudio = requireTelegramMediaAudio() @PreviewFeature -inline fun InputMedia.whenInputMediaDocument(block: (InputMediaDocument) -> T) = asInputMediaDocument() ?.let(block) +@Deprecated("Renamed", ReplaceWith("whenTelegramMediaDocument", "dev.inmo.tgbotapi.extensions.utils.whenTelegramMediaDocument")) +inline fun TelegramMedia.whenInputMediaDocument(block: (TelegramMediaDocument) -> T) = whenTelegramMediaDocument(block) @PreviewFeature -inline fun InputMedia.asInputMediaDocument(): InputMediaDocument? = this as? InputMediaDocument +@Deprecated("Renamed", ReplaceWith("asTelegramMediaDocument", "dev.inmo.tgbotapi.extensions.utils.asTelegramMediaDocument")) +inline fun TelegramMedia.asInputMediaDocument(): TelegramMediaDocument? = asTelegramMediaDocument() @PreviewFeature -inline fun InputMedia.requireInputMediaDocument(): InputMediaDocument = this as InputMediaDocument +@Deprecated("Renamed", ReplaceWith("requireTelegramMediaDocument", "dev.inmo.tgbotapi.extensions.utils.requireTelegramMediaDocument")) +inline fun TelegramMedia.requireInputMediaDocument(): TelegramMediaDocument = requireTelegramMediaDocument() @PreviewFeature -inline fun InputMedia.whenInputMediaPhoto(block: (InputMediaPhoto) -> T) = asInputMediaPhoto() ?.let(block) +@Deprecated("Renamed", ReplaceWith("whenTelegramMediaPhoto", "dev.inmo.tgbotapi.extensions.utils.whenTelegramMediaPhoto")) +inline fun TelegramMedia.whenInputMediaPhoto(block: (TelegramMediaPhoto) -> T) = whenTelegramMediaPhoto(block) @PreviewFeature -inline fun InputMedia.asInputMediaPhoto(): InputMediaPhoto? = this as? InputMediaPhoto +@Deprecated("Renamed", ReplaceWith("asTelegramMediaPhoto", "dev.inmo.tgbotapi.extensions.utils.asTelegramMediaPhoto")) +inline fun TelegramMedia.asInputMediaPhoto(): TelegramMediaPhoto? = asTelegramMediaPhoto() @PreviewFeature -inline fun InputMedia.requireInputMediaPhoto(): InputMediaPhoto = this as InputMediaPhoto +@Deprecated("Renamed", ReplaceWith("requireTelegramMediaPhoto", "dev.inmo.tgbotapi.extensions.utils.requireTelegramMediaPhoto")) +inline fun TelegramMedia.requireInputMediaPhoto(): TelegramMediaPhoto = requireTelegramMediaPhoto() @PreviewFeature -inline fun InputMedia.whenInputMediaVideo(block: (InputMediaVideo) -> T) = asInputMediaVideo() ?.let(block) +@Deprecated("Renamed", ReplaceWith("whenTelegramMediaVideo", "dev.inmo.tgbotapi.extensions.utils.whenTelegramMediaVideo")) +inline fun TelegramMedia.whenInputMediaVideo(block: (TelegramMediaVideo) -> T) = whenTelegramMediaVideo(block) @PreviewFeature -inline fun InputMedia.asInputMediaVideo(): InputMediaVideo? = this as? InputMediaVideo +@Deprecated("Renamed", ReplaceWith("asTelegramMediaVideo", "dev.inmo.tgbotapi.extensions.utils.asTelegramMediaVideo")) +inline fun TelegramMedia.asInputMediaVideo(): TelegramMediaVideo? = asTelegramMediaVideo() @PreviewFeature -inline fun InputMedia.requireInputMediaVideo(): InputMediaVideo = this as InputMediaVideo +@Deprecated("Renamed", ReplaceWith("requireTelegramMediaVideo", "dev.inmo.tgbotapi.extensions.utils.requireTelegramMediaVideo")) +inline fun TelegramMedia.requireInputMediaVideo(): TelegramMediaVideo = requireTelegramMediaVideo() @PreviewFeature -inline fun InputMedia.whenMediaGroupMemberInputMedia(block: (MediaGroupMemberInputMedia) -> T) = asMediaGroupMemberInputMedia() ?.let(block) +@Deprecated("Renamed", ReplaceWith("whenMediaGroupMemberTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.whenMediaGroupMemberTelegramMedia")) +inline fun TelegramMedia.whenMediaGroupMemberInputMedia(block: (MediaGroupMemberTelegramMedia) -> T) = whenMediaGroupMemberTelegramMedia(block) @PreviewFeature -inline fun InputMedia.asMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia? = this as? MediaGroupMemberInputMedia +@Deprecated("Renamed", ReplaceWith("asMediaGroupMemberTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.asMediaGroupMemberTelegramMedia")) +inline fun TelegramMedia.asMediaGroupMemberInputMedia(): MediaGroupMemberTelegramMedia? = asMediaGroupMemberTelegramMedia() @PreviewFeature -inline fun InputMedia.requireMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia = - this as MediaGroupMemberInputMedia +@Deprecated("Renamed", ReplaceWith("requireMediaGroupMemberTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.requireMediaGroupMemberTelegramMedia")) +inline fun TelegramMedia.requireMediaGroupMemberInputMedia(): MediaGroupMemberTelegramMedia = requireMediaGroupMemberTelegramMedia() @PreviewFeature -inline fun InputMedia.whenSizedInputMedia(block: (SizedInputMedia) -> T) = asSizedInputMedia() ?.let(block) +@Deprecated("Renamed", ReplaceWith("whenSizedTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.whenSizedTelegramMedia")) +inline fun TelegramMedia.whenSizedInputMedia(block: (SizedTelegramMedia) -> T) = whenSizedTelegramMedia(block) @PreviewFeature -inline fun InputMedia.asSizedInputMedia(): SizedInputMedia? = this as? SizedInputMedia +@Deprecated("Renamed", ReplaceWith("asSizedTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.asSizedTelegramMedia")) +inline fun TelegramMedia.asSizedInputMedia(): SizedTelegramMedia? = asSizedTelegramMedia() @PreviewFeature -inline fun InputMedia.requireSizedInputMedia(): SizedInputMedia = this as SizedInputMedia +@Deprecated("Renamed", ReplaceWith("requireSizedTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.requireSizedTelegramMedia")) +inline fun TelegramMedia.requireSizedInputMedia(): SizedTelegramMedia = requireSizedTelegramMedia() @PreviewFeature -inline fun InputMedia.whenThumbedInputMedia(block: (ThumbedInputMedia) -> T) = asThumbedInputMedia() ?.let(block) +@Deprecated("Renamed", ReplaceWith("whenThumbedTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.whenThumbedTelegramMedia")) +inline fun TelegramMedia.whenThumbedInputMedia(block: (ThumbedTelegramMedia) -> T) = whenThumbedTelegramMedia(block) @PreviewFeature -inline fun InputMedia.asThumbedInputMedia(): ThumbedInputMedia? = this as? ThumbedInputMedia +@Deprecated("Renamed", ReplaceWith("asThumbedTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.asThumbedTelegramMedia")) +inline fun TelegramMedia.asThumbedInputMedia(): ThumbedTelegramMedia? = asThumbedTelegramMedia() @PreviewFeature -inline fun InputMedia.requireThumbedInputMedia(): ThumbedInputMedia = this as ThumbedInputMedia +@Deprecated("Renamed", ReplaceWith("requireThumbedTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.requireThumbedTelegramMedia")) +inline fun TelegramMedia.requireThumbedInputMedia(): ThumbedTelegramMedia = requireThumbedTelegramMedia() @PreviewFeature -inline fun InputMedia.whenTitledInputMedia(block: (TitledInputMedia) -> T) = asTitledInputMedia() ?.let(block) +@Deprecated("Renamed", ReplaceWith("whenTitledTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.whenTitledTelegramMedia")) +inline fun TelegramMedia.whenTitledInputMedia(block: (TitledTelegramMedia) -> T) = whenTitledTelegramMedia(block) @PreviewFeature -inline fun InputMedia.asTitledInputMedia(): TitledInputMedia? = this as? TitledInputMedia +@Deprecated("Renamed", ReplaceWith("asTitledTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.asTitledTelegramMedia")) +inline fun TelegramMedia.asTitledInputMedia(): TitledTelegramMedia? = asTitledTelegramMedia() @PreviewFeature -inline fun InputMedia.requireTitledInputMedia(): TitledInputMedia = this as TitledInputMedia +@Deprecated("Renamed", ReplaceWith("requireTitledTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.requireTitledTelegramMedia")) +inline fun TelegramMedia.requireTitledInputMedia(): TitledTelegramMedia = requireTitledTelegramMedia() @PreviewFeature -inline fun InputMedia.whenVisualMediaGroupMemberInputMedia(block: (VisualMediaGroupMemberInputMedia) -> T) = asVisualMediaGroupMemberInputMedia() ?.let(block) +@Deprecated("Renamed", ReplaceWith("whenVisualMediaGroupMemberTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.whenVisualMediaGroupMemberTelegramMedia")) +inline fun TelegramMedia.whenVisualMediaGroupMemberInputMedia(block: (VisualMediaGroupMemberTelegramMedia) -> T) = whenVisualMediaGroupMemberTelegramMedia(block) @PreviewFeature -inline fun InputMedia.asVisualMediaGroupMemberInputMedia(): VisualMediaGroupMemberInputMedia? = - this as? VisualMediaGroupMemberInputMedia +@Deprecated("Renamed", ReplaceWith("asVisualMediaGroupMemberTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.asVisualMediaGroupMemberTelegramMedia")) +inline fun TelegramMedia.asVisualMediaGroupMemberInputMedia(): VisualMediaGroupMemberTelegramMedia? = asVisualMediaGroupMemberTelegramMedia() @PreviewFeature -inline fun InputMedia.requireVisualMediaGroupMemberInputMedia(): VisualMediaGroupMemberInputMedia = - this as VisualMediaGroupMemberInputMedia +@Deprecated("Renamed", ReplaceWith("requireVisualMediaGroupMemberTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.requireVisualMediaGroupMemberTelegramMedia")) +inline fun TelegramMedia.requireVisualMediaGroupMemberInputMedia(): VisualMediaGroupMemberTelegramMedia = requireVisualMediaGroupMemberTelegramMedia() + +@PreviewFeature +inline fun TelegramMedia.whenAudioMediaGroupMemberTelegramMedia(block: (AudioMediaGroupMemberTelegramMedia) -> T) = asAudioMediaGroupMemberTelegramMedia() ?.let(block) + +@PreviewFeature +inline fun TelegramMedia.asAudioMediaGroupMemberTelegramMedia(): AudioMediaGroupMemberTelegramMedia? = + this as? AudioMediaGroupMemberTelegramMedia + +@PreviewFeature +inline fun TelegramMedia.requireAudioMediaGroupMemberTelegramMedia(): AudioMediaGroupMemberTelegramMedia = + this as AudioMediaGroupMemberTelegramMedia + +@PreviewFeature +inline fun TelegramMedia.whenDocumentMediaGroupMemberTelegramMedia(block: (DocumentMediaGroupMemberTelegramMedia) -> T) = asDocumentMediaGroupMemberTelegramMedia() ?.let(block) + +@PreviewFeature +inline fun TelegramMedia.asDocumentMediaGroupMemberTelegramMedia(): DocumentMediaGroupMemberTelegramMedia? = + this as? DocumentMediaGroupMemberTelegramMedia + +@PreviewFeature +inline fun TelegramMedia.requireDocumentMediaGroupMemberTelegramMedia(): DocumentMediaGroupMemberTelegramMedia = + this as DocumentMediaGroupMemberTelegramMedia + +@PreviewFeature +inline fun TelegramMedia.whenDuratedTelegramMedia(block: (DuratedTelegramMedia) -> T) = asDuratedTelegramMedia() ?.let(block) + +@PreviewFeature +inline fun TelegramMedia.asDuratedTelegramMedia(): DuratedTelegramMedia? = this as? DuratedTelegramMedia + +@PreviewFeature +inline fun TelegramMedia.requireDuratedTelegramMedia(): DuratedTelegramMedia = this as DuratedTelegramMedia + +@PreviewFeature +inline fun TelegramMedia.whenTelegramMediaAnimation(block: (TelegramMediaAnimation) -> T) = asTelegramMediaAnimation() ?.let(block) + +@PreviewFeature +inline fun TelegramMedia.asTelegramMediaAnimation(): TelegramMediaAnimation? = this as? TelegramMediaAnimation + +@PreviewFeature +inline fun TelegramMedia.requireTelegramMediaAnimation(): TelegramMediaAnimation = this as TelegramMediaAnimation + +@PreviewFeature +inline fun TelegramMedia.whenTelegramMediaAudio(block: (TelegramMediaAudio) -> T) = asTelegramMediaAudio() ?.let(block) + +@PreviewFeature +inline fun TelegramMedia.asTelegramMediaAudio(): TelegramMediaAudio? = this as? TelegramMediaAudio + +@PreviewFeature +inline fun TelegramMedia.requireTelegramMediaAudio(): TelegramMediaAudio = this as TelegramMediaAudio + +@PreviewFeature +inline fun TelegramMedia.whenTelegramMediaDocument(block: (TelegramMediaDocument) -> T) = asTelegramMediaDocument() ?.let(block) + +@PreviewFeature +inline fun TelegramMedia.asTelegramMediaDocument(): TelegramMediaDocument? = this as? TelegramMediaDocument + +@PreviewFeature +inline fun TelegramMedia.requireTelegramMediaDocument(): TelegramMediaDocument = this as TelegramMediaDocument + +@PreviewFeature +inline fun TelegramMedia.whenTelegramMediaPhoto(block: (TelegramMediaPhoto) -> T) = asTelegramMediaPhoto() ?.let(block) + +@PreviewFeature +inline fun TelegramMedia.asTelegramMediaPhoto(): TelegramMediaPhoto? = this as? TelegramMediaPhoto + +@PreviewFeature +inline fun TelegramMedia.requireTelegramMediaPhoto(): TelegramMediaPhoto = this as TelegramMediaPhoto + +@PreviewFeature +inline fun TelegramMedia.whenTelegramMediaVideo(block: (TelegramMediaVideo) -> T) = asTelegramMediaVideo() ?.let(block) + +@PreviewFeature +inline fun TelegramMedia.asTelegramMediaVideo(): TelegramMediaVideo? = this as? TelegramMediaVideo + +@PreviewFeature +inline fun TelegramMedia.requireTelegramMediaVideo(): TelegramMediaVideo = this as TelegramMediaVideo + +@PreviewFeature +inline fun TelegramMedia.whenMediaGroupMemberTelegramMedia(block: (MediaGroupMemberTelegramMedia) -> T) = asMediaGroupMemberTelegramMedia() ?.let(block) + +@PreviewFeature +inline fun TelegramMedia.asMediaGroupMemberTelegramMedia(): MediaGroupMemberTelegramMedia? = this as? MediaGroupMemberTelegramMedia + +@PreviewFeature +inline fun TelegramMedia.requireMediaGroupMemberTelegramMedia(): MediaGroupMemberTelegramMedia = + this as MediaGroupMemberTelegramMedia + +@PreviewFeature +inline fun TelegramMedia.whenSizedTelegramMedia(block: (SizedTelegramMedia) -> T) = asSizedTelegramMedia() ?.let(block) + +@PreviewFeature +inline fun TelegramMedia.asSizedTelegramMedia(): SizedTelegramMedia? = this as? SizedTelegramMedia + +@PreviewFeature +inline fun TelegramMedia.requireSizedTelegramMedia(): SizedTelegramMedia = this as SizedTelegramMedia + +@PreviewFeature +inline fun TelegramMedia.whenThumbedTelegramMedia(block: (ThumbedTelegramMedia) -> T) = asThumbedTelegramMedia() ?.let(block) + +@PreviewFeature +inline fun TelegramMedia.asThumbedTelegramMedia(): ThumbedTelegramMedia? = this as? ThumbedTelegramMedia + +@PreviewFeature +inline fun TelegramMedia.requireThumbedTelegramMedia(): ThumbedTelegramMedia = this as ThumbedTelegramMedia + +@PreviewFeature +inline fun TelegramMedia.whenTitledTelegramMedia(block: (TitledTelegramMedia) -> T) = asTitledTelegramMedia() ?.let(block) + +@PreviewFeature +inline fun TelegramMedia.asTitledTelegramMedia(): TitledTelegramMedia? = this as? TitledTelegramMedia + +@PreviewFeature +inline fun TelegramMedia.requireTitledTelegramMedia(): TitledTelegramMedia = this as TitledTelegramMedia + +@PreviewFeature +inline fun TelegramMedia.whenVisualMediaGroupMemberTelegramMedia(block: (VisualMediaGroupMemberTelegramMedia) -> T) = asVisualMediaGroupMemberTelegramMedia() ?.let(block) + +@PreviewFeature +inline fun TelegramMedia.asVisualMediaGroupMemberTelegramMedia(): VisualMediaGroupMemberTelegramMedia? = + this as? VisualMediaGroupMemberTelegramMedia + +@PreviewFeature +inline fun TelegramMedia.requireVisualMediaGroupMemberTelegramMedia(): VisualMediaGroupMemberTelegramMedia = + this as VisualMediaGroupMemberTelegramMedia @PreviewFeature inline fun Update.whenCallbackQueryUpdate(block: (CallbackQueryUpdate) -> T) = asCallbackQueryUpdate() ?.let(block) diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/MediaGroupsShortcuts.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/MediaGroupsShortcuts.kt index 3b92f53eba..a0f02661e7 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/MediaGroupsShortcuts.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/MediaGroupsShortcuts.kt @@ -33,7 +33,7 @@ fun List>.createResend( replyTo: MessageIdentifier? = null ) = SendMediaGroup( chatId, - map { it.content.toMediaGroupMemberInputMedia() }, + map { it.content.toMediaGroupMemberTelegramMedia() }, disableNotification, protectContent, replyTo