mirror of
https://github.com/InsanusMokrassar/PlaguPoster.git
synced 2024-11-25 08:58:45 +00:00
Compare commits
No commits in common. "cdcdb4ef005080023172c5ba68ac33fd7937a88e" and "63800ce19cf2d89ef94bc469c3cf0d40e3758ac8" have entirely different histories.
cdcdb4ef00
...
63800ce19c
@ -1,11 +1,5 @@
|
|||||||
# PlaguPoster
|
# PlaguPoster
|
||||||
|
|
||||||
## 0.8.0
|
|
||||||
|
|
||||||
* Dependencies update
|
|
||||||
* `Ratings`:
|
|
||||||
* Add autoclearing of ratings without target posts each half hours
|
|
||||||
|
|
||||||
## 0.7.0
|
## 0.7.0
|
||||||
|
|
||||||
* Dependencies update
|
* Dependencies update
|
||||||
|
@ -11,14 +11,15 @@ import kotlinx.coroutines.SupervisorJob
|
|||||||
import kotlinx.serialization.json.JsonObject
|
import kotlinx.serialization.json.JsonObject
|
||||||
import kotlinx.serialization.json.JsonPrimitive
|
import kotlinx.serialization.json.JsonPrimitive
|
||||||
import kotlinx.serialization.json.booleanOrNull
|
import kotlinx.serialization.json.booleanOrNull
|
||||||
|
import org.jetbrains.exposed.sql.Database
|
||||||
import org.koin.core.Koin
|
import org.koin.core.Koin
|
||||||
import org.koin.core.module.Module
|
import org.koin.core.module.Module
|
||||||
|
|
||||||
object CommonPlugin : Plugin {
|
object CommonPlugin : Plugin {
|
||||||
private val Log = logger
|
private val Log = logger
|
||||||
override fun Module.setupDI(config: JsonObject) {
|
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||||
single { CoroutineScope(Dispatchers.Default + SupervisorJob()) }
|
single { CoroutineScope(Dispatchers.Default + SupervisorJob()) }
|
||||||
val useCache = (config["useCache"] as? JsonPrimitive) ?.booleanOrNull ?: true
|
val useCache = (params["useCache"] as? JsonPrimitive) ?.booleanOrNull ?: true
|
||||||
useCache(useCache)
|
useCache(useCache)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,4 +9,4 @@ android.enableJetifier=true
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.8.0
|
version=0.7.0
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
[versions]
|
[versions]
|
||||||
|
|
||||||
kotlin = "2.0.21"
|
kotlin = "2.0.20"
|
||||||
kotlin-serialization = "1.7.3"
|
kotlin-serialization = "1.7.2"
|
||||||
|
|
||||||
plagubot = "10.1.0"
|
plagubot = "9.2.0"
|
||||||
tgbotapi = "20.0.0"
|
tgbotapi = "18.1.0"
|
||||||
microutils = "0.23.0"
|
microutils = "0.22.2"
|
||||||
kslog = "1.3.6"
|
kslog = "1.3.6"
|
||||||
krontab = "2.6.1"
|
krontab = "2.4.0"
|
||||||
plagubot-plugins = "0.24.0"
|
plagubot-plugins = "0.21.0"
|
||||||
|
|
||||||
dokka = "1.9.20"
|
dokka = "1.9.20"
|
||||||
|
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
@ -14,7 +14,7 @@ private val actualPlugin = dev.inmo.plagubot.plugins.inline.queries.Plugin
|
|||||||
object Plugin : Plugin by actualPlugin {
|
object Plugin : Plugin by actualPlugin {
|
||||||
private val log = TagLogger("InlinePlugin")
|
private val log = TagLogger("InlinePlugin")
|
||||||
|
|
||||||
override fun Module.setupDI(params: JsonObject) {
|
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||||
single { actualPlugin }
|
single { actualPlugin }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ import dev.inmo.plagubot.Plugin
|
|||||||
import dev.inmo.plagubot.plugins.inline.queries.models.Format
|
import dev.inmo.plagubot.plugins.inline.queries.models.Format
|
||||||
import dev.inmo.plagubot.plugins.inline.queries.models.OfferTemplate
|
import dev.inmo.plagubot.plugins.inline.queries.models.OfferTemplate
|
||||||
import dev.inmo.plagubot.plugins.inline.queries.repos.InlineTemplatesRepo
|
import dev.inmo.plagubot.plugins.inline.queries.repos.InlineTemplatesRepo
|
||||||
import dev.inmo.plagubot.registerConfig
|
|
||||||
import dev.inmo.plaguposter.common.ChatConfig
|
import dev.inmo.plaguposter.common.ChatConfig
|
||||||
import dev.inmo.plaguposter.posts.models.NewPost
|
import dev.inmo.plaguposter.posts.models.NewPost
|
||||||
import dev.inmo.plaguposter.posts.models.PostContentInfo
|
import dev.inmo.plaguposter.posts.models.PostContentInfo
|
||||||
@ -39,6 +38,7 @@ import kotlinx.coroutines.flow.filter
|
|||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
|
import org.jetbrains.exposed.sql.Database
|
||||||
import org.koin.core.Koin
|
import org.koin.core.Koin
|
||||||
import org.koin.core.module.Module
|
import org.koin.core.module.Module
|
||||||
|
|
||||||
@ -49,8 +49,10 @@ object Plugin : Plugin {
|
|||||||
val throttlingMillis: MilliSeconds = 1000,
|
val throttlingMillis: MilliSeconds = 1000,
|
||||||
val doFullCheck: Boolean = false
|
val doFullCheck: Boolean = false
|
||||||
)
|
)
|
||||||
override fun Module.setupDI(config: JsonObject) {
|
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||||
registerConfig<Config>("messagesChecker") { null }
|
params["messagesChecker"] ?.let { element ->
|
||||||
|
single { get<Json>().decodeFromJsonElement(Config.serializer(), element) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val gcLogger = KSLog("GarbageCollector")
|
private val gcLogger = KSLog("GarbageCollector")
|
||||||
|
@ -10,7 +10,6 @@ import dev.inmo.micro_utils.repos.cache.cached
|
|||||||
import dev.inmo.micro_utils.repos.cache.full.cached
|
import dev.inmo.micro_utils.repos.cache.full.cached
|
||||||
import dev.inmo.micro_utils.repos.cache.full.fullyCached
|
import dev.inmo.micro_utils.repos.cache.full.fullyCached
|
||||||
import dev.inmo.plagubot.Plugin
|
import dev.inmo.plagubot.Plugin
|
||||||
import dev.inmo.plagubot.registerConfig
|
|
||||||
import dev.inmo.plaguposter.common.ChatConfig
|
import dev.inmo.plaguposter.common.ChatConfig
|
||||||
import dev.inmo.plaguposter.common.UnsuccessfulSymbol
|
import dev.inmo.plaguposter.common.UnsuccessfulSymbol
|
||||||
import dev.inmo.plaguposter.common.useCache
|
import dev.inmo.plaguposter.common.useCache
|
||||||
@ -56,8 +55,10 @@ object Plugin : Plugin {
|
|||||||
val rootButtonText: String = "◀️",
|
val rootButtonText: String = "◀️",
|
||||||
val refreshButtonText: String? = "\uD83D\uDD04"
|
val refreshButtonText: String? = "\uD83D\uDD04"
|
||||||
)
|
)
|
||||||
override fun Module.setupDI(params: JsonObject) {
|
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||||
registerConfig<Config>("panel") { null }
|
params["panel"] ?.let { element ->
|
||||||
|
single { get<Json>().decodeFromJsonElement(Config.serializer(), element) }
|
||||||
|
}
|
||||||
single {
|
single {
|
||||||
val config = getOrNull<Config>() ?: Config()
|
val config = getOrNull<Config>() ?: Config()
|
||||||
val builtInButtons = listOfNotNull(
|
val builtInButtons = listOfNotNull(
|
||||||
|
@ -40,13 +40,13 @@ class PostPublisher(
|
|||||||
contents.singleOrNull() ?.also {
|
contents.singleOrNull() ?.also {
|
||||||
targetChatIds.forEach { targetChatId ->
|
targetChatIds.forEach { targetChatId ->
|
||||||
runCatching {
|
runCatching {
|
||||||
bot.copyMessage(fromChatId = it.chatId, messageId = it.messageId, toChatId = targetChatId)
|
bot.copyMessage(targetChatId, it.chatId, it.messageId)
|
||||||
}.onFailure { _ ->
|
}.onFailure { _ ->
|
||||||
runCatching {
|
runCatching {
|
||||||
bot.forwardMessage(
|
bot.forwardMessage(
|
||||||
fromChatId = it.chatId,
|
fromChatId = it.chatId,
|
||||||
messageId = it.messageId,
|
toChatId = cachingChatId,
|
||||||
toChatId = cachingChatId
|
messageId = it.messageId
|
||||||
)
|
)
|
||||||
}.onSuccess {
|
}.onSuccess {
|
||||||
bot.copyMessage(targetChatId, it)
|
bot.copyMessage(targetChatId, it)
|
||||||
|
@ -7,7 +7,6 @@ import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
|||||||
import dev.inmo.micro_utils.koin.singleWithBinds
|
import dev.inmo.micro_utils.koin.singleWithBinds
|
||||||
import dev.inmo.micro_utils.repos.deleteById
|
import dev.inmo.micro_utils.repos.deleteById
|
||||||
import dev.inmo.plagubot.Plugin
|
import dev.inmo.plagubot.Plugin
|
||||||
import dev.inmo.plagubot.database
|
|
||||||
import dev.inmo.plaguposter.common.SuccessfulSymbol
|
import dev.inmo.plaguposter.common.SuccessfulSymbol
|
||||||
import dev.inmo.plaguposter.common.UnsuccessfulSymbol
|
import dev.inmo.plaguposter.common.UnsuccessfulSymbol
|
||||||
import dev.inmo.plaguposter.posts.exposed.ExposedPostsRepo
|
import dev.inmo.plaguposter.posts.exposed.ExposedPostsRepo
|
||||||
@ -27,6 +26,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onComman
|
|||||||
import dev.inmo.tgbotapi.types.message.textsources.regular
|
import dev.inmo.tgbotapi.types.message.textsources.regular
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
|
import org.jetbrains.exposed.sql.Database
|
||||||
import org.koin.core.Koin
|
import org.koin.core.Koin
|
||||||
import org.koin.core.module.Module
|
import org.koin.core.module.Module
|
||||||
|
|
||||||
@ -37,8 +37,8 @@ object Plugin : Plugin {
|
|||||||
val autoRemoveMessages: Boolean = true,
|
val autoRemoveMessages: Boolean = true,
|
||||||
val deleteAfterPublishing: Boolean = true
|
val deleteAfterPublishing: Boolean = true
|
||||||
)
|
)
|
||||||
override fun Module.setupDI(config: JsonObject) {
|
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||||
val configJson = config["posts"] ?: this@Plugin.let {
|
val configJson = params["posts"] ?: this@Plugin.let {
|
||||||
it.logger.w {
|
it.logger.w {
|
||||||
"Unable to load posts plugin due to absence of `posts` key in config"
|
"Unable to load posts plugin due to absence of `posts` key in config"
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ kotlin {
|
|||||||
dependencies {
|
dependencies {
|
||||||
api project(":plaguposter.common")
|
api project(":plaguposter.common")
|
||||||
api project(":plaguposter.posts")
|
api project(":plaguposter.posts")
|
||||||
api libs.krontab
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ import dev.inmo.plagubot.Plugin
|
|||||||
import dev.inmo.plagubot.plugins.inline.queries.models.Format
|
import dev.inmo.plagubot.plugins.inline.queries.models.Format
|
||||||
import dev.inmo.plagubot.plugins.inline.queries.models.OfferTemplate
|
import dev.inmo.plagubot.plugins.inline.queries.models.OfferTemplate
|
||||||
import dev.inmo.plagubot.plugins.inline.queries.repos.InlineTemplatesRepo
|
import dev.inmo.plagubot.plugins.inline.queries.repos.InlineTemplatesRepo
|
||||||
import dev.inmo.plagubot.registerConfig
|
|
||||||
import dev.inmo.plaguposter.posts.models.PostId
|
import dev.inmo.plaguposter.posts.models.PostId
|
||||||
import dev.inmo.plaguposter.posts.repo.PostsRepo
|
import dev.inmo.plaguposter.posts.repo.PostsRepo
|
||||||
import dev.inmo.plaguposter.ratings.models.Rating
|
import dev.inmo.plaguposter.ratings.models.Rating
|
||||||
@ -42,8 +41,8 @@ object Plugin : Plugin {
|
|||||||
val skipPostAge: Seconds? = null
|
val skipPostAge: Seconds? = null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
override fun Module.setupDI(params: JsonObject) {
|
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||||
registerConfig<Config>("gc") { null }
|
single { get<Json>().decodeFromJsonElement(Config.serializer(), params["gc"] ?: return@single null) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
|
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
|
||||||
|
@ -4,17 +4,17 @@ import dev.inmo.micro_utils.repos.KeyValueRepo
|
|||||||
import dev.inmo.micro_utils.repos.exposed.keyvalue.ExposedKeyValueRepo
|
import dev.inmo.micro_utils.repos.exposed.keyvalue.ExposedKeyValueRepo
|
||||||
import dev.inmo.micro_utils.repos.mappers.withMapper
|
import dev.inmo.micro_utils.repos.mappers.withMapper
|
||||||
import dev.inmo.plagubot.Plugin
|
import dev.inmo.plagubot.Plugin
|
||||||
import dev.inmo.plagubot.registerConfig
|
|
||||||
import dev.inmo.plaguposter.posts.models.PostId
|
import dev.inmo.plaguposter.posts.models.PostId
|
||||||
import dev.inmo.plaguposter.ratings.selector.models.SelectorConfig
|
import dev.inmo.plaguposter.ratings.selector.models.SelectorConfig
|
||||||
import korlibs.time.DateTime
|
import korlibs.time.DateTime
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
|
import org.jetbrains.exposed.sql.Database
|
||||||
import org.koin.core.module.Module
|
import org.koin.core.module.Module
|
||||||
import org.koin.core.qualifier.qualifier
|
import org.koin.core.qualifier.qualifier
|
||||||
|
|
||||||
object Plugin : Plugin {
|
object Plugin : Plugin {
|
||||||
override fun Module.setupDI(config: JsonObject) {
|
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||||
registerConfig<SelectorConfig>("selector") { null }
|
single { get<Json>().decodeFromJsonElement(SelectorConfig.serializer(), params["selector"] ?: return@single null) }
|
||||||
single<KeyValueRepo<PostId, DateTime>>(qualifier("latestChosenRepo")) {
|
single<KeyValueRepo<PostId, DateTime>>(qualifier("latestChosenRepo")) {
|
||||||
ExposedKeyValueRepo(
|
ExposedKeyValueRepo(
|
||||||
get(),
|
get(),
|
||||||
|
@ -10,12 +10,10 @@ import dev.inmo.micro_utils.repos.id
|
|||||||
import dev.inmo.micro_utils.repos.pagination.getAll
|
import dev.inmo.micro_utils.repos.pagination.getAll
|
||||||
import dev.inmo.micro_utils.repos.set
|
import dev.inmo.micro_utils.repos.set
|
||||||
import dev.inmo.plagubot.Plugin
|
import dev.inmo.plagubot.Plugin
|
||||||
import dev.inmo.plagubot.database
|
|
||||||
import dev.inmo.plaguposter.common.*
|
import dev.inmo.plaguposter.common.*
|
||||||
import dev.inmo.plagubot.plugins.inline.queries.models.Format
|
import dev.inmo.plagubot.plugins.inline.queries.models.Format
|
||||||
import dev.inmo.plagubot.plugins.inline.queries.models.OfferTemplate
|
import dev.inmo.plagubot.plugins.inline.queries.models.OfferTemplate
|
||||||
import dev.inmo.plagubot.plugins.inline.queries.repos.InlineTemplatesRepo
|
import dev.inmo.plagubot.plugins.inline.queries.repos.InlineTemplatesRepo
|
||||||
import dev.inmo.plagubot.registerConfig
|
|
||||||
import dev.inmo.plaguposter.posts.models.PostId
|
import dev.inmo.plaguposter.posts.models.PostId
|
||||||
import dev.inmo.plaguposter.posts.panel.PanelButtonBuilder
|
import dev.inmo.plaguposter.posts.panel.PanelButtonBuilder
|
||||||
import dev.inmo.plaguposter.posts.panel.PanelButtonsAPI
|
import dev.inmo.plaguposter.posts.panel.PanelButtonsAPI
|
||||||
@ -69,8 +67,10 @@ object Plugin : Plugin {
|
|||||||
val panelButtonText: String = "Ratings"
|
val panelButtonText: String = "Ratings"
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun Module.setupDI(params: JsonObject) {
|
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||||
registerConfig<Config>("ratingsPolls")
|
single {
|
||||||
|
get<Json>().decodeFromJsonElement(Config.serializer(), params["ratingsPolls"] ?: error("Unable to load config for rating polls in $params"))
|
||||||
|
}
|
||||||
single<RatingsVariants>(ratingVariantsQualifier) { get<Config>().variants }
|
single<RatingsVariants>(ratingVariantsQualifier) { get<Config>().variants }
|
||||||
|
|
||||||
single { ExposedPollsToPostsIdsRepo(database) }
|
single { ExposedPollsToPostsIdsRepo(database) }
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package dev.inmo.plaguposter.ratings.models
|
|
||||||
|
|
||||||
import dev.inmo.krontab.EveryHourScheduler
|
|
||||||
import dev.inmo.krontab.KrontabTemplate
|
|
||||||
import dev.inmo.krontab.buildSchedule
|
|
||||||
import kotlinx.serialization.SerialName
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
import kotlinx.serialization.Transient
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
internal data class RatingsConfig(
|
|
||||||
@SerialName("manualRecheckKrontab")
|
|
||||||
val manualRecheckKrontabTemplate: KrontabTemplate = "0 /30 *"
|
|
||||||
) {
|
|
||||||
@Transient
|
|
||||||
val manualRecheckKrontab
|
|
||||||
get() = buildSchedule(manualRecheckKrontabTemplate)
|
|
||||||
}
|
|
@ -1,30 +1,21 @@
|
|||||||
package dev.inmo.plaguposter.ratings
|
package dev.inmo.plaguposter.ratings
|
||||||
|
|
||||||
import dev.inmo.krontab.utils.asTzFlowWithDelays
|
|
||||||
import dev.inmo.kslog.common.TagLogger
|
|
||||||
import dev.inmo.kslog.common.i
|
|
||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.micro_utils.koin.singleWithBinds
|
import dev.inmo.micro_utils.koin.singleWithBinds
|
||||||
import dev.inmo.micro_utils.repos.unset
|
import dev.inmo.micro_utils.repos.unset
|
||||||
import dev.inmo.plagubot.Plugin
|
import dev.inmo.plagubot.Plugin
|
||||||
import dev.inmo.plagubot.config
|
|
||||||
import dev.inmo.plagubot.database
|
|
||||||
import dev.inmo.plagubot.registerConfig
|
|
||||||
import dev.inmo.plaguposter.common.useCache
|
import dev.inmo.plaguposter.common.useCache
|
||||||
import dev.inmo.plaguposter.posts.repo.PostsRepo
|
import dev.inmo.plaguposter.posts.repo.PostsRepo
|
||||||
import dev.inmo.plaguposter.ratings.Plugin.setupBotPlugin
|
|
||||||
import dev.inmo.plaguposter.ratings.exposed.ExposedRatingsRepo
|
import dev.inmo.plaguposter.ratings.exposed.ExposedRatingsRepo
|
||||||
import dev.inmo.plaguposter.ratings.models.RatingsConfig
|
|
||||||
import dev.inmo.plaguposter.ratings.repo.*
|
import dev.inmo.plaguposter.ratings.repo.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
|
import org.jetbrains.exposed.sql.Database
|
||||||
import org.koin.core.Koin
|
import org.koin.core.Koin
|
||||||
import org.koin.core.module.Module
|
import org.koin.core.module.Module
|
||||||
|
|
||||||
object Plugin : Plugin {
|
object Plugin : Plugin {
|
||||||
private val Log = TagLogger("RatingsPlugin")
|
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||||
override fun Module.setupDI(config: JsonObject) {
|
|
||||||
single { ExposedRatingsRepo(database) }
|
single { ExposedRatingsRepo(database) }
|
||||||
singleWithBinds<RatingsRepo> {
|
singleWithBinds<RatingsRepo> {
|
||||||
val base = get<ExposedRatingsRepo>()
|
val base = get<ExposedRatingsRepo>()
|
||||||
@ -35,24 +26,12 @@ object Plugin : Plugin {
|
|||||||
base
|
base
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerConfig(RatingsConfig.serializer(), "ratings") { RatingsConfig() }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun startPlugin(koin: Koin) {
|
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
|
||||||
super.startPlugin(koin)
|
|
||||||
val config = koin.config<RatingsConfig>()
|
|
||||||
val scope = koin.get<CoroutineScope>()
|
|
||||||
val ratingsRepo = koin.get<RatingsRepo>()
|
val ratingsRepo = koin.get<RatingsRepo>()
|
||||||
val postsRepo = koin.get<PostsRepo>()
|
koin.get<PostsRepo>().deletedObjectsIdsFlow.subscribeSafelyWithoutExceptions(this) {
|
||||||
postsRepo.deletedObjectsIdsFlow.subscribeSafelyWithoutExceptions(scope) {
|
|
||||||
ratingsRepo.unset(it)
|
ratingsRepo.unset(it)
|
||||||
}
|
}
|
||||||
config.manualRecheckKrontab.asTzFlowWithDelays().subscribeSafelyWithoutExceptions(scope) {
|
|
||||||
Log.i { "Start clearing ratings without registered posts" }
|
|
||||||
val postsIdsToRemove = ratingsRepo.getAll().keys - postsRepo.getAll().keys
|
|
||||||
Log.i { "Posts to remove: $postsIdsToRemove" }
|
|
||||||
ratingsRepo.unset(postsIdsToRemove.toList())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import dev.inmo.plaguposter.common.SuccessfulSymbol
|
|||||||
import dev.inmo.plagubot.plugins.inline.queries.models.Format
|
import dev.inmo.plagubot.plugins.inline.queries.models.Format
|
||||||
import dev.inmo.plagubot.plugins.inline.queries.models.OfferTemplate
|
import dev.inmo.plagubot.plugins.inline.queries.models.OfferTemplate
|
||||||
import dev.inmo.plagubot.plugins.inline.queries.repos.InlineTemplatesRepo
|
import dev.inmo.plagubot.plugins.inline.queries.repos.InlineTemplatesRepo
|
||||||
import dev.inmo.plagubot.registerConfig
|
|
||||||
import dev.inmo.plaguposter.posts.models.PostId
|
import dev.inmo.plaguposter.posts.models.PostId
|
||||||
import dev.inmo.plaguposter.posts.panel.PanelButtonBuilder
|
import dev.inmo.plaguposter.posts.panel.PanelButtonBuilder
|
||||||
import dev.inmo.plaguposter.posts.panel.PanelButtonsAPI
|
import dev.inmo.plaguposter.posts.panel.PanelButtonsAPI
|
||||||
@ -46,8 +45,10 @@ object Plugin : Plugin {
|
|||||||
internal data class Config(
|
internal data class Config(
|
||||||
val panelButtonText: String? = "Publish"
|
val panelButtonText: String? = "Publish"
|
||||||
)
|
)
|
||||||
override fun Module.setupDI(params: JsonObject) {
|
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||||
registerConfig<Config>("publish_command") { null }
|
params["publish_command"] ?.let { configJson ->
|
||||||
|
single { get<Json>().decodeFromJsonElement(Config.serializer(), configJson) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun BehaviourContextWithFSM<State>.setupBotPlugin(koin: Koin) {
|
override suspend fun BehaviourContextWithFSM<State>.setupBotPlugin(koin: Koin) {
|
||||||
|
@ -16,7 +16,6 @@ import dev.inmo.plagubot.Plugin
|
|||||||
import dev.inmo.plagubot.plugins.inline.queries.models.Format
|
import dev.inmo.plagubot.plugins.inline.queries.models.Format
|
||||||
import dev.inmo.plagubot.plugins.inline.queries.models.OfferTemplate
|
import dev.inmo.plagubot.plugins.inline.queries.models.OfferTemplate
|
||||||
import dev.inmo.plagubot.plugins.inline.queries.repos.InlineTemplatesRepo
|
import dev.inmo.plagubot.plugins.inline.queries.repos.InlineTemplatesRepo
|
||||||
import dev.inmo.plagubot.registerConfig
|
|
||||||
import dev.inmo.plaguposter.common.ChatConfig
|
import dev.inmo.plaguposter.common.ChatConfig
|
||||||
import dev.inmo.plaguposter.posts.models.PostId
|
import dev.inmo.plaguposter.posts.models.PostId
|
||||||
import dev.inmo.plaguposter.posts.repo.ReadPostsRepo
|
import dev.inmo.plaguposter.posts.repo.ReadPostsRepo
|
||||||
@ -63,8 +62,8 @@ object Plugin : Plugin {
|
|||||||
@Transient
|
@Transient
|
||||||
val format: DateFormat = DateFormat(dateTimeFormat)
|
val format: DateFormat = DateFormat(dateTimeFormat)
|
||||||
}
|
}
|
||||||
override fun Module.setupDI(params: JsonObject) {
|
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||||
registerConfig<Config>("timer_trigger") { null }
|
single { get<Json>().decodeFromJsonElement(Config.serializer(), params["timer_trigger"] ?: return@single null) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(FlowPreview::class)
|
@OptIn(FlowPreview::class)
|
||||||
|
@ -1,15 +1,21 @@
|
|||||||
package dev.inmo.plaguposter.triggers.timer.disablers.autoposts
|
package dev.inmo.plaguposter.triggers.timer.disablers.autoposts
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.micro_utils.koin.singleWithRandomQualifier
|
import dev.inmo.micro_utils.koin.singleWithRandomQualifier
|
||||||
|
import dev.inmo.micro_utils.koin.singleWithRandomQualifierAndBinds
|
||||||
import dev.inmo.micro_utils.pagination.FirstPagePagination
|
import dev.inmo.micro_utils.pagination.FirstPagePagination
|
||||||
|
import dev.inmo.micro_utils.repos.unset
|
||||||
import dev.inmo.plagubot.Plugin
|
import dev.inmo.plagubot.Plugin
|
||||||
|
import dev.inmo.plaguposter.ratings.repo.RatingsRepo
|
||||||
import dev.inmo.plaguposter.triggers.selector_with_timer.AutopostFilter
|
import dev.inmo.plaguposter.triggers.selector_with_timer.AutopostFilter
|
||||||
import dev.inmo.plaguposter.triggers.timer.TimersRepo
|
import dev.inmo.plaguposter.triggers.timer.TimersRepo
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
|
import org.jetbrains.exposed.sql.Database
|
||||||
import org.koin.core.module.Module
|
import org.koin.core.module.Module
|
||||||
|
|
||||||
object Plugin : Plugin {
|
object Plugin : Plugin {
|
||||||
override fun Module.setupDI(config: JsonObject) {
|
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||||
singleWithRandomQualifier<AutopostFilter> {
|
singleWithRandomQualifier<AutopostFilter> {
|
||||||
val timersRepo = get<TimersRepo>()
|
val timersRepo = get<TimersRepo>()
|
||||||
AutopostFilter { _, dateTime ->
|
AutopostFilter { _, dateTime ->
|
||||||
|
@ -8,10 +8,11 @@ import dev.inmo.plaguposter.ratings.repo.RatingsRepo
|
|||||||
import dev.inmo.plaguposter.triggers.timer.TimersRepo
|
import dev.inmo.plaguposter.triggers.timer.TimersRepo
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
|
import org.jetbrains.exposed.sql.Database
|
||||||
import org.koin.core.module.Module
|
import org.koin.core.module.Module
|
||||||
|
|
||||||
object Plugin : Plugin {
|
object Plugin : Plugin {
|
||||||
override fun Module.setupDI(config: JsonObject) {
|
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||||
singleWithRandomQualifier(createdAtStart = true) {
|
singleWithRandomQualifier(createdAtStart = true) {
|
||||||
val timersRepo = get<TimersRepo>()
|
val timersRepo = get<TimersRepo>()
|
||||||
val ratingsRepo = get<RatingsRepo>()
|
val ratingsRepo = get<RatingsRepo>()
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package dev.inmo.plaguposter.triggers.timer
|
package dev.inmo.plaguposter.triggers.timer
|
||||||
|
|
||||||
|
import korlibs.time.DateTime
|
||||||
|
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.micro_utils.koin.singleWithRandomQualifierAndBinds
|
import dev.inmo.micro_utils.koin.singleWithRandomQualifierAndBinds
|
||||||
import dev.inmo.micro_utils.repos.set
|
import dev.inmo.micro_utils.repos.set
|
||||||
@ -7,19 +9,24 @@ import dev.inmo.plagubot.Plugin
|
|||||||
import dev.inmo.plaguposter.common.ChatConfig
|
import dev.inmo.plaguposter.common.ChatConfig
|
||||||
import dev.inmo.plaguposter.posts.models.PostId
|
import dev.inmo.plaguposter.posts.models.PostId
|
||||||
import dev.inmo.plaguposter.posts.panel.PanelButtonsAPI
|
import dev.inmo.plaguposter.posts.panel.PanelButtonsAPI
|
||||||
|
import dev.inmo.plaguposter.posts.repo.ReadPostsRepo
|
||||||
import dev.inmo.plaguposter.triggers.timer.repo.ExposedTimersRepo
|
import dev.inmo.plaguposter.triggers.timer.repo.ExposedTimersRepo
|
||||||
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.edit.edit
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.send
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMessageDataCallbackQuery
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMessageDataCallbackQuery
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
|
import org.jetbrains.exposed.sql.Database
|
||||||
import org.koin.core.Koin
|
import org.koin.core.Koin
|
||||||
import org.koin.core.module.Module
|
import org.koin.core.module.Module
|
||||||
import org.koin.dsl.binds
|
import org.koin.dsl.binds
|
||||||
|
|
||||||
object Plugin : Plugin {
|
object Plugin : Plugin {
|
||||||
override fun Module.setupDI(config: JsonObject) {
|
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||||
single { ExposedTimersRepo(get(), get(), get()) } binds arrayOf(TimersRepo::class)
|
single { ExposedTimersRepo(get(), get(), get()) } binds arrayOf(TimersRepo::class)
|
||||||
single(createdAtStart = true) { TimersHandler(get(), get(), get()) }
|
single(createdAtStart = true) { TimersHandler(get(), get(), get()) }
|
||||||
singleWithRandomQualifierAndBinds { TimerPanelButton(get()) }
|
singleWithRandomQualifierAndBinds { TimerPanelButton(get()) }
|
||||||
|
Loading…
Reference in New Issue
Block a user