complete timer plugin

This commit is contained in:
2022-12-14 11:50:02 +06:00
parent c632a2ba14
commit b9c78982b5
22 changed files with 304 additions and 52 deletions

View File

@@ -0,0 +1,8 @@
package dev.inmo.plaguposter.triggers.selector_with_timer
import com.soywiz.klock.DateTime
import dev.inmo.plaguposter.posts.models.PostId
fun interface AutopostFilter {
suspend fun check(postId: PostId, dateTime: DateTime): Boolean
}

View File

@@ -34,9 +34,12 @@ object Plugin : Plugin {
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
val publisher = koin.get<PostPublisher>()
val selector = koin.get<Selector>()
koin.get<Config>().krontab.asFlow().subscribeSafelyWithoutExceptions(this) {
selector.take(now = it).forEach { postId ->
publisher.publish(postId)
val filters = koin.getAll<AutopostFilter>().distinct()
koin.get<Config>().krontab.asFlow().subscribeSafelyWithoutExceptions(this) { dateTime ->
selector.take(now = dateTime).forEach { postId ->
if (filters.all { it.check(postId, dateTime) }) {
publisher.publish(postId)
}
}
}
}