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

rename InputMedia -> TelegramMedia and replace all InputMedia to media package

This commit is contained in:
InsanusMokrassar 2022-04-22 13:54:06 +06:00
parent a930423955
commit 900ef28404
53 changed files with 875 additions and 452 deletions

View File

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

View File

@ -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<out MediaContent>,
media: InputMedia,
media: TelegramMedia,
replyMarkup: InlineKeyboardMarkup? = null
) = editMessageMedia(message.chat.id, message.messageId, media, replyMarkup)

View File

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

View File

@ -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<MediaGroupMessage<MediaGroupContent>> {
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<MediaGroupMessage<MediaGroupContent>> {
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,

View File

@ -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<MediaGroupMemberInputMedia>,
media: List<MediaGroupMemberTelegramMedia>,
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<AudioMediaGroupMemberInputMedia>,
media: List<AudioMediaGroupMemberTelegramMedia>,
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<DocumentMediaGroupMemberInputMedia>,
media: List<DocumentMediaGroupMemberTelegramMedia>,
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<VisualMediaGroupMemberInputMedia>,
media: List<VisualMediaGroupMemberTelegramMedia>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null

View File

@ -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<MediaGroupMemberInputMedia>,
media: List<MediaGroupMemberTelegramMedia>,
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<MediaGroupMemberInputMedia>,
media: List<MediaGroupMemberTelegramMedia>,
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<AudioMediaGroupMemberInputMedia>,
media: List<AudioMediaGroupMemberTelegramMedia>,
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<AudioMediaGroupMemberInputMedia>,
media: List<AudioMediaGroupMemberTelegramMedia>,
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<DocumentMediaGroupMemberInputMedia>,
media: List<DocumentMediaGroupMemberTelegramMedia>,
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<DocumentMediaGroupMemberInputMedia>,
media: List<DocumentMediaGroupMemberTelegramMedia>,
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<VisualMediaGroupMemberInputMedia>,
media: List<VisualMediaGroupMemberTelegramMedia>,
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<VisualMediaGroupMemberInputMedia>,
media: List<VisualMediaGroupMemberTelegramMedia>,
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
)
/**

View File

@ -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
val media: TelegramMedia
}

View File

@ -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<MediaContent>, EditReplyMessage, EditMediaMessage {

View File

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

View File

@ -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 <T : MediaGroupContent> SendMediaGroup(
chatId: ChatIdentifier,
media: List<MediaGroupMemberInputMedia>,
media: List<MediaGroupMemberTelegramMedia>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
@ -36,7 +36,7 @@ fun <T : MediaGroupContent> SendMediaGroup(
val files: List<MultipartFile> = 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 <T : MediaGroupContent> 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<AudioMediaGroupMemberInputMedia>,
media: List<AudioMediaGroupMemberTelegramMedia>,
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<DocumentMediaGroupMemberInputMedia>,
media: List<DocumentMediaGroupMemberTelegramMedia>,
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<VisualMediaGroupMemberInputMedia>,
media: List<VisualMediaGroupMemberTelegramMedia>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
@ -116,7 +116,7 @@ private val messagesListSerializer: KSerializer<List<MediaGroupMessage<MediaGrou
data class SendMediaGroupData internal constructor(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
val media: List<MediaGroupMemberInputMedia> = emptyList(),
val media: List<MediaGroupMemberTelegramMedia> = 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()

View File

@ -1,5 +0,0 @@
package dev.inmo.tgbotapi.types.InputMedia
sealed interface DuratedInputMedia : InputMedia {
val duration: Long?
}

View File

@ -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<RawMessageEntity>? = 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
}

View File

@ -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<RawMessageEntity>? = 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,

View File

@ -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<RawMessageEntity>? = 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

View File

@ -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<RawMessageEntity>? = 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
)

View File

@ -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<InputMedia> {
@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")
}
}

View File

@ -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<RawMessageEntity>? = 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)

View File

@ -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> T.buildArguments(withSerializer: SerializationStrategy<T>) = 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

View File

@ -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<MediaGroupMemberInputMedia> {
@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")
}
}
}

View File

@ -1,6 +0,0 @@
package dev.inmo.tgbotapi.types.InputMedia
sealed interface SizedInputMedia : InputMedia {
val width: Int?
val height: Int?
}

View File

@ -1,7 +0,0 @@
package dev.inmo.tgbotapi.types.InputMedia
import dev.inmo.tgbotapi.requests.abstracts.InputFile
sealed interface ThumbedInputMedia : InputMedia {
val thumb: InputFile?
}

View File

@ -1,5 +0,0 @@
package dev.inmo.tgbotapi.types.InputMedia
sealed interface TitledInputMedia : InputMedia {
val title: String?
}

View File

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

View File

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

View File

@ -0,0 +1,5 @@
package dev.inmo.tgbotapi.types.media
sealed interface DuratedTelegramMedia : TelegramMedia {
val duration: Long?
}

View File

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

View File

@ -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<MediaGroupMemberTelegramMedia> {
@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")
}
}
}

View File

@ -0,0 +1,6 @@
package dev.inmo.tgbotapi.types.media
sealed interface SizedTelegramMedia : TelegramMedia {
val width: Int?
val height: Int?
}

View File

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

View File

@ -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<RawMessageEntity>? = 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
}

View File

@ -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<RawMessageEntity>? = 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
)

View File

@ -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<RawMessageEntity>? = 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
)

View File

@ -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<RawMessageEntity>? = 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
)

View File

@ -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<TelegramMedia> {
@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")
}
}

View File

@ -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<RawMessageEntity>? = 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
}

View File

@ -0,0 +1,7 @@
package dev.inmo.tgbotapi.types.media
import dev.inmo.tgbotapi.requests.abstracts.InputFile
sealed interface ThumbedTelegramMedia : TelegramMedia {
val thumb: InputFile?
}

View File

@ -0,0 +1,5 @@
package dev.inmo.tgbotapi.types.media
sealed interface TitledTelegramMedia : TelegramMedia {
val title: String?
}

View File

@ -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()
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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()
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 <T> InputMedia.whenAudioMediaGroupMemberInputMedia(block: (AudioMediaGroupMemberInputMedia) -> T) = asAudioMediaGroupMemberInputMedia() ?.let(block)
@Deprecated("Renamed", ReplaceWith("whenAudioMediaGroupMemberTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.whenAudioMediaGroupMemberTelegramMedia"))
inline fun <T> 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 <T> InputMedia.whenDocumentMediaGroupMemberInputMedia(block: (DocumentMediaGroupMemberInputMedia) -> T) = asDocumentMediaGroupMemberInputMedia() ?.let(block)
@Deprecated("Renamed", ReplaceWith("whenDocumentMediaGroupMemberTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.whenDocumentMediaGroupMemberTelegramMedia"))
inline fun <T> 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 <T> InputMedia.whenDuratedInputMedia(block: (DuratedInputMedia) -> T) = asDuratedInputMedia() ?.let(block)
@Deprecated("Renamed", ReplaceWith("whenDuratedTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.whenDuratedTelegramMedia"))
inline fun <T> 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 <T> InputMedia.whenInputMediaAnimation(block: (InputMediaAnimation) -> T) = asInputMediaAnimation() ?.let(block)
@Deprecated("Renamed", ReplaceWith("whenTelegramMediaAnimation", "dev.inmo.tgbotapi.extensions.utils.whenTelegramMediaAnimation"))
inline fun <T> 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 <T> InputMedia.whenInputMediaAudio(block: (InputMediaAudio) -> T) = asInputMediaAudio() ?.let(block)
@Deprecated("Renamed", ReplaceWith("whenTelegramMediaAudio", "dev.inmo.tgbotapi.extensions.utils.whenTelegramMediaAudio"))
inline fun <T> 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 <T> InputMedia.whenInputMediaDocument(block: (InputMediaDocument) -> T) = asInputMediaDocument() ?.let(block)
@Deprecated("Renamed", ReplaceWith("whenTelegramMediaDocument", "dev.inmo.tgbotapi.extensions.utils.whenTelegramMediaDocument"))
inline fun <T> 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 <T> InputMedia.whenInputMediaPhoto(block: (InputMediaPhoto) -> T) = asInputMediaPhoto() ?.let(block)
@Deprecated("Renamed", ReplaceWith("whenTelegramMediaPhoto", "dev.inmo.tgbotapi.extensions.utils.whenTelegramMediaPhoto"))
inline fun <T> 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 <T> InputMedia.whenInputMediaVideo(block: (InputMediaVideo) -> T) = asInputMediaVideo() ?.let(block)
@Deprecated("Renamed", ReplaceWith("whenTelegramMediaVideo", "dev.inmo.tgbotapi.extensions.utils.whenTelegramMediaVideo"))
inline fun <T> 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 <T> InputMedia.whenMediaGroupMemberInputMedia(block: (MediaGroupMemberInputMedia) -> T) = asMediaGroupMemberInputMedia() ?.let(block)
@Deprecated("Renamed", ReplaceWith("whenMediaGroupMemberTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.whenMediaGroupMemberTelegramMedia"))
inline fun <T> 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 <T> InputMedia.whenSizedInputMedia(block: (SizedInputMedia) -> T) = asSizedInputMedia() ?.let(block)
@Deprecated("Renamed", ReplaceWith("whenSizedTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.whenSizedTelegramMedia"))
inline fun <T> 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 <T> InputMedia.whenThumbedInputMedia(block: (ThumbedInputMedia) -> T) = asThumbedInputMedia() ?.let(block)
@Deprecated("Renamed", ReplaceWith("whenThumbedTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.whenThumbedTelegramMedia"))
inline fun <T> 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 <T> InputMedia.whenTitledInputMedia(block: (TitledInputMedia) -> T) = asTitledInputMedia() ?.let(block)
@Deprecated("Renamed", ReplaceWith("whenTitledTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.whenTitledTelegramMedia"))
inline fun <T> 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 <T> InputMedia.whenVisualMediaGroupMemberInputMedia(block: (VisualMediaGroupMemberInputMedia) -> T) = asVisualMediaGroupMemberInputMedia() ?.let(block)
@Deprecated("Renamed", ReplaceWith("whenVisualMediaGroupMemberTelegramMedia", "dev.inmo.tgbotapi.extensions.utils.whenVisualMediaGroupMemberTelegramMedia"))
inline fun <T> 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 <T> 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 <T> 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 <T> 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 <T> 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 <T> 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 <T> 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 <T> 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 <T> 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 <T> 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 <T> 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 <T> 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 <T> 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 <T> 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 <T> Update.whenCallbackQueryUpdate(block: (CallbackQueryUpdate) -> T) = asCallbackQueryUpdate() ?.let(block)

View File

@ -33,7 +33,7 @@ fun List<CommonMessage<MediaGroupContent>>.createResend(
replyTo: MessageIdentifier? = null
) = SendMediaGroup<MediaGroupContent>(
chatId,
map { it.content.toMediaGroupMemberInputMedia() },
map { it.content.toMediaGroupMemberTelegramMedia() },
disableNotification,
protectContent,
replyTo