From 53675ca59805a494923c889ceab44d95d4f91211 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 7 Sep 2022 00:23:14 +0600 Subject: [PATCH] fixes and fills --- gradle/libs.versions.toml | 2 + .../src/commonMain/kotlin/DefaultSelector.kt | 5 ++- .../src/commonMain/kotlin/Selector.kt | 3 +- .../kotlin/models/SelectorConfig.kt | 5 ++- .../commonMain/kotlin/models/TimeConfig.kt | 3 +- runner/config.json | 7 ++- settings.gradle | 1 + triggers/command/build.gradle | 1 + triggers/command/src/jvmMain/kotlin/Plugin.kt | 8 ++-- triggers/selector_with_timer/build.gradle | 24 +++++++++++ .../src/commonMain/kotlin/PackageInfo.kt | 1 + .../src/jvmMain/kotlin/Plugin.kt | 43 +++++++++++++++++++ .../src/main/AndroidManifest.xml | 1 + 13 files changed, 91 insertions(+), 13 deletions(-) create mode 100644 triggers/selector_with_timer/build.gradle create mode 100644 triggers/selector_with_timer/src/commonMain/kotlin/PackageInfo.kt create mode 100644 triggers/selector_with_timer/src/jvmMain/kotlin/Plugin.kt create mode 100644 triggers/selector_with_timer/src/main/AndroidManifest.xml diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 62b9baf..15df308 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,6 +7,7 @@ plagubot = "2.3.0" tgbotapi = "3.2.0" microutils = "0.12.6" kslog = "0.5.1" +krontab = "0.8.0" psql = "42.3.6" @@ -38,6 +39,7 @@ microutils-repos-common = { module = "dev.inmo:micro_utils.repos.common", versio microutils-repos-exposed = { module = "dev.inmo:micro_utils.repos.exposed", version.ref = "microutils" } microutils-repos-cache = { module = "dev.inmo:micro_utils.repos.cache", version.ref = "microutils" } kslog = { module = "dev.inmo:kslog", version.ref = "kslog" } +krontab = { module = "dev.inmo:krontab", version.ref = "krontab" } psql = { module = "org.postgresql:postgresql", version.ref = "psql" } diff --git a/ratings/selector/src/commonMain/kotlin/DefaultSelector.kt b/ratings/selector/src/commonMain/kotlin/DefaultSelector.kt index 482f74d..02b52ca 100644 --- a/ratings/selector/src/commonMain/kotlin/DefaultSelector.kt +++ b/ratings/selector/src/commonMain/kotlin/DefaultSelector.kt @@ -1,5 +1,6 @@ package dev.inmo.plaguposter.ratings.selector +import com.soywiz.klock.DateTime import dev.inmo.plaguposter.posts.models.PostId import dev.inmo.plaguposter.ratings.repo.RatingsRepo import dev.inmo.plaguposter.ratings.selector.models.SelectorConfig @@ -8,11 +9,11 @@ class DefaultSelector ( private val config: SelectorConfig, private val repo: RatingsRepo ) : Selector { - override suspend fun take(n: Int): List { + override suspend fun take(n: Int, now: DateTime): List { val result = mutableListOf() do { - val selected = config.active ?.ratings ?.select(repo, result) ?: break + val selected = config.active(now.time) ?.ratings ?.select(repo, result) ?: break result.add(selected) } while (result.size < n) diff --git a/ratings/selector/src/commonMain/kotlin/Selector.kt b/ratings/selector/src/commonMain/kotlin/Selector.kt index c35d18e..813aa20 100644 --- a/ratings/selector/src/commonMain/kotlin/Selector.kt +++ b/ratings/selector/src/commonMain/kotlin/Selector.kt @@ -1,7 +1,8 @@ package dev.inmo.plaguposter.ratings.selector +import com.soywiz.klock.DateTime import dev.inmo.plaguposter.posts.models.PostId interface Selector { - suspend fun take(n: Int = 1): List + suspend fun take(n: Int = 1, now: DateTime = DateTime.now()): List } diff --git a/ratings/selector/src/commonMain/kotlin/models/SelectorConfig.kt b/ratings/selector/src/commonMain/kotlin/models/SelectorConfig.kt index c7909c0..da35cf5 100644 --- a/ratings/selector/src/commonMain/kotlin/models/SelectorConfig.kt +++ b/ratings/selector/src/commonMain/kotlin/models/SelectorConfig.kt @@ -1,11 +1,12 @@ package dev.inmo.plaguposter.ratings.selector.models +import com.soywiz.klock.DateTime +import com.soywiz.klock.Time import kotlinx.serialization.Serializable @Serializable data class SelectorConfig( val items: List ) { - val active: SelectorConfigItem? - get() = items.firstOrNull { it.time.isActive } + fun active(now: Time = DateTime.now().time) = items.firstOrNull { it.time.isActive(now) } } diff --git a/ratings/selector/src/commonMain/kotlin/models/TimeConfig.kt b/ratings/selector/src/commonMain/kotlin/models/TimeConfig.kt index 6937834..826b579 100644 --- a/ratings/selector/src/commonMain/kotlin/models/TimeConfig.kt +++ b/ratings/selector/src/commonMain/kotlin/models/TimeConfig.kt @@ -17,8 +17,7 @@ class TimeConfig( @Transient val range = from .. to - val isActive: Boolean - get() = DateTime.now().time in range + fun isActive(now: Time): Boolean = now in range object TimeSerializer : KSerializer