mirror of
https://github.com/InsanusMokrassar/PlaguPoster.git
synced 2025-12-07 13:35:44 +00:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7dbc5ef254 | |||
| 380e6e1117 | |||
| d5d924401b | |||
| 53e74745aa | |||
| bae2c67136 | |||
| c579fb576c | |||
| a1cffd688e | |||
| 5cab93a7fb | |||
| 1d200c38e4 | |||
| 9ebadfe1e4 | |||
| 333f807c97 | |||
| 9ae7238974 | |||
| 275cc13ea7 | |||
| cdcdb4ef00 | |||
| aeb3bf1f3d | |||
| 569f15330c | |||
| defc83740d | |||
| 66b2b21c1c | |||
| 63800ce19c |
18
CHANGELOG.md
18
CHANGELOG.md
@@ -1,5 +1,23 @@
|
||||
# PlaguPoster
|
||||
|
||||
## 0.10.1
|
||||
|
||||
* Dependencies update
|
||||
|
||||
## 0.10.0
|
||||
|
||||
* Dependencies update
|
||||
|
||||
## 0.9.0
|
||||
|
||||
* Dependencies update
|
||||
|
||||
## 0.8.0
|
||||
|
||||
* Dependencies update
|
||||
* `Ratings`:
|
||||
* Add autoclearing of ratings without target posts each half hours
|
||||
|
||||
## 0.7.0
|
||||
|
||||
* Dependencies update
|
||||
|
||||
21
build.gradle
21
build.gradle
@@ -2,8 +2,8 @@ buildscript {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
maven { url "https://plugins.gradle.org/m2/" }
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -13,12 +13,29 @@ buildscript {
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.nmcp.aggregation)
|
||||
}
|
||||
|
||||
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
|
||||
nmcpAggregation {
|
||||
centralPortal {
|
||||
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
|
||||
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
|
||||
validationTimeout = Duration.ofHours(4)
|
||||
publishingType = System.getenv('PUBLISHING_TYPE') != "" ? System.getenv('PUBLISHING_TYPE') : "USER_MANAGED"
|
||||
}
|
||||
|
||||
publishAllProjectsProbablyBreakingProjectIsolation()
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
google()
|
||||
maven { url "https://nexus.inmo.dev/repository/maven-releases/" }
|
||||
mavenLocal()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,15 +11,14 @@ import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
import kotlinx.serialization.json.booleanOrNull
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
|
||||
object CommonPlugin : Plugin {
|
||||
private val Log = logger
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
override fun Module.setupDI(config: JsonObject) {
|
||||
single { CoroutineScope(Dispatchers.Default + SupervisorJob()) }
|
||||
val useCache = (params["useCache"] as? JsonPrimitive) ?.booleanOrNull ?: true
|
||||
val useCache = (config["useCache"] as? JsonPrimitive) ?.booleanOrNull ?: true
|
||||
useCache(useCache)
|
||||
}
|
||||
|
||||
|
||||
@@ -11,12 +11,19 @@ private String getCurrentVersionChangelog() {
|
||||
return changelogDataOS.toString().trim()
|
||||
}
|
||||
|
||||
if (new File(projectDir, "secret.gradle").exists()) {
|
||||
apply from: './secret.gradle'
|
||||
def githubTokenVariableName = "GITHUB_RELEASE_TOKEN"
|
||||
def githubTokenVariableFromEnv = System.getenv(githubTokenVariableName)
|
||||
|
||||
def secretFile = new File(projectDir, "secret.gradle")
|
||||
if (secretFile.exists() || project.hasProperty(githubTokenVariableName) || (githubTokenVariableFromEnv != "" && githubTokenVariableFromEnv != null)) {
|
||||
if (secretFile.exists()) {
|
||||
apply from: './secret.gradle'
|
||||
}
|
||||
apply plugin: "com.github.breadmoirai.github-release"
|
||||
def githubReleaseToken = project.hasProperty(githubTokenVariableName) ? project.property(githubTokenVariableName).toString() : githubTokenVariableFromEnv
|
||||
|
||||
githubRelease {
|
||||
token "${project.property('GITHUB_RELEASE_TOKEN')}"
|
||||
token githubReleaseToken
|
||||
|
||||
owner "InsanusMokrassar"
|
||||
repo "PlaguPoster"
|
||||
|
||||
@@ -9,4 +9,4 @@ android.enableJetifier=true
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.7.0
|
||||
version=0.10.1
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
[versions]
|
||||
|
||||
kotlin = "2.0.20"
|
||||
kotlin-serialization = "1.7.2"
|
||||
kotlin = "2.2.0"
|
||||
kotlin-serialization = "1.9.0"
|
||||
|
||||
plagubot = "9.2.0"
|
||||
tgbotapi = "18.1.0"
|
||||
microutils = "0.22.2"
|
||||
kslog = "1.3.6"
|
||||
krontab = "2.4.0"
|
||||
plagubot-plugins = "0.21.0"
|
||||
plagubot = "10.7.0"
|
||||
tgbotapi = "27.1.2"
|
||||
microutils = "0.26.2"
|
||||
kslog = "1.5.0"
|
||||
krontab = "2.7.2"
|
||||
plagubot-plugins = "0.24.5"
|
||||
|
||||
dokka = "1.9.20"
|
||||
nmcp="1.0.2"
|
||||
|
||||
dokka = "2.0.0"
|
||||
|
||||
psql = "42.6.0"
|
||||
|
||||
@@ -47,3 +49,5 @@ kotlin-dokka-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", vers
|
||||
|
||||
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
|
||||
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
|
||||
|
||||
nmcp-aggregation = { id = "com.gradleup.nmcp.aggregation", version.ref = "nmcp" }
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -14,7 +14,7 @@ private val actualPlugin = dev.inmo.plagubot.plugins.inline.queries.Plugin
|
||||
object Plugin : Plugin by actualPlugin {
|
||||
private val log = TagLogger("InlinePlugin")
|
||||
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
override fun Module.setupDI(params: JsonObject) {
|
||||
single { actualPlugin }
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import dev.inmo.plagubot.Plugin
|
||||
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.repos.InlineTemplatesRepo
|
||||
import dev.inmo.plagubot.registerConfig
|
||||
import dev.inmo.plaguposter.common.ChatConfig
|
||||
import dev.inmo.plaguposter.posts.models.NewPost
|
||||
import dev.inmo.plaguposter.posts.models.PostContentInfo
|
||||
@@ -38,7 +39,6 @@ import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.*
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
|
||||
@@ -49,10 +49,8 @@ object Plugin : Plugin {
|
||||
val throttlingMillis: MilliSeconds = 1000,
|
||||
val doFullCheck: Boolean = false
|
||||
)
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
params["messagesChecker"] ?.let { element ->
|
||||
single { get<Json>().decodeFromJsonElement(Config.serializer(), element) }
|
||||
}
|
||||
override fun Module.setupDI(config: JsonObject) {
|
||||
registerConfig<Config>("messagesChecker") { null }
|
||||
}
|
||||
|
||||
private val gcLogger = KSLog("GarbageCollector")
|
||||
|
||||
@@ -10,6 +10,7 @@ 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.fullyCached
|
||||
import dev.inmo.plagubot.Plugin
|
||||
import dev.inmo.plagubot.registerConfig
|
||||
import dev.inmo.plaguposter.common.ChatConfig
|
||||
import dev.inmo.plaguposter.common.UnsuccessfulSymbol
|
||||
import dev.inmo.plaguposter.common.useCache
|
||||
@@ -55,10 +56,8 @@ object Plugin : Plugin {
|
||||
val rootButtonText: String = "◀️",
|
||||
val refreshButtonText: String? = "\uD83D\uDD04"
|
||||
)
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
params["panel"] ?.let { element ->
|
||||
single { get<Json>().decodeFromJsonElement(Config.serializer(), element) }
|
||||
}
|
||||
override fun Module.setupDI(params: JsonObject) {
|
||||
registerConfig<Config>("panel") { null }
|
||||
single {
|
||||
val config = getOrNull<Config>() ?: Config()
|
||||
val builtInButtons = listOfNotNull(
|
||||
|
||||
@@ -40,13 +40,13 @@ class PostPublisher(
|
||||
contents.singleOrNull() ?.also {
|
||||
targetChatIds.forEach { targetChatId ->
|
||||
runCatching {
|
||||
bot.copyMessage(targetChatId, it.chatId, it.messageId)
|
||||
bot.copyMessage(fromChatId = it.chatId, messageId = it.messageId, toChatId = targetChatId)
|
||||
}.onFailure { _ ->
|
||||
runCatching {
|
||||
bot.forwardMessage(
|
||||
fromChatId = it.chatId,
|
||||
toChatId = cachingChatId,
|
||||
messageId = it.messageId
|
||||
messageId = it.messageId,
|
||||
toChatId = cachingChatId
|
||||
)
|
||||
}.onSuccess {
|
||||
bot.copyMessage(targetChatId, it)
|
||||
|
||||
@@ -7,6 +7,7 @@ import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.koin.singleWithBinds
|
||||
import dev.inmo.micro_utils.repos.deleteById
|
||||
import dev.inmo.plagubot.Plugin
|
||||
import dev.inmo.plagubot.database
|
||||
import dev.inmo.plaguposter.common.SuccessfulSymbol
|
||||
import dev.inmo.plaguposter.common.UnsuccessfulSymbol
|
||||
import dev.inmo.plaguposter.posts.exposed.ExposedPostsRepo
|
||||
@@ -23,10 +24,9 @@ import dev.inmo.tgbotapi.extensions.api.edit.edit
|
||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||
import dev.inmo.tgbotapi.types.message.textsources.regular
|
||||
import dev.inmo.tgbotapi.types.message.textsources.regularTextSource
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.*
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
|
||||
@@ -37,8 +37,8 @@ object Plugin : Plugin {
|
||||
val autoRemoveMessages: Boolean = true,
|
||||
val deleteAfterPublishing: Boolean = true
|
||||
)
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
val configJson = params["posts"] ?: this@Plugin.let {
|
||||
override fun Module.setupDI(config: JsonObject) {
|
||||
val configJson = config["posts"] ?: this@Plugin.let {
|
||||
it.logger.w {
|
||||
"Unable to load posts plugin due to absence of `posts` key in config"
|
||||
}
|
||||
@@ -90,9 +90,9 @@ object Plugin : Plugin {
|
||||
postsRepo.deleteById(postId)
|
||||
|
||||
if (postsRepo.contains(postId)) {
|
||||
edit(it, it.content.textSources + regular(UnsuccessfulSymbol))
|
||||
edit(it, it.content.textSources + regularTextSource(UnsuccessfulSymbol))
|
||||
} else {
|
||||
edit(it, it.content.textSources + regular(SuccessfulSymbol))
|
||||
edit(it, it.content.textSources + regularTextSource(SuccessfulSymbol))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ class ExposedPostsRepo(
|
||||
}.associateBy { it.id }
|
||||
val existsIds = posts.keys.toList()
|
||||
transaction(db = database) {
|
||||
val deleted = deleteWhere(null, null) {
|
||||
val deleted = deleteWhere {
|
||||
selectByIds(it, existsIds)
|
||||
}
|
||||
with(contentRepo) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
task javadocsJar(type: Jar) {
|
||||
@@ -19,46 +20,30 @@ publishing {
|
||||
}
|
||||
|
||||
developers {
|
||||
|
||||
developer {
|
||||
id = "InsanusMokrassar"
|
||||
name = "Aleksei Ovsiannikov"
|
||||
email = "ovsyannikov.alexey95@gmail.com"
|
||||
}
|
||||
|
||||
developer {
|
||||
id = "InsanusMokrassar"
|
||||
name = "Aleksei Ovsiannikov"
|
||||
email = "ovsyannikov.alexey95@gmail.com"
|
||||
}
|
||||
}
|
||||
|
||||
licenses {
|
||||
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
if (project.hasProperty('GITEA_TOKEN') || System.getenv('GITEA_TOKEN') != null) {
|
||||
maven {
|
||||
name = "Gitea"
|
||||
url = uri("https://git.inmo.dev/api/packages/InsanusMokrassar/maven")
|
||||
|
||||
credentials(HttpHeaderCredentials) {
|
||||
name = "Authorization"
|
||||
value = project.hasProperty('GITEA_TOKEN') ? project.property('GITEA_TOKEN') : System.getenv('GITEA_TOKEN')
|
||||
}
|
||||
|
||||
authentication {
|
||||
header(HttpHeaderAuthentication)
|
||||
}
|
||||
|
||||
license {
|
||||
name = "MIT License"
|
||||
url = "https://opensource.org/licenses/MIT"
|
||||
}
|
||||
}
|
||||
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
|
||||
maven {
|
||||
name = "sonatype"
|
||||
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
|
||||
|
||||
credentials {
|
||||
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
|
||||
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
if ((project.hasProperty('INMONEXUS_USER') || System.getenv('INMONEXUS_USER') != null) && (project.hasProperty('INMONEXUS_PASSWORD') || System.getenv('INMONEXUS_PASSWORD') != null)) {
|
||||
maven {
|
||||
name = "InmoNexus"
|
||||
url = uri("https://nexus.inmo.dev/repository/maven-releases/")
|
||||
|
||||
credentials {
|
||||
username = project.hasProperty('INMONEXUS_USER') ? project.property('INMONEXUS_USER') : System.getenv('INMONEXUS_USER')
|
||||
password = project.hasProperty('INMONEXUS_PASSWORD') ? project.property('INMONEXUS_PASSWORD') : System.getenv('INMONEXUS_PASSWORD')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,13 +52,13 @@ publishing {
|
||||
|
||||
if (project.hasProperty("signing.gnupg.keyName")) {
|
||||
apply plugin: 'signing'
|
||||
|
||||
|
||||
signing {
|
||||
useGpgCmd()
|
||||
|
||||
|
||||
sign publishing.publications
|
||||
}
|
||||
|
||||
|
||||
task signAll {
|
||||
tasks.withType(Sign).forEach {
|
||||
dependsOn(it)
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"licenses":[],"mavenConfig":{"name":"${project.name}","description":"${project.name}","url":"https://github.com/InsanusMokrassar/PlaguPoster","vcsUrl":"https://github.com/InsanusMokrassar/PlaguPoster.git","developers":[{"id":"InsanusMokrassar","name":"Aleksei Ovsiannikov","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"Gitea","url":"https://git.inmo.dev/api/packages/InsanusMokrassar/maven","credsType":{"type":"dev.inmo.kmppscriptbuilder.core.models.MavenPublishingRepository.CredentialsType.HttpHeaderCredentials","headerName":"Authorization","headerValueProperty":"GITEA_TOKEN"}},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"}}}
|
||||
{"licenses":[{"id":"MIT","title":"MIT License","url":"https://opensource.org/licenses/MIT"}],"mavenConfig":{"name":"${project.name}","description":"${project.name}","url":"https://github.com/InsanusMokrassar/PlaguPoster","vcsUrl":"https://github.com/InsanusMokrassar/PlaguPoster.git","developers":[{"id":"InsanusMokrassar","name":"Aleksei Ovsiannikov","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"InmoNexus","url":"https://nexus.inmo.dev/repository/maven-releases/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"}}}
|
||||
@@ -11,6 +11,7 @@ kotlin {
|
||||
dependencies {
|
||||
api project(":plaguposter.common")
|
||||
api project(":plaguposter.posts")
|
||||
api libs.krontab
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import dev.inmo.plagubot.Plugin
|
||||
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.repos.InlineTemplatesRepo
|
||||
import dev.inmo.plagubot.registerConfig
|
||||
import dev.inmo.plaguposter.posts.models.PostId
|
||||
import dev.inmo.plaguposter.posts.repo.PostsRepo
|
||||
import dev.inmo.plaguposter.ratings.models.Rating
|
||||
@@ -41,8 +42,8 @@ object Plugin : Plugin {
|
||||
val skipPostAge: Seconds? = null
|
||||
)
|
||||
}
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
single { get<Json>().decodeFromJsonElement(Config.serializer(), params["gc"] ?: return@single null) }
|
||||
override fun Module.setupDI(params: JsonObject) {
|
||||
registerConfig<Config>("gc") { null }
|
||||
}
|
||||
|
||||
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.mappers.withMapper
|
||||
import dev.inmo.plagubot.Plugin
|
||||
import dev.inmo.plagubot.registerConfig
|
||||
import dev.inmo.plaguposter.posts.models.PostId
|
||||
import dev.inmo.plaguposter.ratings.selector.models.SelectorConfig
|
||||
import korlibs.time.DateTime
|
||||
import kotlinx.serialization.json.*
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.core.qualifier.qualifier
|
||||
|
||||
object Plugin : Plugin {
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
single { get<Json>().decodeFromJsonElement(SelectorConfig.serializer(), params["selector"] ?: return@single null) }
|
||||
override fun Module.setupDI(config: JsonObject) {
|
||||
registerConfig<SelectorConfig>("selector") { null }
|
||||
single<KeyValueRepo<PostId, DateTime>>(qualifier("latestChosenRepo")) {
|
||||
ExposedKeyValueRepo(
|
||||
get(),
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.inmo.plaguposter.ratings.source
|
||||
import com.benasher44.uuid.uuid4
|
||||
import dev.inmo.kslog.common.e
|
||||
import dev.inmo.kslog.common.logger
|
||||
import dev.inmo.micro_utils.coroutines.runCatchingLogging
|
||||
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.pagination.firstPageWithOneElementPagination
|
||||
@@ -10,10 +11,12 @@ import dev.inmo.micro_utils.repos.id
|
||||
import dev.inmo.micro_utils.repos.pagination.getAll
|
||||
import dev.inmo.micro_utils.repos.set
|
||||
import dev.inmo.plagubot.Plugin
|
||||
import dev.inmo.plagubot.database
|
||||
import dev.inmo.plaguposter.common.*
|
||||
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.repos.InlineTemplatesRepo
|
||||
import dev.inmo.plagubot.registerConfig
|
||||
import dev.inmo.plaguposter.posts.models.PostId
|
||||
import dev.inmo.plaguposter.posts.panel.PanelButtonBuilder
|
||||
import dev.inmo.plaguposter.posts.panel.PanelButtonsAPI
|
||||
@@ -40,10 +43,11 @@ import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatInlineKeyboard
|
||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard
|
||||
import dev.inmo.tgbotapi.types.ReplyParameters
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton
|
||||
import dev.inmo.tgbotapi.types.message.textsources.bold
|
||||
import dev.inmo.tgbotapi.types.message.textsources.regular
|
||||
import dev.inmo.tgbotapi.types.message.textsources.boldTextSource
|
||||
import dev.inmo.tgbotapi.types.message.textsources.regularTextSource
|
||||
import dev.inmo.tgbotapi.types.polls.InputPollOption
|
||||
import dev.inmo.tgbotapi.types.polls.PollOption
|
||||
import dev.inmo.tgbotapi.utils.bold
|
||||
import dev.inmo.tgbotapi.utils.buildEntities
|
||||
import dev.inmo.tgbotapi.utils.extensions.makeSourceString
|
||||
import kotlinx.coroutines.delay
|
||||
@@ -67,10 +71,8 @@ object Plugin : Plugin {
|
||||
val panelButtonText: String = "Ratings"
|
||||
)
|
||||
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
single {
|
||||
get<Json>().decodeFromJsonElement(Config.serializer(), params["ratingsPolls"] ?: error("Unable to load config for rating polls in $params"))
|
||||
}
|
||||
override fun Module.setupDI(params: JsonObject) {
|
||||
registerConfig<Config>("ratingsPolls")
|
||||
single<RatingsVariants>(ratingVariantsQualifier) { get<Config>().variants }
|
||||
|
||||
single { ExposedPollsToPostsIdsRepo(database) }
|
||||
@@ -198,17 +200,17 @@ object Plugin : Plugin {
|
||||
}
|
||||
|
||||
if (attachPoll(postId)) {
|
||||
runCatchingSafely {
|
||||
runCatchingLogging {
|
||||
edit(
|
||||
it,
|
||||
it.content.textSources + regular(" $SuccessfulSymbol")
|
||||
it.content.textSources + regularTextSource(" $SuccessfulSymbol")
|
||||
)
|
||||
}
|
||||
} else {
|
||||
runCatchingSafely {
|
||||
runCatchingLogging {
|
||||
edit(
|
||||
it,
|
||||
it.content.textSources + regular(" $UnsuccessfulSymbol")
|
||||
it.content.textSources + regularTextSource(" $UnsuccessfulSymbol")
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -233,17 +235,17 @@ object Plugin : Plugin {
|
||||
|
||||
|
||||
if (detachPoll(postId)) {
|
||||
runCatchingSafely {
|
||||
runCatchingLogging {
|
||||
edit(
|
||||
it,
|
||||
it.content.textSources + regular(" $SuccessfulSymbol")
|
||||
it.content.textSources + regularTextSource(" $SuccessfulSymbol")
|
||||
)
|
||||
}
|
||||
} else {
|
||||
runCatchingSafely {
|
||||
runCatchingLogging {
|
||||
edit(
|
||||
it,
|
||||
it.content.textSources + regular(" $UnsuccessfulSymbol")
|
||||
it.content.textSources + regularTextSource(" $UnsuccessfulSymbol")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
18
ratings/src/commonMain/kotlin/models/Config.kt
Normal file
18
ratings/src/commonMain/kotlin/models/Config.kt
Normal file
@@ -0,0 +1,18 @@
|
||||
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,21 +1,30 @@
|
||||
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.koin.singleWithBinds
|
||||
import dev.inmo.micro_utils.repos.unset
|
||||
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.posts.repo.PostsRepo
|
||||
import dev.inmo.plaguposter.ratings.Plugin.setupBotPlugin
|
||||
import dev.inmo.plaguposter.ratings.exposed.ExposedRatingsRepo
|
||||
import dev.inmo.plaguposter.ratings.models.RatingsConfig
|
||||
import dev.inmo.plaguposter.ratings.repo.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.serialization.json.*
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
|
||||
object Plugin : Plugin {
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
private val Log = TagLogger("RatingsPlugin")
|
||||
override fun Module.setupDI(config: JsonObject) {
|
||||
single { ExposedRatingsRepo(database) }
|
||||
singleWithBinds<RatingsRepo> {
|
||||
val base = get<ExposedRatingsRepo>()
|
||||
@@ -26,12 +35,24 @@ object Plugin : Plugin {
|
||||
base
|
||||
}
|
||||
}
|
||||
|
||||
registerConfig(RatingsConfig.serializer(), "ratings") { RatingsConfig() }
|
||||
}
|
||||
|
||||
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
|
||||
override suspend fun startPlugin(koin: Koin) {
|
||||
super.startPlugin(koin)
|
||||
val config = koin.config<RatingsConfig>()
|
||||
val scope = koin.get<CoroutineScope>()
|
||||
val ratingsRepo = koin.get<RatingsRepo>()
|
||||
koin.get<PostsRepo>().deletedObjectsIdsFlow.subscribeSafelyWithoutExceptions(this) {
|
||||
val postsRepo = koin.get<PostsRepo>()
|
||||
postsRepo.deletedObjectsIdsFlow.subscribeSafelyWithoutExceptions(scope) {
|
||||
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,6 +7,7 @@ import dev.inmo.plaguposter.common.SuccessfulSymbol
|
||||
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.repos.InlineTemplatesRepo
|
||||
import dev.inmo.plagubot.registerConfig
|
||||
import dev.inmo.plaguposter.posts.models.PostId
|
||||
import dev.inmo.plaguposter.posts.panel.PanelButtonBuilder
|
||||
import dev.inmo.plaguposter.posts.panel.PanelButtonsAPI
|
||||
@@ -26,7 +27,7 @@ import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatInlineKeyboard
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.types.MessageId
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton
|
||||
import dev.inmo.tgbotapi.types.message.textsources.regular
|
||||
import dev.inmo.tgbotapi.types.message.textsources.regularTextSource
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.*
|
||||
@@ -45,10 +46,8 @@ object Plugin : Plugin {
|
||||
internal data class Config(
|
||||
val panelButtonText: String? = "Publish"
|
||||
)
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
params["publish_command"] ?.let { configJson ->
|
||||
single { get<Json>().decodeFromJsonElement(Config.serializer(), configJson) }
|
||||
}
|
||||
override fun Module.setupDI(params: JsonObject) {
|
||||
registerConfig<Config>("publish_command") { null }
|
||||
}
|
||||
|
||||
override suspend fun BehaviourContextWithFSM<State>.setupBotPlugin(koin: Koin) {
|
||||
@@ -91,7 +90,7 @@ object Plugin : Plugin {
|
||||
|
||||
edit(
|
||||
it,
|
||||
it.content.textSources + regular(SuccessfulSymbol)
|
||||
it.content.textSources + regularTextSource(SuccessfulSymbol)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import dev.inmo.plagubot.Plugin
|
||||
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.repos.InlineTemplatesRepo
|
||||
import dev.inmo.plagubot.registerConfig
|
||||
import dev.inmo.plaguposter.common.ChatConfig
|
||||
import dev.inmo.plaguposter.posts.models.PostId
|
||||
import dev.inmo.plaguposter.posts.repo.ReadPostsRepo
|
||||
@@ -62,8 +63,8 @@ object Plugin : Plugin {
|
||||
@Transient
|
||||
val format: DateFormat = DateFormat(dateTimeFormat)
|
||||
}
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
single { get<Json>().decodeFromJsonElement(Config.serializer(), params["timer_trigger"] ?: return@single null) }
|
||||
override fun Module.setupDI(params: JsonObject) {
|
||||
registerConfig<Config>("timer_trigger") { null }
|
||||
}
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
|
||||
@@ -1,21 +1,15 @@
|
||||
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.singleWithRandomQualifierAndBinds
|
||||
import dev.inmo.micro_utils.pagination.FirstPagePagination
|
||||
import dev.inmo.micro_utils.repos.unset
|
||||
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.timer.TimersRepo
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.serialization.json.*
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.koin.core.module.Module
|
||||
|
||||
object Plugin : Plugin {
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
override fun Module.setupDI(config: JsonObject) {
|
||||
singleWithRandomQualifier<AutopostFilter> {
|
||||
val timersRepo = get<TimersRepo>()
|
||||
AutopostFilter { _, dateTime ->
|
||||
|
||||
@@ -8,11 +8,10 @@ import dev.inmo.plaguposter.ratings.repo.RatingsRepo
|
||||
import dev.inmo.plaguposter.triggers.timer.TimersRepo
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.serialization.json.*
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.koin.core.module.Module
|
||||
|
||||
object Plugin : Plugin {
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
override fun Module.setupDI(config: JsonObject) {
|
||||
singleWithRandomQualifier(createdAtStart = true) {
|
||||
val timersRepo = get<TimersRepo>()
|
||||
val ratingsRepo = get<RatingsRepo>()
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
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.koin.singleWithRandomQualifierAndBinds
|
||||
import dev.inmo.micro_utils.repos.set
|
||||
@@ -9,24 +7,19 @@ import dev.inmo.plagubot.Plugin
|
||||
import dev.inmo.plaguposter.common.ChatConfig
|
||||
import dev.inmo.plaguposter.posts.models.PostId
|
||||
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.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.send
|
||||
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 kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.serialization.json.*
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.dsl.binds
|
||||
|
||||
object Plugin : Plugin {
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
override fun Module.setupDI(config: JsonObject) {
|
||||
single { ExposedTimersRepo(get(), get(), get()) } binds arrayOf(TimersRepo::class)
|
||||
single(createdAtStart = true) { TimersHandler(get(), get(), get()) }
|
||||
singleWithRandomQualifierAndBinds { TimerPanelButton(get()) }
|
||||
|
||||
Reference in New Issue
Block a user