mirror of
https://github.com/InsanusMokrassar/TelegramBotApiLibraries.git
synced 2024-12-24 01:27:17 +00:00
add several verifications extensions
This commit is contained in:
parent
793bc1936b
commit
71f5bfc9f9
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user