From bc0324a34f3fdbf4e3023b2ea6fca3fb0e2cda42 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 14 Dec 2022 12:09:20 +0600 Subject: [PATCH] small fixes --- triggers/timer/src/jvmMain/kotlin/Plugin.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/triggers/timer/src/jvmMain/kotlin/Plugin.kt b/triggers/timer/src/jvmMain/kotlin/Plugin.kt index 088c278..f305c53 100644 --- a/triggers/timer/src/jvmMain/kotlin/Plugin.kt +++ b/triggers/timer/src/jvmMain/kotlin/Plugin.kt @@ -2,11 +2,13 @@ package dev.inmo.plaguposter.triggers.timer import com.soywiz.klock.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 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 @@ -16,6 +18,7 @@ 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 @@ -32,12 +35,23 @@ object Plugin : Plugin { override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) { val timersRepo = koin.get() val chatsConfig = koin.get() + val panelApi = koin.get() + val scope = koin.get() with(ButtonsBuilder) { includeKeyboardHandling(timersRepo) { postId, dateTime -> timersRepo.set(postId, dateTime) true } } + + timersRepo.onNewValue.subscribeSafelyWithoutExceptions(scope) { + panelApi.forceRefresh(it.first) + } + + timersRepo.onValueRemoved.subscribeSafelyWithoutExceptions(scope) { + panelApi.forceRefresh(it) + } + onMessageDataCallbackQuery( Regex("${TimerPanelButton.timerSetPrefix} [^\\s]+"), initialFilter = {