mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
imrovements in copy/delete/forward messages
This commit is contained in:
parent
0f5bce592b
commit
9425380002
@ -4,6 +4,7 @@ import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.requests.DeleteMessages
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
|
||||
suspend fun TelegramBot.deleteMessages(
|
||||
chatId: ChatIdentifier,
|
||||
@ -35,14 +36,18 @@ suspend fun TelegramBot.deleteMessages(
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.deleteMessages(
|
||||
messages: List<AccessibleMessage>
|
||||
) = messages.groupBy { it.chat }.map { (chat, messages) ->
|
||||
messagesMetas: List<Message.MetaInfo>
|
||||
) = messagesMetas.groupBy { it.chatId }.map { (chatId, messages) ->
|
||||
deleteMessages(
|
||||
chatId = chat.id,
|
||||
chatId = chatId,
|
||||
messageIds = messages.map { it.messageId }
|
||||
)
|
||||
}.all { it }
|
||||
|
||||
suspend fun TelegramBot.deleteMessages(
|
||||
messages: List<AccessibleMessage>
|
||||
) = deleteMessages(messages.map { it.metaInfo })
|
||||
|
||||
suspend fun TelegramBot.delete(
|
||||
chatId: ChatIdentifier,
|
||||
messageIds: List<MessageId>
|
||||
@ -60,6 +65,11 @@ suspend fun TelegramBot.delete(
|
||||
vararg messageIds: MessageId
|
||||
) = deleteMessages(chatId = chatId, messageIds = (listOf(firstMessageId, secondMessageId) + messageIds.toList()))
|
||||
|
||||
|
||||
suspend fun TelegramBot.delete(
|
||||
messagesMetas: List<Message.MetaInfo>
|
||||
) = deleteMessages(messagesMetas)
|
||||
|
||||
suspend fun TelegramBot.delete(
|
||||
messages: List<AccessibleMessage>
|
||||
) = deleteMessages(messages)
|
||||
|
@ -1,9 +1,11 @@
|
||||
package dev.inmo.tgbotapi.extensions.api
|
||||
|
||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.extensions.api.send.copyMessages
|
||||
import dev.inmo.tgbotapi.requests.ForwardMessages
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
|
||||
suspend fun TelegramBot.forwardMessages(
|
||||
toChatId: ChatIdentifier,
|
||||
@ -66,15 +68,15 @@ suspend fun TelegramBot.forwardMessages(
|
||||
|
||||
suspend fun TelegramBot.forwardMessages(
|
||||
toChatId: ChatIdentifier,
|
||||
messages: List<AccessibleMessage>,
|
||||
messagesMetas: List<Message.MetaInfo>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = messages.groupBy { it.chat }.flatMap { (chat, messages) ->
|
||||
) = messagesMetas.groupBy { it.chatId }.flatMap { (chatId, messages) ->
|
||||
forwardMessages(
|
||||
toChatId = toChatId,
|
||||
fromChatId = chat.id,
|
||||
fromChatId = chatId,
|
||||
messageIds = messages.map { it.messageId },
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
@ -83,6 +85,22 @@ suspend fun TelegramBot.forwardMessages(
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun TelegramBot.forwardMessages(
|
||||
toChatId: ChatIdentifier,
|
||||
messages: List<AccessibleMessage>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = forwardMessages(
|
||||
toChatId = toChatId,
|
||||
messagesMetas = messages.map { it.metaInfo },
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.forward(
|
||||
toChatId: ChatIdentifier,
|
||||
fromChatId: ChatIdentifier,
|
||||
@ -139,6 +157,22 @@ suspend fun TelegramBot.forward(
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.forward(
|
||||
toChatId: ChatIdentifier,
|
||||
messagesMetas: List<Message.MetaInfo>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = forwardMessages(
|
||||
toChatId = toChatId,
|
||||
messagesMetas = messagesMetas,
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.forward(
|
||||
toChatId: ChatIdentifier,
|
||||
messages: List<AccessibleMessage>,
|
||||
|
@ -4,6 +4,7 @@ import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.requests.send.CopyMessages
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
|
||||
suspend fun TelegramBot.copyMessages(
|
||||
toChatId: ChatIdentifier,
|
||||
@ -66,15 +67,15 @@ suspend fun TelegramBot.copyMessages(
|
||||
|
||||
suspend fun TelegramBot.copyMessages(
|
||||
toChatId: ChatIdentifier,
|
||||
messages: List<AccessibleMessage>,
|
||||
messagesMetas: List<Message.MetaInfo>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = messages.groupBy { it.chat }.flatMap { (chat, messages) ->
|
||||
) = messagesMetas.groupBy { it.chatId }.flatMap { (chatId, messages) ->
|
||||
copyMessages(
|
||||
toChatId = toChatId,
|
||||
fromChatId = chat.id,
|
||||
fromChatId = chatId,
|
||||
messageIds = messages.map { it.messageId },
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
@ -82,3 +83,107 @@ suspend fun TelegramBot.copyMessages(
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun TelegramBot.copyMessages(
|
||||
toChatId: ChatIdentifier,
|
||||
messages: List<AccessibleMessage>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = copyMessages(
|
||||
toChatId = toChatId,
|
||||
messagesMetas = messages.map { it.metaInfo },
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.copy(
|
||||
toChatId: ChatIdentifier,
|
||||
fromChatId: ChatIdentifier,
|
||||
messageIds: List<MessageId>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = copyMessages(
|
||||
toChatId = toChatId,
|
||||
fromChatId = fromChatId,
|
||||
messageIds = messageIds,
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.copy(
|
||||
toChatId: ChatIdentifier,
|
||||
fromChatId: ChatIdentifier,
|
||||
messageIds: Array<MessageId>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = copyMessages(
|
||||
toChatId = toChatId,
|
||||
fromChatId = fromChatId,
|
||||
messageIds = messageIds,
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.copy(
|
||||
toChatId: ChatIdentifier,
|
||||
fromChatId: ChatIdentifier,
|
||||
firstMessageId: MessageId,
|
||||
vararg messageIds: MessageId,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = copyMessages(
|
||||
toChatId = toChatId,
|
||||
fromChatId = fromChatId,
|
||||
firstMessageId = firstMessageId,
|
||||
messageIds = messageIds,
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.copy(
|
||||
toChatId: ChatIdentifier,
|
||||
messagesMetas: List<Message.MetaInfo>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = copyMessages(
|
||||
toChatId = toChatId,
|
||||
messagesMetas = messagesMetas,
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.copy(
|
||||
toChatId: ChatIdentifier,
|
||||
messages: List<AccessibleMessage>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = copyMessages(
|
||||
toChatId = toChatId,
|
||||
messages = messages,
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user