commonMain.dev.inmo.tgbotapi.extensions.api.DeleteMessages.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tgbotapi.api-jvm Show documentation
Show all versions of tgbotapi.api-jvm Show documentation
API extensions with "Telegram Bot API"-like extensions for TelegramBot and RequestsExecutor
package dev.inmo.tgbotapi.extensions.api
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
import kotlin.jvm.JvmName
suspend fun TelegramBot.deleteMessages(
chatId: ChatIdentifier,
messageIds: List
) = messageIds.chunked(deleteMessagesLimit.last).map {
execute(
DeleteMessages(
chatId = chatId,
messageIds = it
)
)
}.all { it }
suspend fun TelegramBot.deleteMessages(
chatId: ChatIdentifier,
messageIds: Array
) = deleteMessages(
chatId = chatId,
messageIds = messageIds.toList()
)
suspend fun TelegramBot.deleteMessages(
messagesMetas: List
) = messagesMetas.groupBy { it.chatId }.map { (chatId, messages) ->
deleteMessages(
chatId = chatId,
messageIds = messages.map { it.messageId }
)
}.all { it }
@JvmName("deleteMessagesWithMessages")
suspend fun TelegramBot.deleteMessages(
messages: List
) = deleteMessages(messages.map { it.metaInfo })
suspend fun TelegramBot.delete(
chatId: ChatIdentifier,
messageIds: List
) = deleteMessages(chatId = chatId, messageIds = messageIds)
suspend fun TelegramBot.delete(
chatId: ChatIdentifier,
messageIds: Array
) = deleteMessages(chatId = chatId, messageIds = messageIds)
suspend fun TelegramBot.delete(
messagesMetas: List
) = deleteMessages(messagesMetas)
@JvmName("deleteWithMessages")
suspend fun TelegramBot.delete(
messages: List
) = deleteMessages(messages)