From 66b2b21c1c4a8004bb7053f1146192be09a183c2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 22 Sep 2024 18:43:21 +0600 Subject: [PATCH 1/4] start 0.8.0 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e75b7c3..780fc34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # PlaguPoster +## 0.8.0 + ## 0.7.0 * Dependencies update diff --git a/gradle.properties b/gradle.properties index 1188d97..aff8af0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,4 +9,4 @@ android.enableJetifier=true # Project data group=dev.inmo -version=0.7.0 +version=0.8.0 From defc83740d53def65753908e4adde718c43b7833 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 22 Sep 2024 18:53:55 +0600 Subject: [PATCH 2/4] update dependencies --- common/src/jvmMain/kotlin/CommonPlugin.kt | 5 ++--- gradle/libs.versions.toml | 8 ++++---- inlines/src/jvmMain/kotlin/Plugin.kt | 2 +- posts/gc/src/jvmMain/kotlin/Plugin.kt | 8 +++----- posts/panel/src/jvmMain/kotlin/Plugin.kt | 7 +++---- posts/src/jvmMain/kotlin/Plugin.kt | 6 +++--- ratings/gc/src/jvmMain/kotlin/Plugin.kt | 5 +++-- ratings/selector/src/jvmMain/kotlin/Plugin.kt | 6 +++--- ratings/source/src/jvmMain/kotlin/Plugin.kt | 8 ++++---- ratings/src/jvmMain/kotlin/Plugin.kt | 4 ++-- triggers/command/src/jvmMain/kotlin/Plugin.kt | 7 +++---- .../selector_with_timer/src/jvmMain/kotlin/Plugin.kt | 5 +++-- .../disablers/autoposts/src/jvmMain/kotlin/Plugin.kt | 8 +------- .../timer/disablers/ratings/src/jvmMain/kotlin/Plugin.kt | 3 +-- triggers/timer/src/jvmMain/kotlin/Plugin.kt | 9 +-------- 15 files changed, 37 insertions(+), 54 deletions(-) diff --git a/common/src/jvmMain/kotlin/CommonPlugin.kt b/common/src/jvmMain/kotlin/CommonPlugin.kt index ab495b4..435cb74 100644 --- a/common/src/jvmMain/kotlin/CommonPlugin.kt +++ b/common/src/jvmMain/kotlin/CommonPlugin.kt @@ -11,15 +11,14 @@ import kotlinx.coroutines.SupervisorJob import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.json.booleanOrNull -import org.jetbrains.exposed.sql.Database import org.koin.core.Koin import org.koin.core.module.Module object CommonPlugin : Plugin { private val Log = logger - override fun Module.setupDI(database: Database, params: JsonObject) { + override fun Module.setupDI(config: JsonObject) { single { CoroutineScope(Dispatchers.Default + SupervisorJob()) } - val useCache = (params["useCache"] as? JsonPrimitive) ?.booleanOrNull ?: true + val useCache = (config["useCache"] as? JsonPrimitive) ?.booleanOrNull ?: true useCache(useCache) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3df21b0..92ea01f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,12 +3,12 @@ kotlin = "2.0.20" kotlin-serialization = "1.7.2" -plagubot = "9.2.0" -tgbotapi = "18.1.0" +plagubot = "10.0.0" +tgbotapi = "18.2.0" microutils = "0.22.2" kslog = "1.3.6" -krontab = "2.4.0" -plagubot-plugins = "0.21.0" +krontab = "2.5.0" +plagubot-plugins = "0.23.0" dokka = "1.9.20" diff --git a/inlines/src/jvmMain/kotlin/Plugin.kt b/inlines/src/jvmMain/kotlin/Plugin.kt index a0a37bb..a4a512e 100644 --- a/inlines/src/jvmMain/kotlin/Plugin.kt +++ b/inlines/src/jvmMain/kotlin/Plugin.kt @@ -14,7 +14,7 @@ private val actualPlugin = dev.inmo.plagubot.plugins.inline.queries.Plugin object Plugin : Plugin by actualPlugin { private val log = TagLogger("InlinePlugin") - override fun Module.setupDI(database: Database, params: JsonObject) { + override fun Module.setupDI(params: JsonObject) { single { actualPlugin } } diff --git a/posts/gc/src/jvmMain/kotlin/Plugin.kt b/posts/gc/src/jvmMain/kotlin/Plugin.kt index e6b866f..b9c9fd2 100644 --- a/posts/gc/src/jvmMain/kotlin/Plugin.kt +++ b/posts/gc/src/jvmMain/kotlin/Plugin.kt @@ -14,6 +14,7 @@ import dev.inmo.plagubot.Plugin import dev.inmo.plagubot.plugins.inline.queries.models.Format import dev.inmo.plagubot.plugins.inline.queries.models.OfferTemplate import dev.inmo.plagubot.plugins.inline.queries.repos.InlineTemplatesRepo +import dev.inmo.plagubot.registerConfig import dev.inmo.plaguposter.common.ChatConfig import dev.inmo.plaguposter.posts.models.NewPost import dev.inmo.plaguposter.posts.models.PostContentInfo @@ -38,7 +39,6 @@ import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.first import kotlinx.serialization.Serializable import kotlinx.serialization.json.* -import org.jetbrains.exposed.sql.Database import org.koin.core.Koin import org.koin.core.module.Module @@ -49,10 +49,8 @@ object Plugin : Plugin { val throttlingMillis: MilliSeconds = 1000, val doFullCheck: Boolean = false ) - override fun Module.setupDI(database: Database, params: JsonObject) { - params["messagesChecker"] ?.let { element -> - single { get().decodeFromJsonElement(Config.serializer(), element) } - } + override fun Module.setupDI(config: JsonObject) { + registerConfig("messagesChecker") { null } } private val gcLogger = KSLog("GarbageCollector") diff --git a/posts/panel/src/jvmMain/kotlin/Plugin.kt b/posts/panel/src/jvmMain/kotlin/Plugin.kt index 9b42237..f8c6861 100644 --- a/posts/panel/src/jvmMain/kotlin/Plugin.kt +++ b/posts/panel/src/jvmMain/kotlin/Plugin.kt @@ -10,6 +10,7 @@ import dev.inmo.micro_utils.repos.cache.cached import dev.inmo.micro_utils.repos.cache.full.cached import dev.inmo.micro_utils.repos.cache.full.fullyCached import dev.inmo.plagubot.Plugin +import dev.inmo.plagubot.registerConfig import dev.inmo.plaguposter.common.ChatConfig import dev.inmo.plaguposter.common.UnsuccessfulSymbol import dev.inmo.plaguposter.common.useCache @@ -55,10 +56,8 @@ object Plugin : Plugin { val rootButtonText: String = "◀️", val refreshButtonText: String? = "\uD83D\uDD04" ) - override fun Module.setupDI(database: Database, params: JsonObject) { - params["panel"] ?.let { element -> - single { get().decodeFromJsonElement(Config.serializer(), element) } - } + override fun Module.setupDI(params: JsonObject) { + registerConfig("panel") { null } single { val config = getOrNull() ?: Config() val builtInButtons = listOfNotNull( diff --git a/posts/src/jvmMain/kotlin/Plugin.kt b/posts/src/jvmMain/kotlin/Plugin.kt index e7f7a60..9bd7eb3 100644 --- a/posts/src/jvmMain/kotlin/Plugin.kt +++ b/posts/src/jvmMain/kotlin/Plugin.kt @@ -7,6 +7,7 @@ import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.micro_utils.koin.singleWithBinds import dev.inmo.micro_utils.repos.deleteById import dev.inmo.plagubot.Plugin +import dev.inmo.plagubot.database import dev.inmo.plaguposter.common.SuccessfulSymbol import dev.inmo.plaguposter.common.UnsuccessfulSymbol import dev.inmo.plaguposter.posts.exposed.ExposedPostsRepo @@ -26,7 +27,6 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onComman import dev.inmo.tgbotapi.types.message.textsources.regular import kotlinx.serialization.Serializable import kotlinx.serialization.json.* -import org.jetbrains.exposed.sql.Database import org.koin.core.Koin import org.koin.core.module.Module @@ -37,8 +37,8 @@ object Plugin : Plugin { val autoRemoveMessages: Boolean = true, val deleteAfterPublishing: Boolean = true ) - override fun Module.setupDI(database: Database, params: JsonObject) { - val configJson = params["posts"] ?: this@Plugin.let { + override fun Module.setupDI(config: JsonObject) { + val configJson = config["posts"] ?: this@Plugin.let { it.logger.w { "Unable to load posts plugin due to absence of `posts` key in config" } diff --git a/ratings/gc/src/jvmMain/kotlin/Plugin.kt b/ratings/gc/src/jvmMain/kotlin/Plugin.kt index 0369eac..fcacd9f 100644 --- a/ratings/gc/src/jvmMain/kotlin/Plugin.kt +++ b/ratings/gc/src/jvmMain/kotlin/Plugin.kt @@ -15,6 +15,7 @@ import dev.inmo.plagubot.Plugin import dev.inmo.plagubot.plugins.inline.queries.models.Format import dev.inmo.plagubot.plugins.inline.queries.models.OfferTemplate import dev.inmo.plagubot.plugins.inline.queries.repos.InlineTemplatesRepo +import dev.inmo.plagubot.registerConfig import dev.inmo.plaguposter.posts.models.PostId import dev.inmo.plaguposter.posts.repo.PostsRepo import dev.inmo.plaguposter.ratings.models.Rating @@ -41,8 +42,8 @@ object Plugin : Plugin { val skipPostAge: Seconds? = null ) } - override fun Module.setupDI(database: Database, params: JsonObject) { - single { get().decodeFromJsonElement(Config.serializer(), params["gc"] ?: return@single null) } + override fun Module.setupDI(params: JsonObject) { + registerConfig("gc") { null } } override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) { diff --git a/ratings/selector/src/jvmMain/kotlin/Plugin.kt b/ratings/selector/src/jvmMain/kotlin/Plugin.kt index f405210..32c5b42 100644 --- a/ratings/selector/src/jvmMain/kotlin/Plugin.kt +++ b/ratings/selector/src/jvmMain/kotlin/Plugin.kt @@ -4,17 +4,17 @@ import dev.inmo.micro_utils.repos.KeyValueRepo import dev.inmo.micro_utils.repos.exposed.keyvalue.ExposedKeyValueRepo import dev.inmo.micro_utils.repos.mappers.withMapper import dev.inmo.plagubot.Plugin +import dev.inmo.plagubot.registerConfig import dev.inmo.plaguposter.posts.models.PostId import dev.inmo.plaguposter.ratings.selector.models.SelectorConfig import korlibs.time.DateTime import kotlinx.serialization.json.* -import org.jetbrains.exposed.sql.Database import org.koin.core.module.Module import org.koin.core.qualifier.qualifier object Plugin : Plugin { - override fun Module.setupDI(database: Database, params: JsonObject) { - single { get().decodeFromJsonElement(SelectorConfig.serializer(), params["selector"] ?: return@single null) } + override fun Module.setupDI(config: JsonObject) { + registerConfig("selector") { null } single>(qualifier("latestChosenRepo")) { ExposedKeyValueRepo( get(), diff --git a/ratings/source/src/jvmMain/kotlin/Plugin.kt b/ratings/source/src/jvmMain/kotlin/Plugin.kt index 38ac0ce..a6cf5c0 100644 --- a/ratings/source/src/jvmMain/kotlin/Plugin.kt +++ b/ratings/source/src/jvmMain/kotlin/Plugin.kt @@ -10,10 +10,12 @@ import dev.inmo.micro_utils.repos.id import dev.inmo.micro_utils.repos.pagination.getAll import dev.inmo.micro_utils.repos.set import dev.inmo.plagubot.Plugin +import dev.inmo.plagubot.database import dev.inmo.plaguposter.common.* import dev.inmo.plagubot.plugins.inline.queries.models.Format import dev.inmo.plagubot.plugins.inline.queries.models.OfferTemplate import dev.inmo.plagubot.plugins.inline.queries.repos.InlineTemplatesRepo +import dev.inmo.plagubot.registerConfig import dev.inmo.plaguposter.posts.models.PostId import dev.inmo.plaguposter.posts.panel.PanelButtonBuilder import dev.inmo.plaguposter.posts.panel.PanelButtonsAPI @@ -67,10 +69,8 @@ object Plugin : Plugin { val panelButtonText: String = "Ratings" ) - override fun Module.setupDI(database: Database, params: JsonObject) { - single { - get().decodeFromJsonElement(Config.serializer(), params["ratingsPolls"] ?: error("Unable to load config for rating polls in $params")) - } + override fun Module.setupDI(params: JsonObject) { + registerConfig("ratingsPolls") single(ratingVariantsQualifier) { get().variants } single { ExposedPollsToPostsIdsRepo(database) } diff --git a/ratings/src/jvmMain/kotlin/Plugin.kt b/ratings/src/jvmMain/kotlin/Plugin.kt index 5afdb38..44ab330 100644 --- a/ratings/src/jvmMain/kotlin/Plugin.kt +++ b/ratings/src/jvmMain/kotlin/Plugin.kt @@ -4,18 +4,18 @@ import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.micro_utils.koin.singleWithBinds import dev.inmo.micro_utils.repos.unset import dev.inmo.plagubot.Plugin +import dev.inmo.plagubot.database import dev.inmo.plaguposter.common.useCache import dev.inmo.plaguposter.posts.repo.PostsRepo import dev.inmo.plaguposter.ratings.exposed.ExposedRatingsRepo import dev.inmo.plaguposter.ratings.repo.* import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext import kotlinx.serialization.json.* -import org.jetbrains.exposed.sql.Database import org.koin.core.Koin import org.koin.core.module.Module object Plugin : Plugin { - override fun Module.setupDI(database: Database, params: JsonObject) { + override fun Module.setupDI(config: JsonObject) { single { ExposedRatingsRepo(database) } singleWithBinds { val base = get() diff --git a/triggers/command/src/jvmMain/kotlin/Plugin.kt b/triggers/command/src/jvmMain/kotlin/Plugin.kt index 08fe1df..f3b892b 100644 --- a/triggers/command/src/jvmMain/kotlin/Plugin.kt +++ b/triggers/command/src/jvmMain/kotlin/Plugin.kt @@ -7,6 +7,7 @@ import dev.inmo.plaguposter.common.SuccessfulSymbol import dev.inmo.plagubot.plugins.inline.queries.models.Format import dev.inmo.plagubot.plugins.inline.queries.models.OfferTemplate import dev.inmo.plagubot.plugins.inline.queries.repos.InlineTemplatesRepo +import dev.inmo.plagubot.registerConfig import dev.inmo.plaguposter.posts.models.PostId import dev.inmo.plaguposter.posts.panel.PanelButtonBuilder import dev.inmo.plaguposter.posts.panel.PanelButtonsAPI @@ -45,10 +46,8 @@ object Plugin : Plugin { internal data class Config( val panelButtonText: String? = "Publish" ) - override fun Module.setupDI(database: Database, params: JsonObject) { - params["publish_command"] ?.let { configJson -> - single { get().decodeFromJsonElement(Config.serializer(), configJson) } - } + override fun Module.setupDI(params: JsonObject) { + registerConfig("publish_command") { null } } override suspend fun BehaviourContextWithFSM.setupBotPlugin(koin: Koin) { diff --git a/triggers/selector_with_timer/src/jvmMain/kotlin/Plugin.kt b/triggers/selector_with_timer/src/jvmMain/kotlin/Plugin.kt index 9368fbf..f34da01 100644 --- a/triggers/selector_with_timer/src/jvmMain/kotlin/Plugin.kt +++ b/triggers/selector_with_timer/src/jvmMain/kotlin/Plugin.kt @@ -16,6 +16,7 @@ import dev.inmo.plagubot.Plugin import dev.inmo.plagubot.plugins.inline.queries.models.Format import dev.inmo.plagubot.plugins.inline.queries.models.OfferTemplate import dev.inmo.plagubot.plugins.inline.queries.repos.InlineTemplatesRepo +import dev.inmo.plagubot.registerConfig import dev.inmo.plaguposter.common.ChatConfig import dev.inmo.plaguposter.posts.models.PostId import dev.inmo.plaguposter.posts.repo.ReadPostsRepo @@ -62,8 +63,8 @@ object Plugin : Plugin { @Transient val format: DateFormat = DateFormat(dateTimeFormat) } - override fun Module.setupDI(database: Database, params: JsonObject) { - single { get().decodeFromJsonElement(Config.serializer(), params["timer_trigger"] ?: return@single null) } + override fun Module.setupDI(params: JsonObject) { + registerConfig("timer_trigger") { null } } @OptIn(FlowPreview::class) diff --git a/triggers/timer/disablers/autoposts/src/jvmMain/kotlin/Plugin.kt b/triggers/timer/disablers/autoposts/src/jvmMain/kotlin/Plugin.kt index d301480..0333e0f 100644 --- a/triggers/timer/disablers/autoposts/src/jvmMain/kotlin/Plugin.kt +++ b/triggers/timer/disablers/autoposts/src/jvmMain/kotlin/Plugin.kt @@ -1,21 +1,15 @@ package dev.inmo.plaguposter.triggers.timer.disablers.autoposts -import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.micro_utils.koin.singleWithRandomQualifier -import dev.inmo.micro_utils.koin.singleWithRandomQualifierAndBinds import dev.inmo.micro_utils.pagination.FirstPagePagination -import dev.inmo.micro_utils.repos.unset import dev.inmo.plagubot.Plugin -import dev.inmo.plaguposter.ratings.repo.RatingsRepo import dev.inmo.plaguposter.triggers.selector_with_timer.AutopostFilter import dev.inmo.plaguposter.triggers.timer.TimersRepo -import kotlinx.coroutines.CoroutineScope import kotlinx.serialization.json.* -import org.jetbrains.exposed.sql.Database import org.koin.core.module.Module object Plugin : Plugin { - override fun Module.setupDI(database: Database, params: JsonObject) { + override fun Module.setupDI(config: JsonObject) { singleWithRandomQualifier { val timersRepo = get() AutopostFilter { _, dateTime -> diff --git a/triggers/timer/disablers/ratings/src/jvmMain/kotlin/Plugin.kt b/triggers/timer/disablers/ratings/src/jvmMain/kotlin/Plugin.kt index af960ef..3faaec8 100644 --- a/triggers/timer/disablers/ratings/src/jvmMain/kotlin/Plugin.kt +++ b/triggers/timer/disablers/ratings/src/jvmMain/kotlin/Plugin.kt @@ -8,11 +8,10 @@ import dev.inmo.plaguposter.ratings.repo.RatingsRepo import dev.inmo.plaguposter.triggers.timer.TimersRepo import kotlinx.coroutines.CoroutineScope import kotlinx.serialization.json.* -import org.jetbrains.exposed.sql.Database import org.koin.core.module.Module object Plugin : Plugin { - override fun Module.setupDI(database: Database, params: JsonObject) { + override fun Module.setupDI(config: JsonObject) { singleWithRandomQualifier(createdAtStart = true) { val timersRepo = get() val ratingsRepo = get() diff --git a/triggers/timer/src/jvmMain/kotlin/Plugin.kt b/triggers/timer/src/jvmMain/kotlin/Plugin.kt index f0c2602..585b0c2 100644 --- a/triggers/timer/src/jvmMain/kotlin/Plugin.kt +++ b/triggers/timer/src/jvmMain/kotlin/Plugin.kt @@ -1,7 +1,5 @@ package dev.inmo.plaguposter.triggers.timer -import korlibs.time.DateTime -import dev.inmo.micro_utils.coroutines.runCatchingSafely import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.micro_utils.koin.singleWithRandomQualifierAndBinds import dev.inmo.micro_utils.repos.set @@ -9,24 +7,19 @@ import dev.inmo.plagubot.Plugin import dev.inmo.plaguposter.common.ChatConfig import dev.inmo.plaguposter.posts.models.PostId import dev.inmo.plaguposter.posts.panel.PanelButtonsAPI -import dev.inmo.plaguposter.posts.repo.ReadPostsRepo import dev.inmo.plaguposter.triggers.timer.repo.ExposedTimersRepo import dev.inmo.tgbotapi.extensions.api.answers.answer -import dev.inmo.tgbotapi.extensions.api.edit.edit import dev.inmo.tgbotapi.extensions.api.send.reply -import dev.inmo.tgbotapi.extensions.api.send.send import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext -import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMessageDataCallbackQuery import kotlinx.coroutines.CoroutineScope import kotlinx.serialization.json.* -import org.jetbrains.exposed.sql.Database import org.koin.core.Koin import org.koin.core.module.Module import org.koin.dsl.binds object Plugin : Plugin { - override fun Module.setupDI(database: Database, params: JsonObject) { + override fun Module.setupDI(config: JsonObject) { single { ExposedTimersRepo(get(), get(), get()) } binds arrayOf(TimersRepo::class) single(createdAtStart = true) { TimersHandler(get(), get(), get()) } singleWithRandomQualifierAndBinds { TimerPanelButton(get()) } From 569f15330c223048bad70f8905e9267cad7e1f90 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 6 Nov 2024 20:04:54 +0600 Subject: [PATCH 3/4] fixes after update --- gradle/libs.versions.toml | 14 +++++++------- gradle/wrapper/gradle-wrapper.properties | 2 +- .../src/commonMain/kotlin/sending/PostPublisher.kt | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 92ea01f..7229d8d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,14 +1,14 @@ [versions] -kotlin = "2.0.20" -kotlin-serialization = "1.7.2" +kotlin = "2.0.21" +kotlin-serialization = "1.7.3" -plagubot = "10.0.0" -tgbotapi = "18.2.0" -microutils = "0.22.2" +plagubot = "10.1.0" +tgbotapi = "20.0.0" +microutils = "0.23.0" kslog = "1.3.6" -krontab = "2.5.0" -plagubot-plugins = "0.23.0" +krontab = "2.6.1" +plagubot-plugins = "0.24.0" dokka = "1.9.20" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 48c0a02..1e2fbf0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/posts/src/commonMain/kotlin/sending/PostPublisher.kt b/posts/src/commonMain/kotlin/sending/PostPublisher.kt index 9189519..6135f09 100644 --- a/posts/src/commonMain/kotlin/sending/PostPublisher.kt +++ b/posts/src/commonMain/kotlin/sending/PostPublisher.kt @@ -40,13 +40,13 @@ class PostPublisher( contents.singleOrNull() ?.also { targetChatIds.forEach { targetChatId -> runCatching { - bot.copyMessage(targetChatId, it.chatId, it.messageId) + bot.copyMessage(fromChatId = it.chatId, messageId = it.messageId, toChatId = targetChatId) }.onFailure { _ -> runCatching { bot.forwardMessage( fromChatId = it.chatId, - toChatId = cachingChatId, - messageId = it.messageId + messageId = it.messageId, + toChatId = cachingChatId ) }.onSuccess { bot.copyMessage(targetChatId, it) From aeb3bf1f3de825fd06a0d9437786d2c7f451afd0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 6 Nov 2024 20:48:21 +0600 Subject: [PATCH 4/4] ratings auto clearup --- CHANGELOG.md | 4 +++ ratings/build.gradle | 1 + .../src/commonMain/kotlin/models/Config.kt | 18 +++++++++++++ ratings/src/jvmMain/kotlin/Plugin.kt | 25 +++++++++++++++++-- 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 ratings/src/commonMain/kotlin/models/Config.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 780fc34..6fcf9f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.8.0 +* Dependencies update +* `Ratings`: + * Add autoclearing of ratings without target posts each half hours + ## 0.7.0 * Dependencies update diff --git a/ratings/build.gradle b/ratings/build.gradle index 3793d30..1c0d789 100644 --- a/ratings/build.gradle +++ b/ratings/build.gradle @@ -11,6 +11,7 @@ kotlin { dependencies { api project(":plaguposter.common") api project(":plaguposter.posts") + api libs.krontab } } } diff --git a/ratings/src/commonMain/kotlin/models/Config.kt b/ratings/src/commonMain/kotlin/models/Config.kt new file mode 100644 index 0000000..6f8b6c7 --- /dev/null +++ b/ratings/src/commonMain/kotlin/models/Config.kt @@ -0,0 +1,18 @@ +package dev.inmo.plaguposter.ratings.models + +import dev.inmo.krontab.EveryHourScheduler +import dev.inmo.krontab.KrontabTemplate +import dev.inmo.krontab.buildSchedule +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.Transient + +@Serializable +internal data class RatingsConfig( + @SerialName("manualRecheckKrontab") + val manualRecheckKrontabTemplate: KrontabTemplate = "0 /30 *" +) { + @Transient + val manualRecheckKrontab + get() = buildSchedule(manualRecheckKrontabTemplate) +} diff --git a/ratings/src/jvmMain/kotlin/Plugin.kt b/ratings/src/jvmMain/kotlin/Plugin.kt index 44ab330..deb5960 100644 --- a/ratings/src/jvmMain/kotlin/Plugin.kt +++ b/ratings/src/jvmMain/kotlin/Plugin.kt @@ -1,20 +1,29 @@ package dev.inmo.plaguposter.ratings +import dev.inmo.krontab.utils.asTzFlowWithDelays +import dev.inmo.kslog.common.TagLogger +import dev.inmo.kslog.common.i import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.micro_utils.koin.singleWithBinds import dev.inmo.micro_utils.repos.unset import dev.inmo.plagubot.Plugin +import dev.inmo.plagubot.config import dev.inmo.plagubot.database +import dev.inmo.plagubot.registerConfig import dev.inmo.plaguposter.common.useCache import dev.inmo.plaguposter.posts.repo.PostsRepo +import dev.inmo.plaguposter.ratings.Plugin.setupBotPlugin import dev.inmo.plaguposter.ratings.exposed.ExposedRatingsRepo +import dev.inmo.plaguposter.ratings.models.RatingsConfig import dev.inmo.plaguposter.ratings.repo.* import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import kotlinx.coroutines.CoroutineScope import kotlinx.serialization.json.* import org.koin.core.Koin import org.koin.core.module.Module object Plugin : Plugin { + private val Log = TagLogger("RatingsPlugin") override fun Module.setupDI(config: JsonObject) { single { ExposedRatingsRepo(database) } singleWithBinds { @@ -26,12 +35,24 @@ object Plugin : Plugin { base } } + + registerConfig(RatingsConfig.serializer(), "ratings") { RatingsConfig() } } - override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) { + override suspend fun startPlugin(koin: Koin) { + super.startPlugin(koin) + val config = koin.config() + val scope = koin.get() val ratingsRepo = koin.get() - koin.get().deletedObjectsIdsFlow.subscribeSafelyWithoutExceptions(this) { + val postsRepo = koin.get() + postsRepo.deletedObjectsIdsFlow.subscribeSafelyWithoutExceptions(scope) { ratingsRepo.unset(it) } + config.manualRecheckKrontab.asTzFlowWithDelays().subscribeSafelyWithoutExceptions(scope) { + Log.i { "Start clearing ratings without registered posts" } + val postsIdsToRemove = ratingsRepo.getAll().keys - postsRepo.getAll().keys + Log.i { "Posts to remove: $postsIdsToRemove" } + ratingsRepo.unset(postsIdsToRemove.toList()) + } } }