mirror of
https://github.com/InsanusMokrassar/PlaguPoster.git
synced 2025-09-14 20:49:36 +00:00
fixes and fills
This commit is contained in:
@@ -12,6 +12,7 @@ kotlin {
|
||||
dependencies {
|
||||
api project(":plaguposter.common")
|
||||
api project(":plaguposter.posts")
|
||||
api project(":plaguposter.ratings.selector")
|
||||
}
|
||||
}
|
||||
jvmMain {
|
||||
|
@@ -6,6 +6,7 @@ import dev.inmo.plagubot.Plugin
|
||||
import dev.inmo.plaguposter.common.SuccessfulSymbol
|
||||
import dev.inmo.plaguposter.posts.repo.PostsRepo
|
||||
import dev.inmo.plaguposter.posts.sending.PostPublisher
|
||||
import dev.inmo.plaguposter.ratings.selector.Selector
|
||||
import dev.inmo.tgbotapi.extensions.api.edit.edit
|
||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||
import dev.inmo.tgbotapi.extensions.api.send.send
|
||||
@@ -38,10 +39,7 @@ object Plugin : Plugin {
|
||||
override suspend fun BehaviourContextWithFSM<State>.setupBotPlugin(koin: Koin) {
|
||||
val postsRepo = koin.get<PostsRepo>()
|
||||
val publisher = koin.get<PostPublisher>()
|
||||
strictlyOn { state: PublishState ->
|
||||
|
||||
null
|
||||
}
|
||||
val selector = koin.getOrNull<Selector>()
|
||||
|
||||
onCommand("publish_post") {
|
||||
val messageInReply = it.replyTo ?.contentMessageOrNull() ?: let { _ ->
|
||||
@@ -49,7 +47,7 @@ object Plugin : Plugin {
|
||||
|
||||
return@onCommand
|
||||
}
|
||||
val postId = postsRepo.getIdByChatAndMessage(messageInReply.chat.id, messageInReply.messageId)
|
||||
val postId = postsRepo.getIdByChatAndMessage(messageInReply.chat.id, messageInReply.messageId) ?: selector ?.take(1) ?.firstOrNull()
|
||||
if (postId == null) {
|
||||
reply(
|
||||
it,
|
||||
|
24
triggers/selector_with_timer/build.gradle
Normal file
24
triggers/selector_with_timer/build.gradle
Normal file
@@ -0,0 +1,24 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api project(":plaguposter.common")
|
||||
api project(":plaguposter.posts")
|
||||
api project(":plaguposter.ratings.selector")
|
||||
api libs.krontab
|
||||
}
|
||||
}
|
||||
jvmMain {
|
||||
dependencies {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1 @@
|
||||
package dev.inmo.plaguposter.triggers.selector_with_timer
|
43
triggers/selector_with_timer/src/jvmMain/kotlin/Plugin.kt
Normal file
43
triggers/selector_with_timer/src/jvmMain/kotlin/Plugin.kt
Normal file
@@ -0,0 +1,43 @@
|
||||
package dev.inmo.plaguposter.triggers.selector_with_timer
|
||||
|
||||
import dev.inmo.krontab.KrontabTemplate
|
||||
import dev.inmo.krontab.toSchedule
|
||||
import dev.inmo.krontab.utils.asFlow
|
||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||
import dev.inmo.plagubot.Plugin
|
||||
import dev.inmo.plaguposter.posts.sending.PostPublisher
|
||||
import dev.inmo.plaguposter.ratings.selector.Selector
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.json.*
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
|
||||
object Plugin : Plugin {
|
||||
@Serializable
|
||||
internal data class Config(
|
||||
@SerialName("krontab")
|
||||
val krontabTemplate: KrontabTemplate
|
||||
) {
|
||||
@Transient
|
||||
val krontab by lazy {
|
||||
krontabTemplate.toSchedule()
|
||||
}
|
||||
}
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
single { get<Json>().decodeFromJsonElement(Config.serializer(), params["timer_trigger"] ?: return@single null) }
|
||||
}
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1 @@
|
||||
<manifest package="dev.inmo.plaguposter.triggers.selector_with_timer"/>
|
Reference in New Issue
Block a user