add several verifications extensions

This commit is contained in:
InsanusMokrassar 2021-02-23 13:18:22 +06:00
parent 793bc1936b
commit 71f5bfc9f9

View File

@ -0,0 +1,22 @@
package dev.inmo.tgbotapi.libraries.cache.admins
import dev.inmo.tgbotapi.types.ChatId
import dev.inmo.tgbotapi.types.UserId
import dev.inmo.tgbotapi.types.message.abstracts.*
suspend fun AdminsCacheAPI.userIsAdmin(chatId: ChatId, userId: UserId) = this.isAdmin()
suspend fun AdminsCacheAPI.verifyMessageFromAdmin(message: ContentMessage<*>) = when (message) {
is CommonGroupContentMessage<*> -> isAdmin(message.user.id, message.chat.id)
is AnonymousGroupContentMessage<*> -> true
else -> false
}
suspend fun <R> ContentMessage<*>.doAfterVerification(adminsCacheAPI: AdminsCacheAPI, block: suspend () -> R): R? {
val verified = adminsCacheAPI.verifyMessageFromAdmin(this)
return if (verified) {
block()
} else {
null
}
}