From bb7fb985e31c965b7d8b1e9c82af4f58d168cec7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 9 Sep 2022 18:57:19 +0600 Subject: [PATCH] update arguments in activateAdminsChangesListening --- .../cache/admins/AdminsChangesListener.kt | 14 +++++++++++--- .../cache/admins/DefaultAdminsCacheAPI.kt | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) 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 index 036a757..36fb9d4 100644 --- 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 @@ -1,15 +1,23 @@ 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.* +import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.ChatMemberUpdatedFilterByChat import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMemberUpdated +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatChatMemberUpdatedMarkerFactory +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember +import dev.inmo.tgbotapi.types.chat.member.ChatMemberUpdated +import dev.inmo.tgbotapi.types.update.abstracts.Update suspend fun BehaviourContext.activateAdminsChangesListening( - repo: DefaultAdminsCacheAPIRepo + repo: DefaultAdminsCacheAPIRepo, + initialFilter: SimpleFilter? = null, + markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory ) { val me = getMe() - onChatMemberUpdated { + onChatMemberUpdated(initialFilter, markerFactory = markerFactory) { when { it.oldChatMemberState is AdministratorChatMember && it.newChatMemberState !is AdministratorChatMember || it.newChatMemberState is AdministratorChatMember && it.oldChatMemberState !is AdministratorChatMember -> { 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 89dd586..7374290 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 @@ -36,9 +36,9 @@ class DefaultAdminsCacheAPI( settings == null -> null settings.refreshOnRequests && (lastUpdate == null || (DateTime.now() - lastUpdate).seconds > settings.refreshSeconds) -> { - triggerUpdate(chatId) + bot.updateAdmins(chatId, repo, getBotInfo()) } - else -> repo.getChatAdmins(chatId) ?: triggerUpdate(chatId) + else -> repo.getChatAdmins(chatId) ?: bot.updateAdmins(chatId, repo, getBotInfo()) } }