mirror of
https://github.com/InsanusMokrassar/TelegramBotApiLibraries.git
synced 2024-11-18 22:33:51 +00:00
add method to AdminsCacheAPI
This commit is contained in:
parent
06d5cb904b
commit
b76a574929
@ -1,13 +1,20 @@
|
|||||||
package dev.inmo.tgbotapi.libraries.cache.admins
|
package dev.inmo.tgbotapi.libraries.cache.admins
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.asGroupContentMessage
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.AdministratorChatMember
|
import dev.inmo.tgbotapi.types.ChatMember.abstracts.AdministratorChatMember
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.GroupContentMessage
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||||
|
|
||||||
interface AdminsCacheAPI {
|
interface AdminsCacheAPI {
|
||||||
suspend fun getChatAdmins(chatId: ChatId): List<AdministratorChatMember>?
|
suspend fun getChatAdmins(chatId: ChatId): List<AdministratorChatMember>?
|
||||||
suspend fun isAdmin(chatId: ChatId, userId: UserId): Boolean = getChatAdmins(chatId) ?.any {
|
suspend fun isAdmin(chatId: ChatId, userId: UserId): Boolean = getChatAdmins(chatId) ?.any {
|
||||||
it.user.id == userId
|
it.user.id == userId
|
||||||
} == true
|
} == true
|
||||||
|
suspend fun sentByAdmin(groupContentMessage: GroupContentMessage<*>): Boolean
|
||||||
|
suspend fun sentByAdmin(message: Message): Boolean? {
|
||||||
|
return sentByAdmin(message.asGroupContentMessage() ?: return null)
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun settings(): AdminsCacheSettingsAPI
|
suspend fun settings(): AdminsCacheSettingsAPI
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
|||||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChatAdministrators
|
import dev.inmo.tgbotapi.extensions.api.chat.get.getChatAdministrators
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.AdministratorChatMember
|
import dev.inmo.tgbotapi.types.ChatMember.abstracts.AdministratorChatMember
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
interface DefaultAdminsCacheAPIRepo {
|
interface DefaultAdminsCacheAPIRepo {
|
||||||
@ -49,6 +50,17 @@ class DefaultAdminsCacheAPI(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun sentByAdmin(groupContentMessage: GroupContentMessage<*>): Boolean {
|
||||||
|
return when (groupContentMessage) {
|
||||||
|
is AnonymousGroupContentMessage -> true
|
||||||
|
is CommonGroupContentMessage -> isAdmin(
|
||||||
|
groupContentMessage.chat.id,
|
||||||
|
groupContentMessage.user.id
|
||||||
|
)
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun settings(): AdminsCacheSettingsAPI = settingsAPI
|
override suspend fun settings(): AdminsCacheSettingsAPI = settingsAPI
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user