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-08-19 16:45:28 +00:00
|
|
|
import dev.inmo.plaguposter.posts.repo.PostsRepo
|
|
|
|
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
|
|
|
|
|
|
|
|
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-08-20 16:26:38 +00:00
|
|
|
single<PostsRepo> { ExposedPostsRepo(database) }
|
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
|
|
|
}
|
|
|
|
}
|