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

commonMain.dev.inmo.tgbotapi.libraries.cache.admins.MessageSenderVerification.kt Maven / Gradle / Ivy

There is a newer version: 0.26.1
Show newest version
package dev.inmo.tgbotapi.libraries.cache.admins

import dev.inmo.tgbotapi.types.IdChatIdentifier
import dev.inmo.tgbotapi.types.UserId
import dev.inmo.tgbotapi.types.message.abstracts.*

suspend inline fun AdminsCacheAPI.isAdmin(message: Message) = when (message) {
    is CommonGroupContentMessage<*> -> isAdmin(message.chat.id, message.user.id)
    is AnonymousGroupContentMessage<*> -> true
    else -> false
}

suspend inline fun AdminsCacheAPI.verifyMessageFromAdmin(message: Message) = isAdmin(message)

suspend inline fun  AdminsCacheAPI.doIfAdmin(
    chatId: IdChatIdentifier,
    userId: UserId,
    block: () -> R
) = if(isAdmin(chatId, userId)) {
    block()
} else {
    null
}

suspend inline fun  AdminsCacheAPI.doIfAdmin(
    message: Message,
    block: () -> R
) = if(isAdmin(message)) {
    block()
} else {
    null
}

suspend inline fun  ContentMessage<*>.doIfAdmin(adminsCacheAPI: AdminsCacheAPI, block: () -> R): R? {
    val verified = adminsCacheAPI.isAdmin(this)
    return if (verified) {
        block()
    } else {
        null
    }
}

suspend inline fun  ContentMessage<*>.doAfterVerification(adminsCacheAPI: AdminsCacheAPI, block: () -> R) = doIfAdmin(adminsCacheAPI, block)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy