From 250f88e2fead647cca07fb6e062d2edab84f5b65 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 11 Dec 2023 00:19:18 +0600 Subject: [PATCH 1/2] preview adding of several sources chats --- common/src/commonMain/kotlin/ChatConfig.kt | 13 +++++++++---- common/src/jvmMain/kotlin/CommonPlugin.kt | 2 +- posts/gc/src/jvmMain/kotlin/Plugin.kt | 10 ++++++---- posts/panel/src/jvmMain/kotlin/Plugin.kt | 6 +++--- posts_registrar/src/jvmMain/kotlin/Plugin.kt | 4 ++-- ratings/source/src/jvmMain/kotlin/Plugin.kt | 6 +++--- .../src/jvmMain/kotlin/Plugin.kt | 4 ++-- 7 files changed, 26 insertions(+), 19 deletions(-) diff --git a/common/src/commonMain/kotlin/ChatConfig.kt b/common/src/commonMain/kotlin/ChatConfig.kt index dc09bb0..b9b60c5 100644 --- a/common/src/commonMain/kotlin/ChatConfig.kt +++ b/common/src/commonMain/kotlin/ChatConfig.kt @@ -12,15 +12,20 @@ data class ChatConfig( val targetChatId: IdChatIdentifier? = null, @SerialName("sourceChat") @Serializable(FullChatIdentifierSerializer::class) - val sourceChatId: IdChatIdentifier, + val sourceChatId: IdChatIdentifier?, @SerialName("cacheChat") @Serializable(FullChatIdentifierSerializer::class) val cacheChatId: IdChatIdentifier, @SerialName("targetChats") val targetChatIds: List<@Serializable(FullChatIdentifierSerializer::class) IdChatIdentifier> = emptyList(), + @SerialName("sourceChats") + val sourceChatIds: List<@Serializable(FullChatIdentifierSerializer::class) IdChatIdentifier> = emptyList(), ) { val allTargetChatIds by lazy { - listOfNotNull(targetChatId) + targetChatIds + (listOfNotNull(targetChatId) + targetChatIds).toSet() + } + val allSourceChatIds by lazy { + (listOfNotNull(sourceChatId) + sourceChatIds).toSet() } init { @@ -30,8 +35,8 @@ data class ChatConfig( } fun check(chatId: IdChatIdentifier) = when (chatId) { - targetChatId, - sourceChatId, + in allTargetChatIds, + in allSourceChatIds, cacheChatId -> true else -> false } diff --git a/common/src/jvmMain/kotlin/CommonPlugin.kt b/common/src/jvmMain/kotlin/CommonPlugin.kt index 5324019..ab495b4 100644 --- a/common/src/jvmMain/kotlin/CommonPlugin.kt +++ b/common/src/jvmMain/kotlin/CommonPlugin.kt @@ -27,7 +27,7 @@ object CommonPlugin : Plugin { val config = koin.get() Log.iS { "Target chats info: ${config.allTargetChatIds.map { getChat(it) }.joinToString()}" } - Log.iS { "Source chat info: ${getChat(config.sourceChatId)}" } + Log.iS { "Source chats info: ${config.allSourceChatIds.map { getChat(it) }.joinToString()}" } Log.iS { "Cache chat info: ${getChat(config.cacheChatId)}" } } } diff --git a/posts/gc/src/jvmMain/kotlin/Plugin.kt b/posts/gc/src/jvmMain/kotlin/Plugin.kt index d106939..e6b866f 100644 --- a/posts/gc/src/jvmMain/kotlin/Plugin.kt +++ b/posts/gc/src/jvmMain/kotlin/Plugin.kt @@ -104,10 +104,12 @@ object Plugin : Plugin { return@forEach } - send( - chatsConfig.sourceChatId, - "Can't find any messages for post $postId. So, deleting it" - ) + runCatching { + send( + chatsConfig.cacheChatId, + "Can't find any messages for post $postId. So, deleting it" + ) + } runCatching { postsRepo.deleteById(postId) } diff --git a/posts/panel/src/jvmMain/kotlin/Plugin.kt b/posts/panel/src/jvmMain/kotlin/Plugin.kt index 63b9ec8..12df7ac 100644 --- a/posts/panel/src/jvmMain/kotlin/Plugin.kt +++ b/posts/panel/src/jvmMain/kotlin/Plugin.kt @@ -146,7 +146,7 @@ object Plugin : Plugin { onMessageDataCallbackQuery ( initialFilter = { - it.data.startsWith(PanelButtonsAPI.openGlobalMenuDataPrefix) && it.message.chat.id == chatsConfig.sourceChatId + it.data.startsWith(PanelButtonsAPI.openGlobalMenuDataPrefix) && it.message.chat.id in chatsConfig.allSourceChatIds } ) { val postId = it.data.removePrefix(PanelButtonsAPI.openGlobalMenuDataPrefix).let(::PostId) @@ -155,7 +155,7 @@ object Plugin : Plugin { } onMessageDataCallbackQuery( initialFilter = { - it.data.startsWith("delete ") && it.message.chat.id == chatsConfig.sourceChatId + it.data.startsWith("delete ") && it.message.chat.id in chatsConfig.allSourceChatIds } ) { query -> val postId = query.data.removePrefix("delete ").let(::PostId) @@ -182,7 +182,7 @@ object Plugin : Plugin { } onMessageDataCallbackQuery( initialFilter = { - it.data.startsWith("refresh ") && it.message.chat.id == chatsConfig.sourceChatId + it.data.startsWith("refresh ") && it.message.chat.id in chatsConfig.allSourceChatIds } ) { query -> val postId = query.data.removePrefix("refresh ").let(::PostId) diff --git a/posts_registrar/src/jvmMain/kotlin/Plugin.kt b/posts_registrar/src/jvmMain/kotlin/Plugin.kt index 30e17fd..61a1365 100644 --- a/posts_registrar/src/jvmMain/kotlin/Plugin.kt +++ b/posts_registrar/src/jvmMain/kotlin/Plugin.kt @@ -119,12 +119,12 @@ object Plugin : Plugin { null } - onCommand("start_post", initialFilter = { it.sameChat(config.sourceChatId) }) { + onCommand("start_post", initialFilter = { config.allSourceChatIds.any { chatId -> it.sameChat(chatId) } }) { startChain(RegistrationState.InProcess(it.chat.id, emptyList())) } onContentMessage( - initialFilter = { it.sameChat(config.sourceChatId) && !FirstSourceIsCommandsFilter(it) } + initialFilter = { config.allSourceChatIds.any { chatId -> it.sameChat(chatId) } && !FirstSourceIsCommandsFilter(it) } ) { startChain(RegistrationState.Finish(it.chat.id, PostContentInfo.fromMessage(it))) } diff --git a/ratings/source/src/jvmMain/kotlin/Plugin.kt b/ratings/source/src/jvmMain/kotlin/Plugin.kt index dcd3b31..819fd46 100644 --- a/ratings/source/src/jvmMain/kotlin/Plugin.kt +++ b/ratings/source/src/jvmMain/kotlin/Plugin.kt @@ -242,7 +242,7 @@ object Plugin : Plugin { } } onCommand("ratings", requireOnlyCommandInMessage = true) { - if (it.chat.id == chatConfig.sourceChatId) { + if (it.chat.id in chatConfig.allSourceChatIds) { val ratings = ratingsRepo.postsByRatings().toList().sortedByDescending { it.first } val textSources = buildEntities { + "Ratings amount: " + bold("${ratings.sumOf { it.second.size }}") + "\n\n" @@ -260,8 +260,8 @@ object Plugin : Plugin { } } } - includeRootNavigationButtonsHandler(setOf(chatConfig.sourceChatId), ratingsRepo, postsRepo) - onMessageDataCallbackQuery("ratings_interactive", initialFilter = { it.message.chat.id == chatConfig.sourceChatId }) { + includeRootNavigationButtonsHandler(chatConfig.allSourceChatIds, ratingsRepo, postsRepo) + onMessageDataCallbackQuery("ratings_interactive", initialFilter = { it.message.chat.id in chatConfig.allSourceChatIds }) { edit( it.message, ratingsRepo.buildRootButtons() diff --git a/triggers/selector_with_timer/src/jvmMain/kotlin/Plugin.kt b/triggers/selector_with_timer/src/jvmMain/kotlin/Plugin.kt index 5163317..9368fbf 100644 --- a/triggers/selector_with_timer/src/jvmMain/kotlin/Plugin.kt +++ b/triggers/selector_with_timer/src/jvmMain/kotlin/Plugin.kt @@ -151,7 +151,7 @@ object Plugin : Plugin { } } - onCommand("autoschedule_panel", initialFilter = { it.sameChat(chatConfig.sourceChatId) }) { + onCommand("autoschedule_panel", initialFilter = { chatConfig.allSourceChatIds.any { chatId -> it.sameChat(chatId) } }) { val keyboard = buildPage() runCatchingSafely { @@ -167,7 +167,7 @@ object Plugin : Plugin { onMessageDataCallbackQuery( Regex("^$pageCallbackDataQueryPrefix\\d+"), - initialFilter = { it.message.sameChat(chatConfig.sourceChatId) } + initialFilter = { chatConfig.allSourceChatIds.any { sourceChatId -> it.message.sameChat(sourceChatId) } } ) { val page = it.data.removePrefix(pageCallbackDataQueryPrefix).toIntOrNull() ?: let { _ -> answer(it) From 29a19df7fcbe89f09f307fc58c68469a73d2011e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 15 Feb 2024 20:30:10 +0600 Subject: [PATCH 2/2] update dependencies and version --- CHANGELOG.md | 4 ++++ build.gradle | 2 +- gradle.properties | 2 +- gradle/libs.versions.toml | 14 +++++++------- posts/panel/src/jvmMain/kotlin/Plugin.kt | 3 ++- posts/src/jvmMain/kotlin/Plugin.kt | 2 +- ratings/source/src/jvmMain/kotlin/Plugin.kt | 3 ++- .../timer/src/commonMain/kotlin/TimersHandler.kt | 1 + 8 files changed, 19 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 355c44d..399b4de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # PlaguPoster +## 0.5.3 + +* Dependencies update + ## 0.5.2 * Dependencies update diff --git a/build.gradle b/build.gradle index 2326bde..2540c45 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ allprojects { mavenLocal() mavenCentral() google() - maven { url "https://git.inmo.dev/api/packages/InsanusMokrassar/maven" } + maven { url "https://nexus.inmo.dev/repository/maven-releases/" } } } diff --git a/gradle.properties b/gradle.properties index a1165e3..cd60e51 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,4 +10,4 @@ android.enableJetifier=true # Project data group=dev.inmo -version=0.5.2 +version=0.5.3 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 56da3b9..dd48679 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,14 +1,14 @@ [versions] -kotlin = "1.9.21" +kotlin = "1.9.22" kotlin-serialization = "1.6.2" -plagubot = "7.4.1" -tgbotapi = "9.4.2" -microutils = "0.20.19" -kslog = "1.3.1" -krontab = "2.2.4" -plagubot-plugins = "0.17.1" +plagubot = "8.1.1" +tgbotapi = "10.0.1" +microutils = "0.20.34" +kslog = "1.3.2" +krontab = "2.2.7" +plagubot-plugins = "0.18.1" dokka = "1.9.10" diff --git a/posts/panel/src/jvmMain/kotlin/Plugin.kt b/posts/panel/src/jvmMain/kotlin/Plugin.kt index 12df7ac..d886118 100644 --- a/posts/panel/src/jvmMain/kotlin/Plugin.kt +++ b/posts/panel/src/jvmMain/kotlin/Plugin.kt @@ -31,6 +31,7 @@ import dev.inmo.tgbotapi.extensions.utils.types.buttons.dataButton import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatInlineKeyboard import dev.inmo.tgbotapi.types.IdChatIdentifier import dev.inmo.tgbotapi.types.MessageIdentifier +import dev.inmo.tgbotapi.types.ReplyParameters import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.message.ParseMode @@ -112,7 +113,7 @@ object Plugin : Plugin { firstContent.chatId, text = config.text, parseMode = config.parseMode, - replyToMessageId = firstContent.messageId, + replyParameters = ReplyParameters(firstContent.chatId, firstContent.messageId), replyMarkup = InlineKeyboardMarkup(buttons), disableNotification = true ).also { sentMessage -> diff --git a/posts/src/jvmMain/kotlin/Plugin.kt b/posts/src/jvmMain/kotlin/Plugin.kt index 61eb501..e7f7a60 100644 --- a/posts/src/jvmMain/kotlin/Plugin.kt +++ b/posts/src/jvmMain/kotlin/Plugin.kt @@ -58,7 +58,7 @@ object Plugin : Plugin { } single { val config = get() - PostPublisher(get(), get(), config.chats.cacheChatId, config.chats.allTargetChatIds, config.deleteAfterPublishing) + PostPublisher(get(), get(), config.chats.cacheChatId, config.chats.allTargetChatIds.toList(), config.deleteAfterPublishing) } } diff --git a/ratings/source/src/jvmMain/kotlin/Plugin.kt b/ratings/source/src/jvmMain/kotlin/Plugin.kt index 819fd46..c855b64 100644 --- a/ratings/source/src/jvmMain/kotlin/Plugin.kt +++ b/ratings/source/src/jvmMain/kotlin/Plugin.kt @@ -37,6 +37,7 @@ import dev.inmo.tgbotapi.extensions.utils.extensions.sameMessage import dev.inmo.tgbotapi.extensions.utils.types.buttons.dataButton import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatInlineKeyboard import dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard +import dev.inmo.tgbotapi.types.ReplyParameters import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton import dev.inmo.tgbotapi.types.message.textsources.bold import dev.inmo.tgbotapi.types.message.textsources.regular @@ -129,7 +130,7 @@ object Plugin : Plugin { content.chatId, config.ratingOfferText, config.variants.keys.toList(), - replyToMessageId = content.messageId + replyParameters = ReplyParameters(content.chatId, content.messageId) ) pollsToPostsIdsRepo.set(sent.content.poll.id, postId) pollsToMessageInfoRepo.set(sent.content.poll.id, sent.short()) diff --git a/triggers/timer/src/commonMain/kotlin/TimersHandler.kt b/triggers/timer/src/commonMain/kotlin/TimersHandler.kt index ce26046..44a704a 100644 --- a/triggers/timer/src/commonMain/kotlin/TimersHandler.kt +++ b/triggers/timer/src/commonMain/kotlin/TimersHandler.kt @@ -7,6 +7,7 @@ import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.micro_utils.repos.unset import dev.inmo.plaguposter.posts.models.PostId import dev.inmo.plaguposter.posts.sending.PostPublisher +import korlibs.time.millisecondsLong import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import kotlinx.coroutines.delay