diff --git a/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheAPI.kt b/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheAPI.kt index f2fa456..14c3850 100644 --- a/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheAPI.kt +++ b/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheAPI.kt @@ -7,8 +7,8 @@ import dev.inmo.tgbotapi.types.message.abstracts.GroupContentMessage import dev.inmo.tgbotapi.types.message.abstracts.Message interface AdminsCacheAPI { - suspend fun getChatAdmins(chatId: ChatId): List? - suspend fun isAdmin(chatId: ChatId, userId: UserId): Boolean = getChatAdmins(chatId) ?.any { + suspend fun getChatAdmins(chatId: IdChatIdentifier): List? + suspend fun isAdmin(chatId: IdChatIdentifier, userId: UserId): Boolean = getChatAdmins(chatId) ?.any { it.user.id == userId } == true suspend fun sentByAdmin(groupContentMessage: GroupContentMessage<*>): Boolean diff --git a/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheSettingsAPI.kt b/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheSettingsAPI.kt index 5bd1cad..9303ed4 100644 --- a/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheSettingsAPI.kt +++ b/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheSettingsAPI.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.libraries.cache.admins import com.soywiz.klock.minutes -import dev.inmo.tgbotapi.types.ChatId +import dev.inmo.tgbotapi.types.IdChatIdentifier import dev.inmo.tgbotapi.types.Seconds import kotlinx.coroutines.flow.SharedFlow import kotlinx.serialization.Serializable @@ -23,22 +23,22 @@ data class AdminsCacheSettings( } interface AdminsCacheSettingsAPI { - suspend fun getChatSettings(chatId: ChatId): AdminsCacheSettings? + suspend fun getChatSettings(chatId: IdChatIdentifier): AdminsCacheSettings? } interface MutableAdminsCacheSettingsAPI : AdminsCacheSettingsAPI { - val chatSettingsUpdatedFlow: SharedFlow> + val chatSettingsUpdatedFlow: SharedFlow> - suspend fun setChatSettings(chatId: ChatId, settings: AdminsCacheSettings) + suspend fun setChatSettings(chatId: IdChatIdentifier, settings: AdminsCacheSettings) } fun AdminsCacheSettingsAPI.asMutable(): MutableAdminsCacheSettingsAPI? = this as? MutableAdminsCacheSettingsAPI @Serializable class StaticAdminsCacheSettingsAPI( - private val settings: Map + private val settings: Map ) : AdminsCacheSettingsAPI { - override suspend fun getChatSettings(chatId: ChatId): AdminsCacheSettings? = settings[chatId] + override suspend fun getChatSettings(chatId: IdChatIdentifier): AdminsCacheSettings? = settings[chatId] } 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 1688df0..d1797b3 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 @@ -7,7 +7,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMe 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.ChatId +import dev.inmo.tgbotapi.types.IdChatIdentifier import dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember import dev.inmo.tgbotapi.types.chat.member.ChatMemberUpdated import dev.inmo.tgbotapi.types.update.abstracts.Update @@ -35,7 +35,7 @@ suspend fun BehaviourContext.activateAdminsChangesListening( suspend fun BehaviourContext.activateAdminsChangesListening( repo: DefaultAdminsCacheAPIRepo, - allowedChats: List + allowedChats: List ) = activateAdminsChangesListening( repo, { diff --git a/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsSimpleFilter.kt b/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsSimpleFilter.kt index 6fd5fe9..e05e4db 100644 --- a/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsSimpleFilter.kt +++ b/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsSimpleFilter.kt @@ -2,19 +2,19 @@ package dev.inmo.tgbotapi.libraries.cache.admins import dev.inmo.tgbotapi.abstracts.FromUser import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter -import dev.inmo.tgbotapi.types.ChatId +import dev.inmo.tgbotapi.types.IdChatIdentifier import dev.inmo.tgbotapi.types.UserId import dev.inmo.tgbotapi.types.message.abstracts.Message fun AdminsChecker( adminsCacheAPI: AdminsCacheAPI -): SimpleFilter> = SimpleFilter { +): SimpleFilter> = SimpleFilter { adminsCacheAPI.isAdmin(it.first, it.second) } fun AdminsChecker( adminsCacheAPI: AdminsCacheAPI, - mapper: (T) -> Pair + mapper: (T) -> Pair ): SimpleFilter { val baseChecker = AdminsChecker(adminsCacheAPI) @@ -31,7 +31,7 @@ fun MessageAdminsChecker( fun AdminsChecker( adminsCacheAPI: AdminsCacheAPI, - chatId: ChatId + chatId: IdChatIdentifier ) = SimpleFilter { adminsCacheAPI.isAdmin(chatId, it.from.id) } 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 377f5f9..b018dac 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 @@ -11,9 +11,9 @@ import dev.inmo.tgbotapi.types.message.abstracts.* import kotlinx.serialization.Serializable interface DefaultAdminsCacheAPIRepo { - suspend fun getChatAdmins(chatId: ChatId): List? - suspend fun setChatAdmins(chatId: ChatId, chatMembers: List) - suspend fun lastUpdate(chatId: ChatId): DateTime? + suspend fun getChatAdmins(chatId: IdChatIdentifier): List? + suspend fun setChatAdmins(chatId: IdChatIdentifier, chatMembers: List) + suspend fun lastUpdate(chatId: IdChatIdentifier): DateTime? } @Serializable @@ -29,7 +29,7 @@ class DefaultAdminsCacheAPI( bot.getMe().also { botInfo = it } } - override suspend fun getChatAdmins(chatId: ChatId): List? { + override suspend fun getChatAdmins(chatId: IdChatIdentifier): List? { val settings = settingsAPI.getChatSettings(chatId) val lastUpdate = repo.lastUpdate(chatId) return when { @@ -42,7 +42,7 @@ class DefaultAdminsCacheAPI( } } - override suspend fun isAdmin(chatId: ChatId, userId: UserId): Boolean { + override suspend fun isAdmin(chatId: IdChatIdentifier, userId: UserId): Boolean { val settings = settingsAPI.getChatSettings(chatId) val lastUpdate = repo.lastUpdate(chatId) return when { diff --git a/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/MessageSenderVerification.kt b/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/MessageSenderVerification.kt index a5fe89a..7bf0153 100644 --- a/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/MessageSenderVerification.kt +++ b/cache/admins/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/MessageSenderVerification.kt @@ -1,6 +1,6 @@ package dev.inmo.tgbotapi.libraries.cache.admins -import dev.inmo.tgbotapi.types.ChatId +import dev.inmo.tgbotapi.types.IdChatIdentifier import dev.inmo.tgbotapi.types.UserId import dev.inmo.tgbotapi.types.message.abstracts.* @@ -13,7 +13,7 @@ suspend inline fun AdminsCacheAPI.isAdmin(message: Message) = when (message) { suspend inline fun AdminsCacheAPI.verifyMessageFromAdmin(message: Message) = isAdmin(message) suspend inline fun AdminsCacheAPI.doIfAdmin( - chatId: ChatId, + chatId: IdChatIdentifier, userId: UserId, block: () -> R ) = if(isAdmin(chatId, userId)) { 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 index c241bab..edbfa28 100644 --- 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 @@ -3,12 +3,12 @@ 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.IdChatIdentifier import dev.inmo.tgbotapi.types.chat.ExtendedBot import dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember internal suspend fun TelegramBot.updateAdmins( - chatId: ChatId, + chatId: IdChatIdentifier, repo: DefaultAdminsCacheAPIRepo, botInfo: ExtendedBot? = null ): List { diff --git a/cache/admins/micro_utils/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/micro_utils/DefaultAdminsCacheAPI.kt b/cache/admins/micro_utils/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/micro_utils/DefaultAdminsCacheAPI.kt index ee77c23..7e8a650 100644 --- a/cache/admins/micro_utils/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/micro_utils/DefaultAdminsCacheAPI.kt +++ b/cache/admins/micro_utils/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/micro_utils/DefaultAdminsCacheAPI.kt @@ -15,22 +15,22 @@ private sealed class RepoActions { abstract val deferred: CompletableDeferred } private class GetUpdateDateTimeRepoAction( - val chatId: ChatId, + val chatId: IdChatIdentifier, override val deferred: CompletableDeferred ) : RepoActions() private class GetChatAdminsRepoAction( - val chatId: ChatId, + val chatId: IdChatIdentifier, override val deferred: CompletableDeferred?> ) : RepoActions?>() private class SetChatAdminsRepoAction( - val chatId: ChatId, + val chatId: IdChatIdentifier, val newValue: List, override val deferred: CompletableDeferred ) : RepoActions() class DefaultAdminsCacheAPIRepoImpl( - private val adminsRepo: KeyValuesRepo, - private val updatesRepo: KeyValueRepo, + private val adminsRepo: KeyValuesRepo, + private val updatesRepo: KeyValueRepo, private val scope: CoroutineScope ) : DefaultAdminsCacheAPIRepo { private val actor = scope.actorAsync>(Channel.UNLIMITED) { @@ -54,7 +54,7 @@ class DefaultAdminsCacheAPIRepoImpl( } } - override suspend fun getChatAdmins(chatId: ChatId): List? { + override suspend fun getChatAdmins(chatId: IdChatIdentifier): List? { val deferred = CompletableDeferred?>() actor.trySend( GetChatAdminsRepoAction(chatId, deferred) @@ -64,7 +64,7 @@ class DefaultAdminsCacheAPIRepoImpl( return deferred.await() } - override suspend fun setChatAdmins(chatId: ChatId, chatMembers: List) { + override suspend fun setChatAdmins(chatId: IdChatIdentifier, chatMembers: List) { val deferred = CompletableDeferred() actor.trySend( SetChatAdminsRepoAction(chatId, chatMembers, deferred) @@ -73,7 +73,7 @@ class DefaultAdminsCacheAPIRepoImpl( } return deferred.await() } - override suspend fun lastUpdate(chatId: ChatId): DateTime? { + override suspend fun lastUpdate(chatId: IdChatIdentifier): DateTime? { val deferred = CompletableDeferred() actor.trySend( GetUpdateDateTimeRepoAction(chatId, deferred) @@ -85,7 +85,7 @@ class DefaultAdminsCacheAPIRepoImpl( } fun DefaultAdminsCacheAPIRepo( - adminsRepo: KeyValuesRepo, - updatesRepo: KeyValueRepo, + adminsRepo: KeyValuesRepo, + updatesRepo: KeyValueRepo, scope: CoroutineScope ) = DefaultAdminsCacheAPIRepoImpl(adminsRepo, updatesRepo, scope) diff --git a/cache/admins/micro_utils/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/micro_utils/DynamicAdminsCacheSettingsAPI.kt b/cache/admins/micro_utils/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/micro_utils/DynamicAdminsCacheSettingsAPI.kt index 756346b..6d4e324 100644 --- a/cache/admins/micro_utils/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/micro_utils/DynamicAdminsCacheSettingsAPI.kt +++ b/cache/admins/micro_utils/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/micro_utils/DynamicAdminsCacheSettingsAPI.kt @@ -3,22 +3,22 @@ package dev.inmo.tgbotapi.libraries.cache.admins.micro_utils import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.micro_utils.repos.* import dev.inmo.tgbotapi.libraries.cache.admins.* -import dev.inmo.tgbotapi.types.ChatId +import dev.inmo.tgbotapi.types.IdChatIdentifier import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.* class DynamicAdminsCacheSettingsAPI( - private val repo: KeyValueRepo, + private val repo: KeyValueRepo, private val scope: CoroutineScope ) : AdminsCacheSettingsAPI, MutableAdminsCacheSettingsAPI { - override val chatSettingsUpdatedFlow: SharedFlow> + override val chatSettingsUpdatedFlow: SharedFlow> get() = repo.onNewValue.shareIn(scope, SharingStarted.Eagerly) - override suspend fun setChatSettings(chatId: ChatId, settings: AdminsCacheSettings) { + override suspend fun setChatSettings(chatId: IdChatIdentifier, settings: AdminsCacheSettings) { repo.set(chatId, settings) } - override suspend fun getChatSettings(chatId: ChatId): AdminsCacheSettings { + override suspend fun getChatSettings(chatId: IdChatIdentifier): AdminsCacheSettings { val settings = repo.get(chatId) return if (settings == null) { val newSettings = AdminsCacheSettings() @@ -28,4 +28,4 @@ class DynamicAdminsCacheSettingsAPI( settings } } -} \ No newline at end of file +} diff --git a/cache/admins/micro_utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheAPI.kt b/cache/admins/micro_utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheAPI.kt index f46a31b..83549c7 100644 --- a/cache/admins/micro_utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheAPI.kt +++ b/cache/admins/micro_utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheAPI.kt @@ -38,7 +38,7 @@ fun TelegramBot.createAdminsCacheAPI( { long("chatId") }, { text("member") }, "AdminsTable" - ).withMapper( + ).withMapper( keyFromToTo = { chatId }, valueFromToTo = { telegramAdminsSerializationFormat.encodeToString(AdministratorChatMember.serializer(), this) }, keyToToFrom = { toChatId() }, @@ -49,7 +49,7 @@ fun TelegramBot.createAdminsCacheAPI( { long("chatId") }, { long("datetime") }, "AdminsUpdatesTimesTable" - ).withMapper( + ).withMapper( keyFromToTo = { chatId }, valueFromToTo = { this }, keyToToFrom = { toChatId() }, @@ -63,7 +63,7 @@ fun TelegramBot.createAdminsCacheAPI( { long("chatId") }, { text("settings") }, "DynamicAdminsCacheSettingsAPI" - ).withMapper( + ).withMapper( keyFromToTo = { chatId }, valueFromToTo = { telegramAdminsSerializationFormat.encodeToString(AdminsCacheSettings.serializer() , this) }, keyToToFrom = { toChatId() }, diff --git a/cache/admins/plagubot/src/jvmMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsPlugin.kt b/cache/admins/plagubot/src/jvmMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsPlugin.kt index c9d5aed..d157c6a 100644 --- a/cache/admins/plagubot/src/jvmMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsPlugin.kt +++ b/cache/admins/plagubot/src/jvmMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsPlugin.kt @@ -55,7 +55,7 @@ class AdminsPlugin : Plugin { { long("chatId") }, { text("member") }, "AdminsTable" - ).withMapper( + ).withMapper( keyFromToTo = { chatId }, valueFromToTo = { telegramAdminsSerializationFormat.encodeToString(this) }, keyToToFrom = { toChatId() }, @@ -66,7 +66,7 @@ class AdminsPlugin : Plugin { { long("chatId") }, { long("datetime") }, "AdminsUpdatesTimesTable" - ).withMapper( + ).withMapper( keyFromToTo = { chatId }, valueFromToTo = { this }, keyToToFrom = { toChatId() }, @@ -82,7 +82,7 @@ class AdminsPlugin : Plugin { { long("chatId") }, { text("settings") }, "DynamicAdminsCacheSettingsAPI" - ).withMapper( + ).withMapper( keyFromToTo = { chatId }, valueFromToTo = { telegramAdminsSerializationFormat.encodeToString(this) }, keyToToFrom = { toChatId() }, diff --git a/cache/content/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/media/common/DefaultMessageContentCache.kt b/cache/content/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/media/common/DefaultMessageContentCache.kt index 9ea614e..77907b0 100644 --- a/cache/content/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/media/common/DefaultMessageContentCache.kt +++ b/cache/content/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/media/common/DefaultMessageContentCache.kt @@ -4,7 +4,7 @@ import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.DownloadFileStream import dev.inmo.tgbotapi.requests.get.GetFile import dev.inmo.tgbotapi.requests.send.media.* -import dev.inmo.tgbotapi.types.ChatId +import dev.inmo.tgbotapi.types.IdChatIdentifier import dev.inmo.tgbotapi.types.media.* import dev.inmo.tgbotapi.types.message.content.MediaContent import dev.inmo.tgbotapi.types.message.content.MessageContent @@ -13,7 +13,7 @@ import io.ktor.utils.io.core.Input class DefaultMessageContentCache( private val bot: TelegramBot, - private val filesRefreshingChatId: ChatId, + private val filesRefreshingChatId: IdChatIdentifier, private val simpleMessageContentCache: MessagesSimpleCache, private val mediaFileActualityChecker: MediaFileActualityChecker = MediaFileActualityChecker.WithDelay( MediaFileActualityChecker.Default(filesRefreshingChatId) @@ -111,7 +111,7 @@ class DefaultMessageContentCache( companion object { operator fun invoke( bot: TelegramBot, - filesRefreshingChatId: ChatId, + filesRefreshingChatId: IdChatIdentifier, simpleMessageContentCache: MessagesSimpleCache = InMemoryMessagesSimpleCache(), mediaFileActualityChecker: MediaFileActualityChecker = MediaFileActualityChecker.WithDelay( MediaFileActualityChecker.Default(filesRefreshingChatId) diff --git a/cache/content/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/media/common/MediaFileActualityChecker.kt b/cache/content/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/media/common/MediaFileActualityChecker.kt index 941ed37..b67f203 100644 --- a/cache/content/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/media/common/MediaFileActualityChecker.kt +++ b/cache/content/common/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/media/common/MediaFileActualityChecker.kt @@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.DeleteMessage import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.ChatId +import dev.inmo.tgbotapi.types.IdChatIdentifier import dev.inmo.tgbotapi.types.MilliSeconds import dev.inmo.tgbotapi.types.message.content.MediaContent @@ -14,7 +15,7 @@ fun interface MediaFileActualityChecker { suspend fun TelegramBot.saved(mediaContent: MediaContent) {} class Default( - private val checkingChatId: ChatId + private val checkingChatId: IdChatIdentifier ) : MediaFileActualityChecker { override suspend fun TelegramBot.isActual(mediaContent: MediaContent): Boolean { return runCatching {