mirror of
https://github.com/InsanusMokrassar/PlaguPoster.git
synced 2025-11-12 09:20:06 +00:00
complete timer plugin
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user