1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-23 09:07:12 +00:00

remove redundant copyMessage

This commit is contained in:
InsanusMokrassar 2022-01-10 13:48:00 +06:00
parent 0c0ec22348
commit 33c8ee0803

View File

@ -22,7 +22,7 @@ import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.SentMediaGroupUpdate
*/ */
suspend inline fun TelegramBot.copyMessages( suspend inline fun TelegramBot.copyMessages(
toChatId: ChatIdentifier, toChatId: ChatIdentifier,
messages: List<MediaGroupContent>, messages: List<MediaGroupMessage<MediaGroupContent>>,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
@ -30,7 +30,7 @@ suspend inline fun TelegramBot.copyMessages(
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null allowSendingWithoutReply: Boolean? = null
): List<MediaGroupMessage<MediaGroupContent>> { ): List<MediaGroupMessage<MediaGroupContent>> {
val first = messages.first().toMediaGroupMemberInputMedia().let { val first = messages.first().content.toMediaGroupMemberInputMedia().let {
if (text != null) { if (text != null) {
when (it) { when (it) {
is InputMediaAudio -> it.copy(text = text, parseMode = parseMode) is InputMediaAudio -> it.copy(text = text, parseMode = parseMode)
@ -46,7 +46,7 @@ suspend inline fun TelegramBot.copyMessages(
return sendMediaGroup( return sendMediaGroup(
toChatId, toChatId,
listOf(first) + messages.drop(1).map { listOf(first) + messages.drop(1).map {
it.toMediaGroupMemberInputMedia() it.content.toMediaGroupMemberInputMedia()
}, },
disableNotification, disableNotification,
protectContent, 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<MediaGroupMessage<MediaGroupContent>>,
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 * Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements
* will be copied as they are * will be copied as they are
@ -121,14 +106,14 @@ suspend inline fun TelegramBot.copyMessages(
*/ */
suspend inline fun TelegramBot.copyMessages( suspend inline fun TelegramBot.copyMessages(
toChatId: ChatIdentifier, toChatId: ChatIdentifier,
messages: List<MediaGroupContent>, messages: List<MediaGroupMessage<MediaGroupContent>>,
entities: TextSourcesList, entities: TextSourcesList,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null allowSendingWithoutReply: Boolean? = null
): List<MediaGroupMessage<MediaGroupContent>> { ): List<MediaGroupMessage<MediaGroupContent>> {
val first = messages.first().toMediaGroupMemberInputMedia().let { val first = messages.first().content.toMediaGroupMemberInputMedia().let {
when (it) { when (it) {
is InputMediaAudio -> InputMediaAudio(it.file, entities, it.duration, it.performer, it.title, it.thumb) 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 InputMediaDocument -> InputMediaDocument(it.file, entities, it.thumb, it.disableContentTypeDetection)
@ -140,7 +125,7 @@ suspend inline fun TelegramBot.copyMessages(
return sendMediaGroup( return sendMediaGroup(
toChatId, toChatId,
listOf(first) + messages.drop(1).map { listOf(first) + messages.drop(1).map {
it.toMediaGroupMemberInputMedia() it.content.toMediaGroupMemberInputMedia()
}, },
disableNotification, disableNotification,
protectContent, 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<MediaGroupMessage<MediaGroupContent>>,
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 * Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements
* will be copied as they are * will be copied as they are