mirror of
https://github.com/InsanusMokrassar/TelegramBotApiLibraries.git
synced 2024-11-18 14:23:52 +00:00
add filter for bot itself in getting of administrators
This commit is contained in:
parent
e6bd25dc30
commit
b13a1e29bf
@ -2,10 +2,10 @@ package dev.inmo.tgbotapi.libraries.cache.admins
|
|||||||
|
|
||||||
import com.soywiz.klock.DateTime
|
import com.soywiz.klock.DateTime
|
||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
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.ChatId
|
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.UserId
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
interface DefaultAdminsCacheAPIRepo {
|
interface DefaultAdminsCacheAPIRepo {
|
||||||
@ -20,8 +20,18 @@ class DefaultAdminsCacheAPI(
|
|||||||
private val repo: DefaultAdminsCacheAPIRepo,
|
private val repo: DefaultAdminsCacheAPIRepo,
|
||||||
private val settingsAPI: AdminsCacheSettingsAPI
|
private val settingsAPI: AdminsCacheSettingsAPI
|
||||||
) : AdminsCacheAPI {
|
) : AdminsCacheAPI {
|
||||||
|
private lateinit var botInfo: ExtendedBot
|
||||||
|
private suspend fun getBotInfo(): ExtendedBot = try {
|
||||||
|
botInfo
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
bot.getMe().also { botInfo = it }
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun triggerUpdate(chatId: ChatId): List<AdministratorChatMember> {
|
private suspend fun triggerUpdate(chatId: ChatId): List<AdministratorChatMember> {
|
||||||
val admins = bot.getChatAdministrators(chatId)
|
val botInfo = getBotInfo()
|
||||||
|
val admins = bot.getChatAdministrators(chatId).filter {
|
||||||
|
botInfo.id != it.user.id
|
||||||
|
}
|
||||||
repo.setChatAdmins(chatId, admins)
|
repo.setChatAdmins(chatId, admins)
|
||||||
return admins
|
return admins
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user