mirror of
https://github.com/InsanusMokrassar/TelegramBotApiLibraries.git
synced 2024-11-17 13:53:50 +00:00
update dependencies and add opportunity to listen for admins in chats
This commit is contained in:
parent
5f1f512db4
commit
18fc3fd1dd
@ -0,0 +1,24 @@
|
||||
package dev.inmo.tgbotapi.libraries.cache.admins
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMemberUpdated
|
||||
import dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember
|
||||
|
||||
suspend fun BehaviourContext.activateAdminsChangesListening(
|
||||
repo: DefaultAdminsCacheAPIRepo
|
||||
) {
|
||||
val me = getMe()
|
||||
onChatMemberUpdated {
|
||||
when {
|
||||
it.oldChatMemberState is AdministratorChatMember && it.newChatMemberState !is AdministratorChatMember ||
|
||||
it.newChatMemberState is AdministratorChatMember && it.oldChatMemberState !is AdministratorChatMember -> {
|
||||
updateAdmins(
|
||||
it.chat.id,
|
||||
repo,
|
||||
me
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -29,15 +29,6 @@ class DefaultAdminsCacheAPI(
|
||||
bot.getMe().also { botInfo = it }
|
||||
}
|
||||
|
||||
private suspend fun triggerUpdate(chatId: ChatId): List<AdministratorChatMember> {
|
||||
val botInfo = getBotInfo()
|
||||
val admins = bot.getChatAdministrators(chatId).filter {
|
||||
botInfo.id != it.user.id
|
||||
}
|
||||
repo.setChatAdmins(chatId, admins)
|
||||
return admins
|
||||
}
|
||||
|
||||
override suspend fun getChatAdmins(chatId: ChatId): List<AdministratorChatMember>? {
|
||||
val settings = settingsAPI.getChatSettings(chatId)
|
||||
val lastUpdate = repo.lastUpdate(chatId)
|
||||
@ -63,5 +54,4 @@ class DefaultAdminsCacheAPI(
|
||||
}
|
||||
|
||||
override suspend fun settings(): AdminsCacheSettingsAPI = settingsAPI
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
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.ChatId
|
||||
import dev.inmo.tgbotapi.types.chat.ExtendedBot
|
||||
import dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember
|
||||
|
||||
internal suspend fun TelegramBot.updateAdmins(
|
||||
chatId: ChatId,
|
||||
repo: DefaultAdminsCacheAPIRepo,
|
||||
botInfo: ExtendedBot? = null
|
||||
): List<AdministratorChatMember> {
|
||||
val botInfo = botInfo ?: getMe()
|
||||
val admins = getChatAdministrators(chatId).filter {
|
||||
botInfo.id != it.user.id
|
||||
}
|
||||
repo.setChatAdmins(chatId, admins)
|
||||
return admins
|
||||
}
|
@ -11,10 +11,10 @@ kotlin_serialisation_core_version=1.4.0
|
||||
|
||||
github_release_plugin_version=2.4.1
|
||||
|
||||
tgbotapi_version=3.2.0
|
||||
micro_utils_version=0.12.5
|
||||
tgbotapi_version=3.2.1
|
||||
micro_utils_version=0.12.11
|
||||
exposed_version=0.39.2
|
||||
plagubot_version=2.2.0
|
||||
plagubot_version=2.3.1
|
||||
|
||||
# ANDROID
|
||||
|
||||
@ -33,5 +33,5 @@ dokka_version=1.7.10
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.5.2
|
||||
android_code_version=29
|
||||
version=0.5.3
|
||||
android_code_version=30
|
||||
|
Loading…
Reference in New Issue
Block a user