From 8d27349868ea48399358d78a73c9c5654b2ab538 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 9 Feb 2021 18:26:10 +0600 Subject: [PATCH] update content resends and different other things --- .../types/InputMedia/InputMediaAudio.kt | 12 +++++++ .../types/InputMedia/InputMediaDocument.kt | 8 +++++ .../types/InputMedia/InputMediaPhoto.kt | 7 ++++ .../tgbotapi/types/ParseMode/ParseMode.kt | 5 +-- .../inmo/tgbotapi/types/files/VideoFile.kt | 13 ++++++++ .../types/message/content/TextContent.kt | 33 +++++++------------ .../message/content/media/AnimationContent.kt | 13 ++------ .../message/content/media/AudioContent.kt | 11 ++----- .../message/content/media/DocumentContent.kt | 13 ++------ .../message/content/media/PhotoContent.kt | 11 ++----- .../message/content/media/VideoContent.kt | 11 ++----- .../message/content/media/VoiceContent.kt | 13 ++------ 12 files changed, 72 insertions(+), 78 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt index 01d416f485..5dc1aba16f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt @@ -74,3 +74,15 @@ fun AudioFile.toInputMediaAudio( title, thumb ?.fileId ) + +fun AudioFile.toInputMediaAudio( + textSources: TextSourcesList = emptyList(), + title: String? = this.title +): InputMediaAudio = InputMediaAudio( + fileId, + textSources, + duration, + performer, + title, + thumb ?.fileId +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt index a448046867..94e5af6b31 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt @@ -70,3 +70,11 @@ fun DocumentFile.toInputMediaDocument( parseMode, thumb ?.fileId ) + +fun DocumentFile.toInputMediaDocument( + textSources: TextSourcesList = emptyList() +) = InputMediaDocument( + fileId, + textSources, + thumb ?.fileId +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt index 345d60b117..05ba4fb671 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt @@ -53,3 +53,10 @@ fun PhotoSize.toInputMediaPhoto( caption, parseMode ) + +fun PhotoSize.toInputMediaPhoto( + textSources: TextSourcesList = emptyList() +): InputMediaPhoto = InputMediaPhoto( + fileId, + textSources +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ParseMode/ParseMode.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ParseMode/ParseMode.kt index 8cd2f094d1..af48b4dbee 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ParseMode/ParseMode.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ParseMode/ParseMode.kt @@ -39,8 +39,9 @@ typealias HTML = HTMLParseMode internal object ParseModeSerializerObject : KSerializer { override fun deserialize(decoder: Decoder): ParseMode { return when (decoder.decodeString()) { - MarkdownParseMode.parseModeName -> MarkdownParseMode - HTMLParseMode.parseModeName -> HTMLParseMode + Markdown.parseModeName -> Markdown + MarkdownV2.parseModeName -> MarkdownV2 + HTML.parseModeName -> HTML else -> throw IllegalArgumentException("Unknown parse mode") } } 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 eebd6ea018..45b4525896 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 @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.files +import dev.inmo.tgbotapi.CommonAbstracts.TextSourcesList import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InputMedia.InputMediaVideo @@ -44,3 +45,15 @@ inline fun VideoFile.toInputMediaVideo( duration, thumb ?.fileId ) + +@Suppress("NOTHING_TO_INLINE") +inline fun VideoFile.toInputMediaVideo( + textSources: TextSourcesList +) = InputMediaVideo( + fileId, + textSources, + width, + height, + duration, + thumb ?.fileId +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt index 83a5488e46..ff94ffb84e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt @@ -1,16 +1,15 @@ package dev.inmo.tgbotapi.types.message.content -import dev.inmo.tgbotapi.CommonAbstracts.TextPart -import dev.inmo.tgbotapi.CommonAbstracts.TextedInput +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.SendTextMessage import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.MessageIdentifier -import dev.inmo.tgbotapi.types.ParseMode.* +import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode +import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent -import dev.inmo.tgbotapi.utils.internal.* data class TextContent( override val text: String, @@ -24,8 +23,7 @@ data class TextContent( replyMarkup: KeyboardMarkup? ): Request> = SendTextMessage( chatId, - toHtmlTexts().first(), - HTMLParseMode, + textSources, false, disableNotification, replyToMessageId, @@ -48,6 +46,10 @@ data class TextContent( HTMLParseMode ) + @Deprecated( + "Useless due to fact that createResend currently use textSource and that will guarantee correct sending of message", + ReplaceWith("createResend") + ) fun createResends( chatId: ChatIdentifier, disableNotification: Boolean, @@ -55,20 +57,7 @@ data class TextContent( allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup?, parseMode: ParseMode = HTMLParseMode - ): List>> = when (parseMode) { - is MarkdownParseMode -> toMarkdownTexts() - is MarkdownV2ParseMode -> toMarkdownV2Texts() - is HTMLParseMode -> toHtmlTexts() - }.map { - SendTextMessage( - chatId, - it, - parseMode, - false, - disableNotification, - replyToMessageId, - allowSendingWithoutReply, - replyMarkup - ) - } + ): List>> = listOf( + createResend(chatId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + ) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt index f0cf652083..edbcb2312b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt @@ -1,21 +1,16 @@ package dev.inmo.tgbotapi.types.message.content.media -import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* 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.MessageIdentifier -import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode -import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2 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 dev.inmo.tgbotapi.utils.internal.toHtmlCaptions -import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Captions data class AnimationContent( override val media: AnimationFile, @@ -33,8 +28,7 @@ data class AnimationContent( chatId, media.fileId, media.thumb ?.fileId, - toHtmlCaptions().firstOrNull(), - HTMLParseMode, + textSources, media.duration, media.width, media.height, @@ -46,8 +40,7 @@ data class AnimationContent( override fun asInputMedia(): InputMediaAnimation = InputMediaAnimation( media.fileId, - toMarkdownV2Captions().firstOrNull(), - MarkdownV2, + textSources, media.width, media.height, media.duration, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt index b326522b96..2d4f9a7148 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt @@ -1,18 +1,17 @@ package dev.inmo.tgbotapi.types.message.content.media import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.textSources 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.MessageIdentifier -import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.AudioFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.AudioMediaGroupContent -import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions data class AudioContent( override val media: AudioFile, @@ -29,8 +28,7 @@ data class AudioContent( chatId, media.fileId, media.thumb ?.fileId, - toHtmlCaptions().firstOrNull(), - HTMLParseMode, + textSources, media.duration, media.performer, media.title, @@ -42,8 +40,5 @@ data class AudioContent( override fun toMediaGroupMemberInputMedia(): InputMediaAudio = asInputMedia() - override fun asInputMedia(): InputMediaAudio = media.toInputMediaAudio( - toHtmlCaptions().firstOrNull(), - HTMLParseMode - ) + override fun asInputMedia(): InputMediaAudio = media.toInputMediaAudio(textSources) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt index 8ff70ac761..747cc77fdb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt @@ -1,21 +1,18 @@ package dev.inmo.tgbotapi.types.message.content.media -import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* 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.MessageIdentifier -import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.DocumentFile import dev.inmo.tgbotapi.types.files.asDocumentFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.DocumentMediaGroupContent import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent -import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions data class DocumentContent( override val media: DocumentFile, @@ -32,8 +29,7 @@ data class DocumentContent( chatId, media.fileId, media.thumb ?.fileId, - toHtmlCaptions().firstOrNull(), - HTMLParseMode, + textSources, disableNotification, replyToMessageId, allowSendingWithoutReply, @@ -42,10 +38,7 @@ data class DocumentContent( override fun toMediaGroupMemberInputMedia(): InputMediaDocument = asInputMedia() - override fun asInputMedia(): InputMediaDocument = media.toInputMediaDocument( - toHtmlCaptions().firstOrNull(), - HTMLParseMode - ) + override fun asInputMedia(): InputMediaDocument = media.toInputMediaDocument(textSources) } @Suppress("NOTHING_TO_INLINE") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt index 9a7ceabb4c..27fc6102fa 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt @@ -1,19 +1,18 @@ package dev.inmo.tgbotapi.types.message.content.media import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.textSources 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.MessageIdentifier -import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MediaCollectionContent import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent -import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions data class PhotoContent( override val mediaCollection: Photo, @@ -31,8 +30,7 @@ data class PhotoContent( ): Request> = SendPhoto( chatId, media.fileId, - toHtmlCaptions().firstOrNull(), - HTMLParseMode, + textSources, disableNotification, replyToMessageId, allowSendingWithoutReply, @@ -41,8 +39,5 @@ data class PhotoContent( override fun toMediaGroupMemberInputMedia(): InputMediaPhoto = asInputMedia() - override fun asInputMedia(): InputMediaPhoto = media.toInputMediaPhoto( - toHtmlCaptions().firstOrNull(), - HTMLParseMode - ) + override fun asInputMedia(): InputMediaPhoto = media.toInputMediaPhoto(textSources) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt index aa5b4185bb..5b1ec9197b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt @@ -1,18 +1,17 @@ package dev.inmo.tgbotapi.types.message.content.media import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.textSources 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.MessageIdentifier -import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode 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.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent -import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions data class VideoContent( override val media: VideoFile, @@ -29,8 +28,7 @@ data class VideoContent( chatId, media.fileId, media.thumb ?.fileId, - toHtmlCaptions().firstOrNull(), - HTMLParseMode, + textSources, media.duration, media.width, media.height, @@ -43,8 +41,5 @@ data class VideoContent( override fun toMediaGroupMemberInputMedia(): InputMediaVideo = asInputMedia() - override fun asInputMedia(): InputMediaVideo = media.toInputMediaVideo( - toHtmlCaptions().firstOrNull(), - HTMLParseMode - ) + override fun asInputMedia(): InputMediaVideo = media.toInputMediaVideo(textSources) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt index 6a9894444f..421f2b6a75 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt @@ -1,20 +1,15 @@ package dev.inmo.tgbotapi.types.message.content.media -import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* 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.MessageIdentifier -import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode -import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2 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 dev.inmo.tgbotapi.utils.internal.toHtmlCaptions -import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Captions data class VoiceContent( override val media: VoiceFile, @@ -30,8 +25,7 @@ data class VoiceContent( ): Request> = SendVoice( chatId, media.fileId, - toHtmlCaptions().firstOrNull(), - HTMLParseMode, + textSources, media.duration, disableNotification, replyToMessageId, @@ -41,8 +35,7 @@ data class VoiceContent( override fun asInputMedia(): InputMediaAudio = InputMediaAudio( media.fileId, - toMarkdownV2Captions().firstOrNull(), - MarkdownV2, + textSources, media.duration ) }