2022-08-21 10:03:27 +00:00
|
|
|
package dev.inmo.plaguposter.ratings
|
|
|
|
|
2022-09-04 09:46:45 +00:00
|
|
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
|
|
|
import dev.inmo.micro_utils.repos.unset
|
2022-08-21 10:03:27 +00:00
|
|
|
import dev.inmo.plagubot.Plugin
|
|
|
|
import dev.inmo.plaguposter.posts.exposed.ExposedPostsRepo
|
2022-09-04 09:46:45 +00:00
|
|
|
import dev.inmo.plaguposter.posts.repo.PostsRepo
|
2022-08-21 10:03:27 +00:00
|
|
|
import dev.inmo.plaguposter.ratings.exposed.ExposedRatingsRepo
|
2022-09-04 07:27:35 +00:00
|
|
|
import dev.inmo.plaguposter.ratings.repo.*
|
2022-09-04 09:46:45 +00:00
|
|
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
2022-08-21 10:03:27 +00:00
|
|
|
import kotlinx.serialization.json.*
|
|
|
|
import org.jetbrains.exposed.sql.Database
|
2022-09-04 09:46:45 +00:00
|
|
|
import org.koin.core.Koin
|
2022-08-21 10:03:27 +00:00
|
|
|
import org.koin.core.module.Module
|
2022-09-04 07:27:35 +00:00
|
|
|
import org.koin.dsl.binds
|
2022-08-21 10:03:27 +00:00
|
|
|
|
|
|
|
object Plugin : Plugin {
|
|
|
|
override fun Module.setupDI(database: Database, params: JsonObject) {
|
2022-09-04 09:46:45 +00:00
|
|
|
single { ExposedRatingsRepo(database) } binds arrayOf(
|
2022-09-04 07:27:35 +00:00
|
|
|
RatingsRepo::class,
|
|
|
|
ReadRatingsRepo::class,
|
|
|
|
WriteRatingsRepo::class,
|
|
|
|
)
|
2022-08-21 10:03:27 +00:00
|
|
|
}
|
2022-09-04 09:46:45 +00:00
|
|
|
|
|
|
|
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
|
|
|
|
val ratingsRepo = koin.get<RatingsRepo>()
|
|
|
|
koin.get<PostsRepo>().deletedObjectsIdsFlow.subscribeSafelyWithoutExceptions(this) {
|
|
|
|
ratingsRepo.unset(it)
|
|
|
|
}
|
|
|
|
}
|
2022-08-21 10:03:27 +00:00
|
|
|
}
|