mirror of
https://github.com/InsanusMokrassar/TelegramBotApiLibraries.git
synced 2024-12-22 16:47:16 +00:00
refactor isAdmin
This commit is contained in:
parent
71f5bfc9f9
commit
3026f8d1f6
@ -5,7 +5,9 @@ import dev.inmo.tgbotapi.types.ChatMember.abstracts.AdministratorChatMember
|
||||
|
||||
interface AdminsCacheAPI {
|
||||
suspend fun getChatAdmins(chatId: ChatId): List<AdministratorChatMember>?
|
||||
suspend fun isAdmin(userId: UserId, chatId: ChatId): Boolean
|
||||
suspend fun isAdmin(chatId: ChatId, userId: UserId): Boolean = getChatAdmins(chatId) ?.any {
|
||||
it.user.id == userId
|
||||
} == true
|
||||
|
||||
suspend fun settings(): AdminsCacheSettingsAPI
|
||||
}
|
||||
|
@ -39,10 +39,6 @@ class DefaultAdminsCacheAPI(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun isAdmin(userId: UserId, chatId: ChatId): Boolean = getChatAdmins(chatId) ?.any {
|
||||
it.user.id == userId
|
||||
} == true
|
||||
|
||||
override suspend fun settings(): AdminsCacheSettingsAPI = settingsAPI
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ 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 CommonGroupContentMessage<*> -> isAdmin(message.chat.id, message.user.id)
|
||||
is AnonymousGroupContentMessage<*> -> true
|
||||
else -> false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user