From a76b7977b3da51de3ebd9f172f5432e065c24e1f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 10 Jan 2022 12:38:48 +0600 Subject: [PATCH 1/5] start 0.38.2 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ba52cd572..c76ac385c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.38.2 + ## 0.38.1 * `Core`: diff --git a/gradle.properties b/gradle.properties index 3bcc54326f..d9104d8d69 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,6 +18,6 @@ micro_utils_version=0.9.0 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.38.1 +library_version=0.38.2 github_release_plugin_version=2.2.12 From a615d1c4fd2b14fb33a1b5fb99ab1097b0f08d9e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 10 Jan 2022 13:06:18 +0600 Subject: [PATCH 2/5] copyMessages for media groups --- CHANGELOG.md | 3 + .../extensions/api/send/CopyMessages.kt | 177 ++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index c76ac385c8..a4819419a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.38.2 +* `API` + * New extensions `TelegramBot#copyMessages` for media groups + ## 0.38.1 * `Core`: diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt new file mode 100644 index 0000000000..88780f3ba2 --- /dev/null +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt @@ -0,0 +1,177 @@ +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.requests.send.CopyMessage +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.InputMedia.* +import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList +import dev.inmo.tgbotapi.types.MessageIdentifier +import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup +import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage +import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent +import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.MediaGroupUpdate +import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.SentMediaGroupUpdate + +/** + * Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements + * will be copied as they are + */ +suspend inline fun TelegramBot.copyMessages( + toChatId: ChatIdentifier, + messages: List>, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + protectContent: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null +): List> { + val first = messages.first().content.toMediaGroupMemberInputMedia().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) + } + } else { + it + } + } + + return sendMediaGroup( + toChatId, + listOf(first) + messages.drop(1).map { + it.content.toMediaGroupMemberInputMedia() + }, + disableNotification, + protectContent, + replyToMessageId, + allowSendingWithoutReply + ) +} + +/** + * Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements + * will be copied as they are + */ +suspend inline fun TelegramBot.copyMessages( + toChat: Chat, + messages: List>, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + protectContent: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null +) = copyMessages(toChat.id, messages, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply) + +/** + * Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements + * will be copied as they are + */ +suspend inline fun TelegramBot.copyMessages( + toChat: ChatIdentifier, + update: SentMediaGroupUpdate, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + protectContent: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null +) = copyMessages(toChat, update.data, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply) + +/** + * Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements + * will be copied as they are + */ +suspend inline fun TelegramBot.copyMessages( + toChat: Chat, + update: SentMediaGroupUpdate, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + protectContent: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null +) = copyMessages(toChat.id, update, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply) + +/** + * Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements + * will be copied as they are + */ +suspend inline fun TelegramBot.copyMessages( + toChatId: ChatIdentifier, + messages: List>, + entities: TextSourcesList, + disableNotification: Boolean = false, + protectContent: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null +): List> { + val first = messages.first().content.toMediaGroupMemberInputMedia().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) + } + } + + return sendMediaGroup( + toChatId, + listOf(first) + messages.drop(1).map { + it.content.toMediaGroupMemberInputMedia() + }, + disableNotification, + protectContent, + replyToMessageId, + allowSendingWithoutReply + ) +} + +/** + * Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements + * will be copied as they are + */ +suspend inline fun TelegramBot.copyMessages( + toChat: Chat, + messages: List>, + entities: TextSourcesList, + disableNotification: Boolean = false, + protectContent: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null +) = copyMessages(toChat.id, messages, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply) + +/** + * Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements + * will be copied as they are + */ +suspend inline fun TelegramBot.copyMessages( + toChat: ChatIdentifier, + update: SentMediaGroupUpdate, + entities: TextSourcesList, + disableNotification: Boolean = false, + protectContent: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null +) = copyMessages(toChat, update.data, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply) + +/** + * Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements + * will be copied as they are + */ +suspend inline fun TelegramBot.copyMessages( + toChat: Chat, + update: SentMediaGroupUpdate, + entities: TextSourcesList, + disableNotification: Boolean = false, + protectContent: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null +) = copyMessages(toChat.id, update, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply) From 24bffbbd979c0f5d43d6b950d5e13d3d996289e6 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 10 Jan 2022 13:15:10 +0600 Subject: [PATCH 3/5] addopportunity to copy messages using just content --- .../extensions/api/send/CopyMessages.kt | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt index 88780f3ba2..8ac014069c 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt @@ -22,7 +22,7 @@ import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.SentMediaGroupUpdate */ suspend inline fun TelegramBot.copyMessages( toChatId: ChatIdentifier, - messages: List>, + messages: List, text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, @@ -30,7 +30,7 @@ suspend inline fun TelegramBot.copyMessages( replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null ): List> { - val first = messages.first().content.toMediaGroupMemberInputMedia().let { + val first = messages.first().toMediaGroupMemberInputMedia().let { if (text != null) { when (it) { is InputMediaAudio -> it.copy(text = text, parseMode = parseMode) @@ -46,7 +46,7 @@ suspend inline fun TelegramBot.copyMessages( return sendMediaGroup( toChatId, listOf(first) + messages.drop(1).map { - it.content.toMediaGroupMemberInputMedia() + it.toMediaGroupMemberInputMedia() }, disableNotification, protectContent, @@ -55,6 +55,21 @@ suspend inline fun TelegramBot.copyMessages( ) } +/** + * Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements + * will be copied as they are + */ +suspend inline fun TelegramBot.copyMessages( + toChatId: ChatIdentifier, + messages: List>, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + protectContent: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null +) = copyMessages(toChatId, messages.map { it.content }, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply) + /** * Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements * will be copied as they are @@ -106,14 +121,14 @@ suspend inline fun TelegramBot.copyMessages( */ suspend inline fun TelegramBot.copyMessages( toChatId: ChatIdentifier, - messages: List>, + messages: List, entities: TextSourcesList, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null ): List> { - val first = messages.first().content.toMediaGroupMemberInputMedia().let { + val first = messages.first().toMediaGroupMemberInputMedia().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) @@ -125,7 +140,7 @@ suspend inline fun TelegramBot.copyMessages( return sendMediaGroup( toChatId, listOf(first) + messages.drop(1).map { - it.content.toMediaGroupMemberInputMedia() + it.toMediaGroupMemberInputMedia() }, disableNotification, protectContent, @@ -134,6 +149,20 @@ suspend inline fun TelegramBot.copyMessages( ) } +/** + * Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements + * will be copied as they are + */ +suspend inline fun TelegramBot.copyMessages( + toChatId: ChatIdentifier, + messages: List>, + entities: TextSourcesList, + disableNotification: Boolean = false, + protectContent: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null +) = copyMessages(toChatId, messages.map { it.content }, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply) + /** * Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements * will be copied as they are From 0c0ec22348554fe97d60998e2bf86de39d62de32 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 10 Jan 2022 13:16:50 +0600 Subject: [PATCH 4/5] update microutils dependency --- CHANGELOG.md | 3 +++ gradle.properties | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4819419a3..98d03acee3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.38.2 +* `Common`: + * `Version`: + * `MicroUtils`: `0.9.0` -> `0.9.1` * `API` * New extensions `TelegramBot#copyMessages` for media groups diff --git a/gradle.properties b/gradle.properties index d9104d8d69..6b1f41d6d1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ uuid_version=0.3.1 ktor_version=1.6.7 -micro_utils_version=0.9.0 +micro_utils_version=0.9.1 javax_activation_version=1.1.1 From 33c8ee0803e080edc29c49bced964766ed56be66 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 10 Jan 2022 13:48:00 +0600 Subject: [PATCH 5/5] remove redundant copyMessage --- .../extensions/api/send/CopyMessages.kt | 41 +++---------------- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt index 8ac014069c..88780f3ba2 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt @@ -22,7 +22,7 @@ import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.SentMediaGroupUpdate */ suspend inline fun TelegramBot.copyMessages( toChatId: ChatIdentifier, - messages: List, + messages: List>, text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, @@ -30,7 +30,7 @@ suspend inline fun TelegramBot.copyMessages( replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null ): List> { - val first = messages.first().toMediaGroupMemberInputMedia().let { + val first = messages.first().content.toMediaGroupMemberInputMedia().let { if (text != null) { when (it) { is InputMediaAudio -> it.copy(text = text, parseMode = parseMode) @@ -46,7 +46,7 @@ suspend inline fun TelegramBot.copyMessages( return sendMediaGroup( toChatId, listOf(first) + messages.drop(1).map { - it.toMediaGroupMemberInputMedia() + it.content.toMediaGroupMemberInputMedia() }, disableNotification, protectContent, @@ -55,21 +55,6 @@ suspend inline fun TelegramBot.copyMessages( ) } -/** - * Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements - * will be copied as they are - */ -suspend inline fun TelegramBot.copyMessages( - toChatId: ChatIdentifier, - messages: List>, - text: String? = null, - parseMode: ParseMode? = null, - disableNotification: Boolean = false, - protectContent: Boolean = false, - replyToMessageId: MessageIdentifier? = null, - allowSendingWithoutReply: Boolean? = null -) = copyMessages(toChatId, messages.map { it.content }, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply) - /** * Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements * will be copied as they are @@ -121,14 +106,14 @@ suspend inline fun TelegramBot.copyMessages( */ suspend inline fun TelegramBot.copyMessages( toChatId: ChatIdentifier, - messages: List, + messages: List>, entities: TextSourcesList, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null ): List> { - val first = messages.first().toMediaGroupMemberInputMedia().let { + val first = messages.first().content.toMediaGroupMemberInputMedia().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) @@ -140,7 +125,7 @@ suspend inline fun TelegramBot.copyMessages( return sendMediaGroup( toChatId, listOf(first) + messages.drop(1).map { - it.toMediaGroupMemberInputMedia() + it.content.toMediaGroupMemberInputMedia() }, disableNotification, protectContent, @@ -149,20 +134,6 @@ suspend inline fun TelegramBot.copyMessages( ) } -/** - * Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements - * will be copied as they are - */ -suspend inline fun TelegramBot.copyMessages( - toChatId: ChatIdentifier, - messages: List>, - entities: TextSourcesList, - disableNotification: Boolean = false, - protectContent: Boolean = false, - replyToMessageId: MessageIdentifier? = null, - allowSendingWithoutReply: Boolean? = null -) = copyMessages(toChatId, messages.map { it.content }, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply) - /** * Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements * will be copied as they are