mirror of
https://github.com/InsanusMokrassar/PlaguPoster.git
synced 2024-12-22 14:07:14 +00:00
commit
16bd62da51
@ -1,5 +1,11 @@
|
|||||||
# PlaguPoster
|
# PlaguPoster
|
||||||
|
|
||||||
|
## 0.5.6
|
||||||
|
|
||||||
|
* `Ratings`:
|
||||||
|
* `GC`:
|
||||||
|
* Now GC will autoclear ratings even if post is absent in posts repo
|
||||||
|
|
||||||
## 0.5.5
|
## 0.5.5
|
||||||
|
|
||||||
* Dependencies update
|
* Dependencies update
|
||||||
|
@ -10,4 +10,4 @@ android.enableJetifier=true
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.5.5
|
version=0.5.6
|
||||||
|
@ -7,13 +7,18 @@ import dev.inmo.krontab.toSchedule
|
|||||||
import dev.inmo.krontab.utils.asFlowWithDelays
|
import dev.inmo.krontab.utils.asFlowWithDelays
|
||||||
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
|
import dev.inmo.micro_utils.koin.singleWithRandomQualifier
|
||||||
import dev.inmo.micro_utils.repos.*
|
import dev.inmo.micro_utils.repos.*
|
||||||
import dev.inmo.plagubot.Plugin
|
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.plaguposter.posts.models.PostId
|
import dev.inmo.plaguposter.posts.models.PostId
|
||||||
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
|
||||||
import dev.inmo.plaguposter.ratings.repo.RatingsRepo
|
import dev.inmo.plaguposter.ratings.repo.RatingsRepo
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
import dev.inmo.tgbotapi.types.Seconds
|
import dev.inmo.tgbotapi.types.Seconds
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
@ -62,7 +67,9 @@ object Plugin : Plugin {
|
|||||||
suspend fun doAutoClear() {
|
suspend fun doAutoClear() {
|
||||||
val dropCreatedBefore = DateTime.now() - (autoclear.skipPostAge ?: 0).seconds
|
val dropCreatedBefore = DateTime.now() - (autoclear.skipPostAge ?: 0).seconds
|
||||||
ratingsRepo.getPostsWithRatingLessEq(autoclear.rating).keys.forEach {
|
ratingsRepo.getPostsWithRatingLessEq(autoclear.rating).keys.forEach {
|
||||||
if ((postsRepo.getPostCreationTime(it) ?: return@forEach) < dropCreatedBefore) {
|
val postCreationDateTime = postsRepo.getPostCreationTime(it) ?: (dropCreatedBefore - 1.seconds) // do dropping if post creation time is not available
|
||||||
|
if (postCreationDateTime < dropCreatedBefore) {
|
||||||
|
ratingsRepo.unset(it)
|
||||||
postsRepo.deleteById(it)
|
postsRepo.deleteById(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,6 +80,13 @@ object Plugin : Plugin {
|
|||||||
autoclear.autoClearKrontab.toSchedule().asFlowWithDelays().subscribeSafelyWithoutExceptions(scope) {
|
autoclear.autoClearKrontab.toSchedule().asFlowWithDelays().subscribeSafelyWithoutExceptions(scope) {
|
||||||
doAutoClear()
|
doAutoClear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onCommand("clean_posts_by_ratings") {
|
||||||
|
doAutoClear()
|
||||||
|
}
|
||||||
|
koin.getOrNull<InlineTemplatesRepo>() ?.addTemplate(
|
||||||
|
OfferTemplate("Force autoclear", listOf(Format("/clean_posts_by_ratings")))
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user