diff --git a/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsChangesListener.kt b/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsChangesListener.kt new file mode 100644 index 0000000..036a757 --- /dev/null +++ b/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsChangesListener.kt @@ -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 + ) + } + } + } +} diff --git a/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/DefaultAdminsCacheAPI.kt b/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/DefaultAdminsCacheAPI.kt index 75c6ae0..89dd586 100644 --- a/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/DefaultAdminsCacheAPI.kt +++ b/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/DefaultAdminsCacheAPI.kt @@ -29,15 +29,6 @@ class DefaultAdminsCacheAPI( bot.getMe().also { botInfo = it } } - private suspend fun triggerUpdate(chatId: ChatId): List { - 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? { val settings = settingsAPI.getChatSettings(chatId) val lastUpdate = repo.lastUpdate(chatId) @@ -63,5 +54,4 @@ class DefaultAdminsCacheAPI( } override suspend fun settings(): AdminsCacheSettingsAPI = settingsAPI - } diff --git a/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/TriggerAdminsUpdate.kt b/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/TriggerAdminsUpdate.kt new file mode 100644 index 0000000..c241bab --- /dev/null +++ b/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/TriggerAdminsUpdate.kt @@ -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 { + val botInfo = botInfo ?: getMe() + val admins = getChatAdministrators(chatId).filter { + botInfo.id != it.user.id + } + repo.setChatAdmins(chatId, admins) + return admins +} diff --git a/gradle.properties b/gradle.properties index 330ac00..be1ce12 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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