This commit is contained in:
InsanusMokrassar 2022-09-09 18:17:02 +06:00
parent 7549286c84
commit 4c9b6e485f
3 changed files with 10 additions and 7 deletions

View File

@ -97,7 +97,9 @@ class ExposedPostsRepo(
} }
} }
override fun insert(value: NewPost, it: InsertStatement<Number>) {} override fun insert(value: NewPost, it: InsertStatement<Number>) {
it[createdColumn] = DateTime.now().unixMillis
}
override suspend fun deleteById(ids: List<PostId>) { override suspend fun deleteById(ids: List<PostId>) {
onBeforeDelete(ids) onBeforeDelete(ids)

View File

@ -6,8 +6,7 @@ import dev.inmo.krontab.KrontabTemplate
import dev.inmo.krontab.toSchedule import dev.inmo.krontab.toSchedule
import dev.inmo.krontab.utils.asFlow import dev.inmo.krontab.utils.asFlow
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
import dev.inmo.micro_utils.repos.deleteById import dev.inmo.micro_utils.repos.*
import dev.inmo.micro_utils.repos.id
import dev.inmo.plagubot.Plugin import dev.inmo.plagubot.Plugin
import dev.inmo.plaguposter.posts.repo.PostsRepo import dev.inmo.plaguposter.posts.repo.PostsRepo
import dev.inmo.plaguposter.ratings.models.Rating import dev.inmo.plaguposter.ratings.models.Rating
@ -45,9 +44,11 @@ object Plugin : Plugin {
config.immediateDrop ?.let { toDrop -> config.immediateDrop ?.let { toDrop ->
ratingsRepo.onNewValue.subscribeSafelyWithoutExceptions(this) { ratingsRepo.onNewValue.subscribeSafelyWithoutExceptions(this) {
if (it.value <= toDrop) {
postsRepo.deleteById(it.id) postsRepo.deleteById(it.id)
} }
} }
}
config.autoclear ?.let { autoclear -> config.autoclear ?.let { autoclear ->
autoclear.autoClearKrontab.toSchedule().asFlow().subscribeSafelyWithoutExceptions(scope) { autoclear.autoClearKrontab.toSchedule().asFlow().subscribeSafelyWithoutExceptions(scope) {
val dropCreatedBefore = it - (autoclear.skipPostAge ?: 0).seconds val dropCreatedBefore = it - (autoclear.skipPostAge ?: 0).seconds

View File

@ -21,9 +21,9 @@ import kotlinx.serialization.encoding.Encoder
@Serializable @Serializable
data class RatingConfig( data class RatingConfig(
val min: Rating?, val min: Rating? = null,
val max: Rating?, val max: Rating? = null,
val prefer: Prefer, val prefer: Prefer = Prefer.Random,
val otherwise: RatingConfig? = null, val otherwise: RatingConfig? = null,
val postAge: Seconds? = null val postAge: Seconds? = null
) { ) {