From d4490dec7504468c6333c99ec3d1b0ce2c7bf404 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 14 Feb 2025 21:01:47 +0600 Subject: [PATCH] potentially cover new update of Bot API --- .../tgbotapi/extensions/api/ForwardMessage.kt | 19 +++++++++----- .../extensions/api/send/CopyMessage.kt | 24 ++++++++++++++++++ .../extensions/api/send/media/SendVideo.kt | 20 +++++++++++++++ .../inmo/tgbotapi/abstracts/CoverableData.kt | 8 ++++++ .../abstracts/WithCustomStartMediaData.kt | 7 ++++++ .../inmo/tgbotapi/requests/ForwardMessage.kt | 5 +++- .../requests/abstracts/MultipartRequest.kt | 7 ++++++ .../tgbotapi/requests/send/CopyMessage.kt | 10 +++++++- .../abstracts/CoveredSendMessageRequest.kt | 10 ++++++++ .../requests/send/media/SendMediaGroup.kt | 5 ++++ .../requests/send/media/SendPaidMedia.kt | 11 ++++++++ .../tgbotapi/requests/send/media/SendVideo.kt | 25 ++++++++++++++++--- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 4 +++ .../tgbotapi/types/files/CoveredMediaFile.kt | 5 ++++ .../types/files/CustomStartMediaFile.kt | 5 ++++ .../inmo/tgbotapi/types/files/VideoFile.kt | 6 ++++- .../types/media/CoveredTelegramMedia.kt | 7 ++++++ .../types/media/TelegramMediaVideo.kt | 14 ++++++++++- .../types/media/TelegramPaidMediaVideo.kt | 15 +++++++++-- .../media/WithCustomStartTelegramMedia.kt | 6 +++++ .../types/message/content/VideoContent.kt | 2 ++ 21 files changed, 199 insertions(+), 16 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/CoverableData.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/WithCustomStartMediaData.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/CoveredSendMessageRequest.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/CoveredMediaFile.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/CustomStartMediaFile.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/CoveredTelegramMedia.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/WithCustomStartTelegramMedia.kt diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/ForwardMessage.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/ForwardMessage.kt index d196a5123d..ff07e2d325 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/ForwardMessage.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/ForwardMessage.kt @@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.requests.ForwardMessage import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.MessageThreadId +import dev.inmo.tgbotapi.types.Seconds import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.PossiblyForwardedMessage @@ -15,10 +16,11 @@ public suspend fun TelegramBot.forwardMessage( toChatId: ChatIdentifier, messageId: MessageId, threadId: MessageThreadId? = toChatId.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false ): PossiblyForwardedMessage = execute( - ForwardMessage(fromChatId, toChatId, messageId, threadId, disableNotification, protectContent) + ForwardMessage(fromChatId, toChatId, messageId, threadId, startTimestamp, disableNotification, protectContent) ) public suspend fun TelegramBot.forwardMessage( @@ -26,40 +28,45 @@ public suspend fun TelegramBot.forwardMessage( toChatId: ChatIdentifier, messageId: MessageId, threadId: MessageThreadId? = toChatId.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false -): PossiblyForwardedMessage = forwardMessage(fromChat.id, toChatId, messageId, threadId, disableNotification, protectContent) +): PossiblyForwardedMessage = forwardMessage(fromChat.id, toChatId, messageId, threadId, startTimestamp, disableNotification, protectContent) public suspend fun TelegramBot.forwardMessage( fromChatId: ChatIdentifier, toChat: Chat, messageId: MessageId, threadId: MessageThreadId? = toChat.id.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false -): PossiblyForwardedMessage = forwardMessage(fromChatId, toChat.id, messageId, threadId, disableNotification, protectContent) +): PossiblyForwardedMessage = forwardMessage(fromChatId, toChat.id, messageId, threadId, startTimestamp, disableNotification, protectContent) public suspend fun TelegramBot.forwardMessage( fromChat: Chat, toChat: Chat, messageId: MessageId, threadId: MessageThreadId? = toChat.id.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false -): PossiblyForwardedMessage = forwardMessage(fromChat.id, toChat.id, messageId, threadId, disableNotification, protectContent) +): PossiblyForwardedMessage = forwardMessage(fromChat.id, toChat.id, messageId, threadId, startTimestamp, disableNotification, protectContent) public suspend fun TelegramBot.forwardMessage( toChatId: ChatIdentifier, message: AccessibleMessage, threadId: MessageThreadId? = toChatId.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false -): PossiblyForwardedMessage = forwardMessage(message.chat, toChatId, message.messageId, threadId, disableNotification, protectContent) +): PossiblyForwardedMessage = forwardMessage(message.chat, toChatId, message.messageId, threadId, startTimestamp, disableNotification, protectContent) public suspend fun TelegramBot.forwardMessage( toChat: Chat, message: AccessibleMessage, threadId: MessageThreadId? = toChat.id.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false -): PossiblyForwardedMessage = forwardMessage(message.chat, toChat, message.messageId, threadId, disableNotification, protectContent) +): PossiblyForwardedMessage = forwardMessage(message.chat, toChat, message.messageId, threadId, startTimestamp, disableNotification, protectContent) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessage.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessage.kt index 395ffde4d0..448fef01ee 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessage.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessage.kt @@ -21,6 +21,7 @@ public suspend inline fun TelegramBot.copyMessage( parseMode: ParseMode? = null, showCaptionAboveMedia: Boolean = false, threadId: MessageThreadId? = toChatId.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false, allowPaidBroadcast: Boolean = false, @@ -35,6 +36,7 @@ public suspend inline fun TelegramBot.copyMessage( parseMode = parseMode, showCaptionAboveMedia = showCaptionAboveMedia, threadId = threadId, + startTimestamp = startTimestamp, disableNotification = disableNotification, protectContent = protectContent, allowPaidBroadcast = allowPaidBroadcast, @@ -55,6 +57,7 @@ public suspend inline fun TelegramBot.copyMessage( parseMode: ParseMode? = null, showCaptionAboveMedia: Boolean = false, threadId: MessageThreadId? = toChatId.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false, allowPaidBroadcast: Boolean = false, @@ -68,6 +71,7 @@ public suspend inline fun TelegramBot.copyMessage( parseMode = parseMode, showCaptionAboveMedia = showCaptionAboveMedia, threadId = threadId, + startTimestamp = startTimestamp, disableNotification = disableNotification, protectContent = protectContent, allowPaidBroadcast = allowPaidBroadcast, @@ -87,6 +91,7 @@ public suspend inline fun TelegramBot.copyMessage( parseMode: ParseMode? = null, showCaptionAboveMedia: Boolean = false, threadId: MessageThreadId? = toChat.id.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false, allowPaidBroadcast: Boolean = false, @@ -100,6 +105,7 @@ public suspend inline fun TelegramBot.copyMessage( parseMode = parseMode, showCaptionAboveMedia = showCaptionAboveMedia, threadId = threadId, + startTimestamp = startTimestamp, disableNotification = disableNotification, protectContent = protectContent, allowPaidBroadcast = allowPaidBroadcast, @@ -119,6 +125,7 @@ public suspend inline fun TelegramBot.copyMessage( parseMode: ParseMode? = null, showCaptionAboveMedia: Boolean = false, threadId: MessageThreadId? = toChat.id.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false, allowPaidBroadcast: Boolean = false, @@ -132,6 +139,7 @@ public suspend inline fun TelegramBot.copyMessage( parseMode = parseMode, showCaptionAboveMedia = showCaptionAboveMedia, threadId = threadId, + startTimestamp = startTimestamp, disableNotification = disableNotification, protectContent = protectContent, allowPaidBroadcast = allowPaidBroadcast, @@ -151,6 +159,7 @@ public suspend inline fun TelegramBot.copyMessage( entities: TextSourcesList, showCaptionAboveMedia: Boolean = false, threadId: MessageThreadId? = toChatId.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false, allowPaidBroadcast: Boolean = false, @@ -164,6 +173,7 @@ public suspend inline fun TelegramBot.copyMessage( entities = entities, showCaptionAboveMedia = showCaptionAboveMedia, threadId = threadId, + startTimestamp = startTimestamp, disableNotification = disableNotification, protectContent = protectContent, allowPaidBroadcast = allowPaidBroadcast, @@ -183,6 +193,7 @@ public suspend inline fun TelegramBot.copyMessage( entities: TextSourcesList, showCaptionAboveMedia: Boolean = false, threadId: MessageThreadId? = toChatId.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false, allowPaidBroadcast: Boolean = false, @@ -195,6 +206,7 @@ public suspend inline fun TelegramBot.copyMessage( entities = entities, showCaptionAboveMedia = showCaptionAboveMedia, threadId = threadId, + startTimestamp = startTimestamp, disableNotification = disableNotification, protectContent = protectContent, allowPaidBroadcast = allowPaidBroadcast, @@ -213,6 +225,7 @@ public suspend inline fun TelegramBot.copyMessage( entities: TextSourcesList, showCaptionAboveMedia: Boolean = false, threadId: MessageThreadId? = toChat.id.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false, allowPaidBroadcast: Boolean = false, @@ -225,6 +238,7 @@ public suspend inline fun TelegramBot.copyMessage( entities = entities, showCaptionAboveMedia = showCaptionAboveMedia, threadId = threadId, + startTimestamp = startTimestamp, disableNotification = disableNotification, protectContent = protectContent, allowPaidBroadcast = allowPaidBroadcast, @@ -243,6 +257,7 @@ public suspend inline fun TelegramBot.copyMessage( entities: TextSourcesList, showCaptionAboveMedia: Boolean = false, threadId: MessageThreadId? = toChat.id.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false, allowPaidBroadcast: Boolean = false, @@ -255,6 +270,7 @@ public suspend inline fun TelegramBot.copyMessage( entities = entities, showCaptionAboveMedia = showCaptionAboveMedia, threadId = threadId, + startTimestamp = startTimestamp, disableNotification = disableNotification, protectContent = protectContent, allowPaidBroadcast = allowPaidBroadcast, @@ -273,6 +289,7 @@ public suspend inline fun TelegramBot.copyMessage( parseMode: ParseMode? = null, showCaptionAboveMedia: Boolean = false, threadId: MessageThreadId? = toChatId.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false, allowPaidBroadcast: Boolean = false, @@ -286,6 +303,7 @@ public suspend inline fun TelegramBot.copyMessage( parseMode = parseMode, showCaptionAboveMedia = showCaptionAboveMedia, threadId = threadId, + startTimestamp = startTimestamp, disableNotification = disableNotification, protectContent = protectContent, allowPaidBroadcast = allowPaidBroadcast, @@ -304,6 +322,7 @@ public suspend inline fun TelegramBot.copyMessage( parseMode: ParseMode? = null, showCaptionAboveMedia: Boolean = false, threadId: MessageThreadId? = toChat.id.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false, allowPaidBroadcast: Boolean = false, @@ -317,6 +336,7 @@ public suspend inline fun TelegramBot.copyMessage( parseMode = parseMode, showCaptionAboveMedia = showCaptionAboveMedia, threadId = threadId, + startTimestamp = startTimestamp, disableNotification = disableNotification, protectContent = protectContent, allowPaidBroadcast = allowPaidBroadcast, @@ -334,6 +354,7 @@ public suspend inline fun TelegramBot.copyMessage( entities: TextSourcesList, showCaptionAboveMedia: Boolean = false, threadId: MessageThreadId? = toChatId.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false, allowPaidBroadcast: Boolean = false, @@ -346,6 +367,7 @@ public suspend inline fun TelegramBot.copyMessage( entities = entities, showCaptionAboveMedia = showCaptionAboveMedia, threadId = threadId, + startTimestamp = startTimestamp, disableNotification = disableNotification, protectContent = protectContent, allowPaidBroadcast = allowPaidBroadcast, @@ -363,6 +385,7 @@ public suspend inline fun TelegramBot.copyMessage( entities: TextSourcesList, showCaptionAboveMedia: Boolean = false, threadId: MessageThreadId? = toChat.id.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false, allowPaidBroadcast: Boolean = false, @@ -375,6 +398,7 @@ public suspend inline fun TelegramBot.copyMessage( entities = entities, showCaptionAboveMedia = showCaptionAboveMedia, threadId = threadId, + startTimestamp = startTimestamp, disableNotification = disableNotification, protectContent = protectContent, allowPaidBroadcast = allowPaidBroadcast, diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt index 5517f18d64..440a3a58e1 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt @@ -25,6 +25,8 @@ public suspend fun TelegramBot.sendVideo( parseMode: ParseMode? = null, showCaptionAboveMedia: Boolean = false, spoilered: Boolean = false, + cover: InputFile? = null, + startTimestamp: Seconds? = null, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -45,6 +47,8 @@ public suspend fun TelegramBot.sendVideo( parseMode = parseMode, showCaptionAboveMedia = showCaptionAboveMedia, spoilered = spoilered, + cover = cover, + startTimestamp = startTimestamp, duration = duration, width = width, height = height, @@ -87,6 +91,8 @@ public suspend fun TelegramBot.sendVideo( parseMode = parseMode, showCaptionAboveMedia = showCaptionAboveMedia, spoilered = spoilered, + cover = video.cover ?.fileId, + startTimestamp = video.startTimestamp, duration = video.duration, width = video.width, height = video.height, @@ -112,6 +118,8 @@ public suspend fun TelegramBot.sendVideo( parseMode: ParseMode? = null, showCaptionAboveMedia: Boolean = false, spoilered: Boolean = false, + cover: InputFile? = null, + startTimestamp: Seconds? = null, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -131,6 +139,8 @@ public suspend fun TelegramBot.sendVideo( parseMode = parseMode, showCaptionAboveMedia = showCaptionAboveMedia, spoilered = spoilered, + cover = cover, + startTimestamp = startTimestamp, duration = duration, width = width, height = height, @@ -192,6 +202,8 @@ public suspend inline fun TelegramBot.sendVideo( entities: TextSourcesList, showCaptionAboveMedia: Boolean = false, spoilered: Boolean = false, + cover: InputFile? = null, + startTimestamp: Seconds? = null, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -211,6 +223,8 @@ public suspend inline fun TelegramBot.sendVideo( entities = entities, showCaptionAboveMedia = showCaptionAboveMedia, spoilered = spoilered, + cover = cover, + startTimestamp = startTimestamp, duration = duration, width = width, height = height, @@ -251,6 +265,8 @@ public suspend inline fun TelegramBot.sendVideo( entities = entities, showCaptionAboveMedia = showCaptionAboveMedia, spoilered = spoilered, + cover = video.cover ?.fileId, + startTimestamp = video.startTimestamp, duration = video.duration, width = video.width, height = video.height, @@ -275,6 +291,8 @@ public suspend inline fun TelegramBot.sendVideo( entities: TextSourcesList, showCaptionAboveMedia: Boolean = false, spoilered: Boolean = false, + cover: InputFile? = null, + startTimestamp: Seconds? = null, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -293,6 +311,8 @@ public suspend inline fun TelegramBot.sendVideo( entities = entities, showCaptionAboveMedia = showCaptionAboveMedia, spoilered = spoilered, + cover = cover, + startTimestamp = startTimestamp, duration = duration, width = width, height = height, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/CoverableData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/CoverableData.kt new file mode 100644 index 0000000000..fbe400360a --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/CoverableData.kt @@ -0,0 +1,8 @@ +package dev.inmo.tgbotapi.abstracts + +import dev.inmo.tgbotapi.types.files.Photo +import dev.inmo.tgbotapi.types.files.TelegramMediaFile + +interface CoverableData { + val cover: Photo? +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/WithCustomStartMediaData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/WithCustomStartMediaData.kt new file mode 100644 index 0000000000..430815d327 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/WithCustomStartMediaData.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.abstracts + +import dev.inmo.tgbotapi.types.Seconds + +interface WithCustomStartMediaData { + val startTimestamp: Seconds? +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/ForwardMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/ForwardMessage.kt index eca9e8706a..e8b0d99219 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/ForwardMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/ForwardMessage.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.requests +import dev.inmo.tgbotapi.abstracts.WithCustomStartMediaData import dev.inmo.tgbotapi.abstracts.types.MessageAction import dev.inmo.tgbotapi.abstracts.types.ProtectContent import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest @@ -21,11 +22,13 @@ data class ForwardMessage( override val messageId: MessageId, @SerialName(messageThreadIdField) override val threadId: MessageThreadId? = toChatId.threadId, + @SerialName(videoStartTimestampField) + override val startTimestamp: Seconds? = null, @SerialName(disableNotificationField) val disableNotification: Boolean = false, @SerialName(protectContentField) override val protectContent: Boolean = false -): SimpleRequest, MessageAction, ProtectContent, OptionallyMessageThreadRequest { +): SimpleRequest, MessageAction, ProtectContent, OptionallyMessageThreadRequest, WithCustomStartMediaData { override val chatId: ChatIdentifier get() = fromChatId diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/abstracts/MultipartRequest.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/abstracts/MultipartRequest.kt index 4e4385866f..16eef9fa99 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/abstracts/MultipartRequest.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/abstracts/MultipartRequest.kt @@ -5,4 +5,11 @@ import kotlinx.serialization.json.JsonObject interface MultipartRequest : Request { val paramsJson: JsonObject val mediaMap: Map + + interface Common : MultipartRequest, SimpleRequest { + val data: SimpleRequest + + override val paramsJson: JsonObject + get() = data.json() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt index fbc21badcd..edca7d0f6e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.requests.send import dev.inmo.tgbotapi.abstracts.TextedOutput +import dev.inmo.tgbotapi.abstracts.WithCustomStartMediaData import dev.inmo.tgbotapi.abstracts.WithCustomizableCaption import dev.inmo.tgbotapi.abstracts.types.MessageAction import dev.inmo.tgbotapi.abstracts.types.ProtectContent @@ -89,6 +90,7 @@ fun CopyMessage( parseMode: ParseMode? = null, showCaptionAboveMedia: Boolean = false, threadId: MessageThreadId? = toChatId.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false, allowPaidBroadcast: Boolean = false, @@ -103,6 +105,7 @@ fun CopyMessage( rawEntities = null, showCaptionAboveMedia = showCaptionAboveMedia, threadId = threadId, + startTimestamp = startTimestamp, disableNotification = disableNotification, protectContent = protectContent, allowPaidBroadcast = allowPaidBroadcast, @@ -117,6 +120,7 @@ fun CopyMessage( entities: List, showCaptionAboveMedia: Boolean = false, threadId: MessageThreadId? = toChatId.threadId, + startTimestamp: Seconds? = null, disableNotification: Boolean = false, protectContent: Boolean = false, allowPaidBroadcast: Boolean = false, @@ -131,6 +135,7 @@ fun CopyMessage( rawEntities = entities.toRawMessageEntities(), showCaptionAboveMedia = showCaptionAboveMedia, threadId = threadId, + startTimestamp = startTimestamp, disableNotification = disableNotification, protectContent = protectContent, allowPaidBroadcast = allowPaidBroadcast, @@ -156,6 +161,8 @@ data class CopyMessage internal constructor( override val showCaptionAboveMedia: Boolean = false, @SerialName(messageThreadIdField) override val threadId: MessageThreadId? = toChatId.threadId, + @SerialName(videoStartTimestampField) + override val startTimestamp: Seconds? = null, @SerialName(disableNotificationField) override val disableNotification: Boolean = false, @SerialName(protectContentField) @@ -172,7 +179,8 @@ data class CopyMessage internal constructor( MessageAction, TextedOutput, ProtectContent, - OptionallyMessageThreadRequest { + OptionallyMessageThreadRequest, + WithCustomStartMediaData { override val chatId: ChatIdentifier get() = fromChatId override val textSources: List? by lazy { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/CoveredSendMessageRequest.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/CoveredSendMessageRequest.kt new file mode 100644 index 0000000000..1d366a113b --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/CoveredSendMessageRequest.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.requests.send.abstracts + +import dev.inmo.tgbotapi.requests.abstracts.FileId + +interface CoveredSendMessageRequest: SendMessageRequest { + /** + * Duration of media, usually in seconds + */ + val cover: String? +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt index 4fc5d6735a..63ef5c25e8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt @@ -51,6 +51,11 @@ fun SendMediaGroup( it.thumb as? MultipartFile } else { null + }, + if (it is CoveredTelegramMedia) { + it.cover as? MultipartFile + } else { + null } ) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPaidMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPaidMedia.kt index d343e00b28..09c0ba2cc7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPaidMedia.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPaidMedia.kt @@ -12,6 +12,7 @@ import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList import dev.inmo.tgbotapi.types.message.ParseMode import dev.inmo.tgbotapi.types.message.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup +import dev.inmo.tgbotapi.types.media.CoveredTelegramMedia import dev.inmo.tgbotapi.types.media.ThumbedTelegramMedia import dev.inmo.tgbotapi.types.message.* import dev.inmo.tgbotapi.types.message.RawMessageEntity @@ -63,6 +64,11 @@ fun SendPaidMedia( it.thumb as? MultipartFile } else { null + }, + if (it is CoveredTelegramMedia) { + it.cover as? MultipartFile + } else { + null } ) } @@ -117,6 +123,11 @@ fun SendPaidMedia( it.thumb as? MultipartFile } else { null + }, + if (it is CoveredTelegramMedia) { + it.cover as? MultipartFile + } else { + null } ) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt index 5b4e9590df..3e86233fc5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.requests.send.media +import dev.inmo.tgbotapi.abstracts.WithCustomStartMediaData import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.common.CommonMultipartFileRequest import dev.inmo.tgbotapi.requests.send.abstracts.* @@ -29,6 +30,8 @@ fun SendVideo( parseMode: ParseMode? = null, showCaptionAboveMedia: Boolean = false, spoilered: Boolean = false, + cover: InputFile? = null, + startTimestamp: Seconds? = null, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -44,11 +47,14 @@ fun SendVideo( ): Request> { val videoAsFile = video as? MultipartFile val thumbAsFile = thumbnail as? MultipartFile + val coverAsFile = cover as? MultipartFile val data = SendVideoData( chatId = chatId, video = video, thumbnail = thumbnail ?.fileId, + cover = cover ?.fileId, + startTimestamp = startTimestamp, text = text, parseMode = parseMode, rawEntities = null, @@ -68,12 +74,12 @@ fun SendVideo( replyMarkup = replyMarkup ) - return if (videoAsFile == null && thumbAsFile == null) { + return if (videoAsFile == null && thumbAsFile == null && coverAsFile == null) { data } else { CommonMultipartFileRequest( data, - listOfNotNull(videoAsFile, thumbAsFile).associateBy { it.fileId } + listOfNotNull(videoAsFile, thumbAsFile, coverAsFile).associateBy { it.fileId } ) } } @@ -85,6 +91,8 @@ fun SendVideo( entities: TextSourcesList, showCaptionAboveMedia: Boolean = false, spoilered: Boolean = false, + cover: InputFile? = null, + startTimestamp: Seconds? = null, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -100,11 +108,14 @@ fun SendVideo( ): Request> { val videoAsFile = video as? MultipartFile val thumbAsFile = thumbnail as? MultipartFile + val coverAsFile = cover as? MultipartFile val data = SendVideoData( chatId = chatId, video = video, thumbnail = thumbnail ?.fileId, + cover = cover ?.fileId, + startTimestamp = startTimestamp, text = entities.makeString(), parseMode = null, rawEntities = entities.toRawMessageEntities(), @@ -124,12 +135,12 @@ fun SendVideo( replyMarkup = replyMarkup ) - return if (videoAsFile == null && thumbAsFile == null) { + return if (videoAsFile == null && thumbAsFile == null && coverAsFile == null) { data } else { CommonMultipartFileRequest( data, - listOfNotNull(videoAsFile, thumbAsFile).associateBy { it.fileId } + listOfNotNull(videoAsFile, thumbAsFile, coverAsFile).associateBy { it.fileId } ) } } @@ -145,6 +156,10 @@ data class SendVideoData internal constructor( val video: InputFile, @SerialName(thumbnailField) override val thumbnail: String? = null, + @SerialName(coverField) + override val cover: String? = null, + @SerialName(startTimestampField) + override val startTimestamp: Seconds? = null, @SerialName(captionField) override val text: String? = null, @SerialName(parseModeField) @@ -187,6 +202,8 @@ data class SendVideoData internal constructor( DuratedSendMessageRequest>, SizedSendMessageRequest>, WithCustomizableCaptionRequest>, + CoveredSendMessageRequest>, + WithCustomStartMediaData, OptionallyWithSpoilerRequest { override val textSources: TextSourcesList? by lazy { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 7df1682327..a91b4510fe 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -315,6 +315,9 @@ const val userAdministratorRightsField = "user_administrator_rights" const val botAdministratorRightsField = "bot_administrator_rights" const val botIsMemberField = "bot_is_member" +const val startTimestampField = "start_timestamp" +const val videoStartTimestampField = "video_start_timestamp" + const val fileNameField = "file_name" const val mimeTypeField = "mime_type" const val fileIdField = "file_id" @@ -424,6 +427,7 @@ const val idField = "id" const val pollIdField = "poll_id" const val textField = "text" const val thumbnailField = "thumbnail" +const val coverField = "cover" const val emojiField = "emoji" const val emojisField = "emojis" const val titleField = "title" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/CoveredMediaFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/CoveredMediaFile.kt new file mode 100644 index 0000000000..b150ef97e2 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/CoveredMediaFile.kt @@ -0,0 +1,5 @@ +package dev.inmo.tgbotapi.types.files + +import dev.inmo.tgbotapi.abstracts.CoverableData + +sealed interface CoveredMediaFile : TelegramMediaFile, CoverableData diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/CustomStartMediaFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/CustomStartMediaFile.kt new file mode 100644 index 0000000000..f8225e14d4 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/CustomStartMediaFile.kt @@ -0,0 +1,5 @@ +package dev.inmo.tgbotapi.types.files + +import dev.inmo.tgbotapi.abstracts.WithCustomStartMediaData + +sealed interface CustomStartMediaFile : WithCustomStartMediaData diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt index e9d492ff5f..b984a1b988 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt @@ -24,13 +24,17 @@ data class VideoFile( override val duration: Long? = null, @SerialName(thumbnailField) override val thumbnail: PhotoSize? = null, + @SerialName(coverField) + override val cover: Photo? = null, + @SerialName(startTimestampField) + override val startTimestamp: Seconds? = null, @SerialName(fileNameField) override val fileName: String? = null, @SerialName(mimeTypeField) override val mimeType: MimeType? = null, @SerialName(fileSizeField) override val fileSize: Long? = null -) : TelegramMediaFile, CustomNamedMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile, +) : TelegramMediaFile, CustomNamedMediaFile, MimedMediaFile, CoveredMediaFile, CustomStartMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile, MediaContentVariant, UsefulAsPaidMediaFile @Suppress("NOTHING_TO_INLINE") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/CoveredTelegramMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/CoveredTelegramMedia.kt new file mode 100644 index 0000000000..d1268243d9 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/CoveredTelegramMedia.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.types.media + +import dev.inmo.tgbotapi.requests.abstracts.InputFile + +sealed interface CoveredTelegramMedia : TelegramMedia { + val cover: InputFile? +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaVideo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaVideo.kt index 8bfef8cdce..971e44b410 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaVideo.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaVideo.kt @@ -1,6 +1,8 @@ package dev.inmo.tgbotapi.types.media +import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.requests.abstracts.InputFile +import dev.inmo.tgbotapi.requests.abstracts.MultipartRequest import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList @@ -70,13 +72,23 @@ data class TelegramMediaVideo internal constructor ( private val rawEntities: List? = null, @SerialName(hasSpoilerField) override val spoilered: Boolean = false, + @SerialName(coverField) + override val cover: InputFile? = null, + @SerialName(startTimestampField) + override val startTimestamp: Seconds? = null, @SerialName(showCaptionAboveMediaField) override val showCaptionAboveMedia: Boolean = false, override val width: Int? = null, override val height: Int? = null, override val duration: Long? = null, override val thumb: InputFile? = null -) : TelegramFreeMedia, SizedTelegramMedia, DuratedTelegramMedia, ThumbedTelegramMedia, VisualMediaGroupMemberTelegramMedia { +) : TelegramFreeMedia, + SizedTelegramMedia, + DuratedTelegramMedia, + ThumbedTelegramMedia, + CoveredTelegramMedia, + WithCustomStartTelegramMedia, + VisualMediaGroupMemberTelegramMedia { override val type: String = videoTelegramMediaType override val textSources: TextSourcesList? by lazy { rawEntities ?.asTextSources(text ?: return@lazy null) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramPaidMediaVideo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramPaidMediaVideo.kt index 01c6f73a12..2feb1e9791 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramPaidMediaVideo.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramPaidMediaVideo.kt @@ -18,7 +18,16 @@ data class TelegramPaidMediaVideo ( override val duration: Long? = null, @SerialName(supportsStreamingField) val supportsStreaming: Boolean = false, -) : VisualTelegramPaidMedia, SizedTelegramMedia, DuratedTelegramMedia, ThumbedTelegramMedia { + @SerialName(coverField) + override val cover: InputFile? = null, + @SerialName(startTimestampField) + override val startTimestamp: Seconds? = null, +) : VisualTelegramPaidMedia, + SizedTelegramMedia, + DuratedTelegramMedia, + ThumbedTelegramMedia, + CoveredTelegramMedia, + WithCustomStartTelegramMedia { override val type: String = videoTelegramPaidMediaType @SerialName(mediaField) @@ -31,7 +40,9 @@ fun VideoFile.toTelegramPaidMediaVideo(): TelegramPaidMediaVideo = TelegramPaidM thumb = thumbnail ?.fileId, width = width, height = height, - duration = duration + duration = duration, + cover = cover ?.fileId, + startTimestamp = startTimestamp, ) fun PaidMedia.Video.toTelegramPaidMediaVideo(): TelegramPaidMediaVideo = video.toTelegramPaidMediaVideo() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/WithCustomStartTelegramMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/WithCustomStartTelegramMedia.kt new file mode 100644 index 0000000000..fbf4d981d7 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/WithCustomStartTelegramMedia.kt @@ -0,0 +1,6 @@ +package dev.inmo.tgbotapi.types.media + +import dev.inmo.tgbotapi.abstracts.WithCustomStartMediaData +import dev.inmo.tgbotapi.requests.abstracts.FileId + +sealed interface WithCustomStartTelegramMedia : TelegramMedia, WithCustomStartMediaData diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VideoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VideoContent.kt index efc4d75795..01c07ad848 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VideoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VideoContent.kt @@ -38,6 +38,8 @@ data class VideoContent( entities = textSources, showCaptionAboveMedia = showCaptionAboveMedia, spoilered = spoilered, + cover = media.cover ?.fileId, + startTimestamp = media.startTimestamp, duration = media.duration, width = media.width, height = media.height,