All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.dev.inmo.tgbotapi.libraries.cache.admins.TriggerAdminsUpdate.kt Maven / Gradle / Ivy

The newest version!
package dev.inmo.tgbotapi.libraries.cache.admins

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.types.IdChatIdentifier
import dev.inmo.tgbotapi.types.chat.ExtendedBot
import dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember

internal suspend fun TelegramBot.updateAdmins(
    chatId: IdChatIdentifier,
    repo: DefaultAdminsCacheAPIRepo,
    botInfo: ExtendedBot? = null
): List {
    val botInfo = botInfo ?: getMe()
    val admins = getChatAdministrators(chatId).filter {
        botInfo.id != it.user.id
    }
    repo.setChatAdmins(chatId, admins)
    return admins
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy