All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.dev.inmo.tgbotapi.extensions.api.DeleteMessage.kt Maven / Gradle / Ivy

Go to download

API extensions with "Telegram Bot API"-like extensions for TelegramBot and RequestsExecutor

There is a newer version: 20.0.1
Show newest version
package dev.inmo.tgbotapi.extensions.api

import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.DeleteMessage
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.chat.Chat
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import dev.inmo.tgbotapi.types.message.content.MediaGroupCollectionContent

suspend fun TelegramBot.deleteMessage(
    chatId: ChatIdentifier,
    messageId: MessageId
) = execute(
    DeleteMessage(chatId, messageId)
)

suspend fun TelegramBot.deleteMessage(
    chat: Chat,
    messageId: MessageId
) = deleteMessage(chat.id, messageId)

suspend fun TelegramBot.deleteMessage(
    message: AccessibleMessage
): Boolean {
    val mediaGroupContent = ((message as? ContentMessage<*>) ?.content as? MediaGroupCollectionContent<*>)
    if (mediaGroupContent == null) {
        return deleteMessage(message.chat, message.messageId)
    } else {
        return mediaGroupContent.group.map {
            deleteMessage(it.sourceMessage)
        }.all { it }
    }
}

suspend fun TelegramBot.delete(
    chatId: ChatIdentifier,
    messageId: MessageId
) = deleteMessage(chatId, messageId)

suspend fun TelegramBot.delete(
    chat: Chat,
    messageId: MessageId
) = deleteMessage(chat, messageId)

suspend fun TelegramBot.delete(
    message: AccessibleMessage
) = deleteMessage(message)

suspend fun AccessibleMessage.delete(
    requestsExecutor: TelegramBot
) = requestsExecutor.deleteMessage(this)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy