2022-08-18 12:59:05 +00:00
|
|
|
package dev.inmo.plaguposter.posts
|
|
|
|
|
2022-08-19 16:45:28 +00:00
|
|
|
import dev.inmo.kslog.common.logger
|
|
|
|
import dev.inmo.kslog.common.w
|
2022-08-18 12:59:05 +00:00
|
|
|
import dev.inmo.plagubot.Plugin
|
2022-08-19 16:45:28 +00:00
|
|
|
import dev.inmo.plaguposter.posts.exposed.ExposedPostsRepo
|
2022-08-31 18:03:26 +00:00
|
|
|
import dev.inmo.plaguposter.posts.models.ChatConfig
|
2022-09-04 07:27:35 +00:00
|
|
|
import dev.inmo.plaguposter.posts.repo.*
|
2022-08-19 16:45:28 +00:00
|
|
|
import dev.inmo.plaguposter.posts.sending.PostPublisher
|
|
|
|
import dev.inmo.tgbotapi.types.ChatId
|
|
|
|
import kotlinx.serialization.SerialName
|
|
|
|
import kotlinx.serialization.Serializable
|
|
|
|
import kotlinx.serialization.json.*
|
2022-08-18 12:59:05 +00:00
|
|
|
import org.jetbrains.exposed.sql.Database
|
|
|
|
import org.koin.core.module.Module
|
2022-09-04 07:27:35 +00:00
|
|
|
import org.koin.dsl.binds
|
2022-08-18 12:59:05 +00:00
|
|
|
|
|
|
|
object Plugin : Plugin {
|
|
|
|
override fun Module.setupDI(database: Database, params: JsonObject) {
|
2022-08-19 16:45:28 +00:00
|
|
|
val configJson = params["posts"] ?: this@Plugin.let {
|
|
|
|
it.logger.w {
|
|
|
|
"Unable to load posts plugin due to absence of `posts` key in config"
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2022-08-31 18:03:26 +00:00
|
|
|
single { get<Json>().decodeFromJsonElement(ChatConfig.serializer(), configJson) }
|
2022-09-04 07:27:35 +00:00
|
|
|
single { ExposedPostsRepo(database) } binds arrayOf(
|
|
|
|
PostsRepo::class,
|
|
|
|
ReadPostsRepo::class,
|
|
|
|
WritePostsRepo::class,
|
|
|
|
)
|
2022-08-19 16:45:28 +00:00
|
|
|
single {
|
2022-08-31 18:03:26 +00:00
|
|
|
val config = get<ChatConfig>()
|
2022-08-19 16:45:28 +00:00
|
|
|
PostPublisher(get(), get(), config.cacheChatId, config.targetChatId)
|
|
|
|
}
|
2022-08-18 12:59:05 +00:00
|
|
|
}
|
|
|
|
}
|