From ceec31220871b75e4133a580fe5df37fd7cad6ec Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 11 Oct 2022 11:28:59 +0600 Subject: [PATCH 01/30] start 0.0.5 --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 5a5466a..09448b3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,5 +10,5 @@ android.enableJetifier=true # Project data group=dev.inmo -version=0.0.4 -android_code_version=4 +version=0.0.5 +android_code_version=5 From e285cc9ec6e886c8c0930a9751624ec8b63d65f8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 11 Oct 2022 11:38:50 +0600 Subject: [PATCH 02/30] deprecate uncommon inline plugin --- gradle/libs.versions.toml | 2 + inlines/build.gradle | 1 + inlines/src/commonMain/kotlin/PackageInfo.kt | 2 +- inlines/src/jvmMain/kotlin/Plugin.kt | 78 +++---------------- inlines/src/jvmMain/kotlin/models/Format.kt | 40 ---------- .../jvmMain/kotlin/models/OfferTemplate.kt | 22 ------ .../kotlin/repos/InlineTemplatesRepo.kt | 16 ---- inlines/src/main/AndroidManifest.xml | 2 +- posts/src/jvmMain/kotlin/Plugin.kt | 6 +- posts_registrar/src/jvmMain/kotlin/Plugin.kt | 6 +- ratings/source/src/jvmMain/kotlin/Plugin.kt | 6 +- runner/config.json | 2 +- sample/config.json | 2 +- triggers/command/src/jvmMain/kotlin/Plugin.kt | 6 +- 14 files changed, 28 insertions(+), 163 deletions(-) delete mode 100644 inlines/src/jvmMain/kotlin/models/Format.kt delete mode 100644 inlines/src/jvmMain/kotlin/models/OfferTemplate.kt delete mode 100644 inlines/src/jvmMain/kotlin/repos/InlineTemplatesRepo.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c5bfc92..b365ec4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,6 +9,7 @@ microutils = "0.12.16" kslog = "0.5.2" krontab = "0.8.1" tgbotapi-libraries = "0.5.5" +plagubot-plugins = "0.4.1" psql = "42.5.0" @@ -36,6 +37,7 @@ android-test-espresso-core = { module = "androidx.test.espresso:espresso-core", tgbotapi = { module = "dev.inmo:tgbotapi", version.ref = "tgbotapi" } plagubot-plugin = { module = "dev.inmo:plagubot.plugin", version.ref = "plagubot" } plagubot-bot = { module = "dev.inmo:plagubot.bot", version.ref = "plagubot" } +plagubot-plugins-inline-queries = { module = "dev.inmo:plagubot.plugins.inline.queries", version.ref = "plagubot-plugins" } microutils-repos-common = { module = "dev.inmo:micro_utils.repos.common", version.ref = "microutils" } microutils-repos-exposed = { module = "dev.inmo:micro_utils.repos.exposed", version.ref = "microutils" } microutils-repos-cache = { module = "dev.inmo:micro_utils.repos.cache", version.ref = "microutils" } diff --git a/inlines/build.gradle b/inlines/build.gradle index c3a8634..e7f55c0 100644 --- a/inlines/build.gradle +++ b/inlines/build.gradle @@ -15,6 +15,7 @@ kotlin { } jvmMain { dependencies { + api libs.plagubot.plugins.inline.queries } } } diff --git a/inlines/src/commonMain/kotlin/PackageInfo.kt b/inlines/src/commonMain/kotlin/PackageInfo.kt index 848be3b..434bc2c 100644 --- a/inlines/src/commonMain/kotlin/PackageInfo.kt +++ b/inlines/src/commonMain/kotlin/PackageInfo.kt @@ -1 +1 @@ -package dev.inmo.plaguposter.inlines +package dev.inmo.plagubot.plugins.inline.queries diff --git a/inlines/src/jvmMain/kotlin/Plugin.kt b/inlines/src/jvmMain/kotlin/Plugin.kt index 98550a5..0b94aa7 100644 --- a/inlines/src/jvmMain/kotlin/Plugin.kt +++ b/inlines/src/jvmMain/kotlin/Plugin.kt @@ -1,81 +1,21 @@ package dev.inmo.plaguposter.inlines -import dev.inmo.micro_utils.pagination.Pagination -import dev.inmo.micro_utils.pagination.utils.paginate +import dev.inmo.kslog.common.TagLogger +import dev.inmo.kslog.common.w import dev.inmo.plagubot.Plugin -import dev.inmo.plaguposter.common.ChatConfig -import dev.inmo.plaguposter.inlines.models.Format -import dev.inmo.plaguposter.inlines.models.OfferTemplate -import dev.inmo.plaguposter.inlines.repos.InlineTemplatesRepo -import dev.inmo.tgbotapi.bot.exceptions.RequestException -import dev.inmo.tgbotapi.extensions.api.answers.answerInlineQuery -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.onBaseInlineQuery -import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand -import dev.inmo.tgbotapi.extensions.utils.types.buttons.* -import dev.inmo.tgbotapi.types.inlineQueryAnswerResultsLimit -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 -object Plugin : Plugin { - @Serializable - internal data class Config( - val preset: List - ) - override fun Module.setupDI(database: Database, params: JsonObject) { - single { get().decodeFromJsonElement(Config.serializer(), params["inlines"] ?: return@single Config(emptyList())) } - single { InlineTemplatesRepo(getOrNull() ?.preset ?.toMutableSet() ?: mutableSetOf()) } - } +private val actualPlugin = dev.inmo.plagubot.plugins.inline.queries.Plugin +object Plugin : Plugin by actualPlugin { + private val log = TagLogger("InlinePlugin") override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) { - val templatesRepo = koin.get() - onBaseInlineQuery { query -> - val page = query.offset.toIntOrNull() ?: 0 - val queryString = query.query.trim() - try { - answerInlineQuery( - query, - templatesRepo.templates.paginate( - Pagination( - page, - inlineQueryAnswerResultsLimit.last + 1 - ) - ).results.mapIndexedNotNull { index, offerTemplate -> - offerTemplate.createArticleResult( - index.toString(), - queryString - ) - }, - nextOffset = (page + 1).toString(), - cachedTime = 0 - ) - } catch (e: RequestException) { - bot.answerInlineQuery( - query, - cachedTime = 0 - ) - } + log.w { + "Built-in inline plugin has been deprecated. Use \"${actualPlugin::class.qualifiedName}\" instead" } - onCommand("help", requireOnlyCommandInMessage = true) { - reply( - it, - "Push the button above to see available commands", - replyMarkup = flatInlineKeyboard { - inlineQueryInCurrentChatButton("Toggle commands", "") - } - ) - } - koin.getOrNull() ?.apply { - addTemplate( - OfferTemplate( - "Trigger help button", - listOf(Format("/help")) - ) - ) + with(actualPlugin) { + setupBotPlugin(koin) } } } diff --git a/inlines/src/jvmMain/kotlin/models/Format.kt b/inlines/src/jvmMain/kotlin/models/Format.kt deleted file mode 100644 index 9b88dbf..0000000 --- a/inlines/src/jvmMain/kotlin/models/Format.kt +++ /dev/null @@ -1,40 +0,0 @@ -package dev.inmo.plaguposter.inlines.models - -import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent -import dev.inmo.tgbotapi.types.message.MarkdownV2 -import kotlinx.serialization.Serializable -import kotlinx.serialization.Transient - -@Serializable -data class Format( - val template: String, - val regexTemplate: String = "^$", - val splitBy: String? = null, - val enableMarkdownSupport: Boolean = false -) { - @Transient - val queryRegex = Regex(regexTemplate, RegexOption.DOT_MATCHES_ALL) - - init { - println(queryRegex) - } - - fun formatByRegex(with: String): String? { - return if (queryRegex.matches(with)) { - template.format(*(splitBy ?.let { with.split(it).toTypedArray() } ?: arrayOf(with))) - } else { - null - } - } - - fun createContent(with: String): InputTextMessageContent? { - return if (queryRegex.matches(with)) { - InputTextMessageContent( - template.format(*(splitBy ?.let { with.split(it).toTypedArray() } ?: arrayOf(with))), - if (enableMarkdownSupport) MarkdownV2 else null - ) - } else { - null - } - } -} diff --git a/inlines/src/jvmMain/kotlin/models/OfferTemplate.kt b/inlines/src/jvmMain/kotlin/models/OfferTemplate.kt deleted file mode 100644 index 55466d1..0000000 --- a/inlines/src/jvmMain/kotlin/models/OfferTemplate.kt +++ /dev/null @@ -1,22 +0,0 @@ -package dev.inmo.plaguposter.inlines.models - -import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle -import kotlinx.serialization.Serializable - -@Serializable -data class OfferTemplate( - val title: String, - val formats: List = emptyList(), - val description: String? = null -) { - fun createArticleResult(id: String, query: String): InlineQueryResultArticle? = formats.firstOrNull { - it.queryRegex.matches(query) - } ?.createContent(query) ?.let { content -> - InlineQueryResultArticle( - id, - title, - content, - description = description - ) - } -} diff --git a/inlines/src/jvmMain/kotlin/repos/InlineTemplatesRepo.kt b/inlines/src/jvmMain/kotlin/repos/InlineTemplatesRepo.kt deleted file mode 100644 index 57b34d5..0000000 --- a/inlines/src/jvmMain/kotlin/repos/InlineTemplatesRepo.kt +++ /dev/null @@ -1,16 +0,0 @@ -package dev.inmo.plaguposter.inlines.repos - -import dev.inmo.plaguposter.inlines.models.OfferTemplate - -class InlineTemplatesRepo( - private val _templates: MutableSet -) { - internal val templates - get() = _templates.toList() - suspend fun addTemplate(offerTemplate: OfferTemplate): Boolean { - return _templates.add(offerTemplate) - } - suspend fun dropTemplate(offerTemplate: OfferTemplate): Boolean { - return _templates.remove(offerTemplate) - } -} diff --git a/inlines/src/main/AndroidManifest.xml b/inlines/src/main/AndroidManifest.xml index 41df2ea..4dbbf06 100644 --- a/inlines/src/main/AndroidManifest.xml +++ b/inlines/src/main/AndroidManifest.xml @@ -1 +1 @@ - + diff --git a/posts/src/jvmMain/kotlin/Plugin.kt b/posts/src/jvmMain/kotlin/Plugin.kt index 7b53695..c56f832 100644 --- a/posts/src/jvmMain/kotlin/Plugin.kt +++ b/posts/src/jvmMain/kotlin/Plugin.kt @@ -10,9 +10,9 @@ import dev.inmo.plaguposter.common.SuccessfulSymbol import dev.inmo.plaguposter.common.UnsuccessfulSymbol import dev.inmo.plaguposter.posts.exposed.ExposedPostsRepo import dev.inmo.plaguposter.common.ChatConfig -import dev.inmo.plaguposter.inlines.models.Format -import dev.inmo.plaguposter.inlines.models.OfferTemplate -import dev.inmo.plaguposter.inlines.repos.InlineTemplatesRepo +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.plaguposter.posts.repo.* import dev.inmo.plaguposter.posts.sending.PostPublisher import dev.inmo.tgbotapi.extensions.api.delete diff --git a/posts_registrar/src/jvmMain/kotlin/Plugin.kt b/posts_registrar/src/jvmMain/kotlin/Plugin.kt index 8840e6a..3eef447 100644 --- a/posts_registrar/src/jvmMain/kotlin/Plugin.kt +++ b/posts_registrar/src/jvmMain/kotlin/Plugin.kt @@ -5,9 +5,9 @@ import dev.inmo.micro_utils.fsm.common.State import dev.inmo.micro_utils.repos.create import dev.inmo.plagubot.Plugin import dev.inmo.plaguposter.common.* -import dev.inmo.plaguposter.inlines.models.Format -import dev.inmo.plaguposter.inlines.models.OfferTemplate -import dev.inmo.plaguposter.inlines.repos.InlineTemplatesRepo +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.plaguposter.posts.models.* import dev.inmo.plaguposter.posts.registrar.state.RegistrationState import dev.inmo.plaguposter.posts.repo.PostsRepo diff --git a/ratings/source/src/jvmMain/kotlin/Plugin.kt b/ratings/source/src/jvmMain/kotlin/Plugin.kt index 9cb3228..6c58f56 100644 --- a/ratings/source/src/jvmMain/kotlin/Plugin.kt +++ b/ratings/source/src/jvmMain/kotlin/Plugin.kt @@ -11,9 +11,9 @@ import dev.inmo.micro_utils.repos.pagination.getAll import dev.inmo.micro_utils.repos.set import dev.inmo.plagubot.Plugin import dev.inmo.plaguposter.common.* -import dev.inmo.plaguposter.inlines.models.Format -import dev.inmo.plaguposter.inlines.models.OfferTemplate -import dev.inmo.plaguposter.inlines.repos.InlineTemplatesRepo +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.plaguposter.posts.models.PostId import dev.inmo.plaguposter.posts.panel.PanelButtonBuilder import dev.inmo.plaguposter.posts.panel.PanelButtonsAPI diff --git a/runner/config.json b/runner/config.json index 93e4b88..4ba4f3a 100644 --- a/runner/config.json +++ b/runner/config.json @@ -7,13 +7,13 @@ }, "botToken": "1234567890:ABCDEFGHIJKLMNOP_qrstuvwxyz12345678", "plugins": [ + "dev.inmo.plagubot.plugins.inline.queries.Plugin", "dev.inmo.plaguposter.posts.Plugin", "dev.inmo.plaguposter.posts.registrar.Plugin", "dev.inmo.plaguposter.ratings.Plugin", "dev.inmo.plaguposter.ratings.source.Plugin", "dev.inmo.plaguposter.ratings.selector.Plugin", "dev.inmo.plaguposter.triggers.selector_with_timer.Plugin", - "dev.inmo.plaguposter.inlines.Plugin", "dev.inmo.plaguposter.triggers.command.Plugin", "dev.inmo.plaguposter.posts.panel.Plugin" ], diff --git a/sample/config.json b/sample/config.json index 91f1d29..a8fd9be 100644 --- a/sample/config.json +++ b/sample/config.json @@ -14,7 +14,7 @@ "dev.inmo.plaguposter.ratings.selector.Plugin", "dev.inmo.plaguposter.triggers.selector_with_timer.Plugin", "dev.inmo.plaguposter.ratings.gc.Plugin", - "dev.inmo.plaguposter.inlines.Plugin", + "dev.inmo.plagubot.plugins.inline.queries.Plugin", "dev.inmo.plaguposter.triggers.command.Plugin" ], "posts": { diff --git a/triggers/command/src/jvmMain/kotlin/Plugin.kt b/triggers/command/src/jvmMain/kotlin/Plugin.kt index 5423728..23e86e1 100644 --- a/triggers/command/src/jvmMain/kotlin/Plugin.kt +++ b/triggers/command/src/jvmMain/kotlin/Plugin.kt @@ -7,9 +7,9 @@ import dev.inmo.micro_utils.pagination.firstPageWithOneElementPagination import dev.inmo.plagubot.Plugin import dev.inmo.plaguposter.common.SuccessfulSymbol import dev.inmo.plaguposter.common.UnsuccessfulSymbol -import dev.inmo.plaguposter.inlines.models.Format -import dev.inmo.plaguposter.inlines.models.OfferTemplate -import dev.inmo.plaguposter.inlines.repos.InlineTemplatesRepo +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.plaguposter.posts.models.PostId import dev.inmo.plaguposter.posts.panel.PanelButtonBuilder import dev.inmo.plaguposter.posts.panel.PanelButtonsAPI From 6a43cb32c6aed71a88ce20220f60eef1a7f8f1d1 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 11 Oct 2022 11:43:09 +0600 Subject: [PATCH 03/30] init scheduling trigger --- settings.gradle | 1 + .../selector_with_scheduling/build.gradle | 21 +++++++++++++++++++ .../src/commonMain/kotlin/PackageInfo.kt | 1 + .../src/jvmMain/kotlin/Plugin.kt | 11 ++++++++++ .../src/main/AndroidManifest.xml | 1 + 5 files changed, 35 insertions(+) create mode 100644 triggers/selector_with_scheduling/build.gradle create mode 100644 triggers/selector_with_scheduling/src/commonMain/kotlin/PackageInfo.kt create mode 100644 triggers/selector_with_scheduling/src/jvmMain/kotlin/Plugin.kt create mode 100644 triggers/selector_with_scheduling/src/main/AndroidManifest.xml diff --git a/settings.gradle b/settings.gradle index 4cfbdc9..4974edb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -11,6 +11,7 @@ String[] includes = [ ":ratings:gc", ":triggers:command", ":triggers:selector_with_timer", + ":triggers:selector_with_scheduling", ":inlines", // ":settings", ":runner" diff --git a/triggers/selector_with_scheduling/build.gradle b/triggers/selector_with_scheduling/build.gradle new file mode 100644 index 0000000..c3a8634 --- /dev/null +++ b/triggers/selector_with_scheduling/build.gradle @@ -0,0 +1,21 @@ +plugins { + id "org.jetbrains.kotlin.multiplatform" + id "org.jetbrains.kotlin.plugin.serialization" + id "com.android.library" +} + +apply from: "$mppProjectWithSerializationPresetPath" + +kotlin { + sourceSets { + commonMain { + dependencies { + api project(":plaguposter.common") + } + } + jvmMain { + dependencies { + } + } + } +} diff --git a/triggers/selector_with_scheduling/src/commonMain/kotlin/PackageInfo.kt b/triggers/selector_with_scheduling/src/commonMain/kotlin/PackageInfo.kt new file mode 100644 index 0000000..6b58a49 --- /dev/null +++ b/triggers/selector_with_scheduling/src/commonMain/kotlin/PackageInfo.kt @@ -0,0 +1 @@ +package dev.inmo.plaguposter.triggers.selector_with_scheduling diff --git a/triggers/selector_with_scheduling/src/jvmMain/kotlin/Plugin.kt b/triggers/selector_with_scheduling/src/jvmMain/kotlin/Plugin.kt new file mode 100644 index 0000000..d360aa8 --- /dev/null +++ b/triggers/selector_with_scheduling/src/jvmMain/kotlin/Plugin.kt @@ -0,0 +1,11 @@ +package dev.inmo.plaguposter.triggers.selector_with_scheduling + +import dev.inmo.plagubot.Plugin +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) { + } +} diff --git a/triggers/selector_with_scheduling/src/main/AndroidManifest.xml b/triggers/selector_with_scheduling/src/main/AndroidManifest.xml new file mode 100644 index 0000000..acdf85d --- /dev/null +++ b/triggers/selector_with_scheduling/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + From 4ac30cc6670fc3984ae29132209dfc48c7a4d5fa Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:01:49 +0600 Subject: [PATCH 04/30] Update libs.versions.toml --- gradle/libs.versions.toml | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b365ec4..ceb08c3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,28 +1,18 @@ [versions] -kotlin = "1.7.10" -kotlin-serialization = "1.4.0" +kotlin = "1.7.20" +kotlin-serialization = "1.4.1" -plagubot = "2.3.4" -tgbotapi = "3.2.7" -microutils = "0.12.16" +plagubot = "2.4.0" +tgbotapi = "3.3.0" +microutils = "0.13.1" kslog = "0.5.2" krontab = "0.8.1" -tgbotapi-libraries = "0.5.5" -plagubot-plugins = "0.4.1" +tgbotapi-libraries = "0.5.6" +plagubot-plugins = "0.5.0" psql = "42.5.0" -dexcount = "3.1.0" -junit_version = "4.12" -test_ext_junit_version = "1.1.3" -espresso_core = "3.4.0" - -android-gradle-plugin = "7.2.2" -android-minSdk = "21" -android-compileSdk = "33" -android-buildTools = "33.0.0" - [libraries] kotlin = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" } @@ -49,8 +39,6 @@ psql = { module = "org.postgresql:postgresql", version.ref = "psql" } # buildscript classpaths -android-tools-build = { module = "com.android.tools.build:gradle", version.ref = "android-gradle-plugin" } -android-dexcount = { module = "com.getkeepsafe.dexcount:dexcount-gradle-plugin", version.ref = "dexcount" } kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } kotlin-serialization-plugin = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" } kotlin-dokka-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "kotlin" } From 5ae07394dcd40ee83f0841d25fe88c3226e16f17 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:06:56 +0600 Subject: [PATCH 05/30] Delete defaultAndroidSettings.gradle --- defaultAndroidSettings.gradle | 66 ----------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 defaultAndroidSettings.gradle diff --git a/defaultAndroidSettings.gradle b/defaultAndroidSettings.gradle deleted file mode 100644 index 1902595..0000000 --- a/defaultAndroidSettings.gradle +++ /dev/null @@ -1,66 +0,0 @@ -apply plugin: 'com.getkeepsafe.dexcount' - -android { - ext { - jvmKotlinFolderFile = { - String sep = File.separator - return new File("${project.projectDir}${sep}src${sep}jvmMain${sep}kotlin") - } - - enableIncludingJvmCodeInAndroidPart = { - File jvmKotlinFolder = jvmKotlinFolderFile() - if (jvmKotlinFolder.exists()) { - android.sourceSets.main.java.srcDirs += jvmKotlinFolder.path - } - } - - disableIncludingJvmCodeInAndroidPart = { - File jvmKotlinFolder = jvmKotlinFolderFile() - String[] oldDirs = android.sourceSets.main.java.srcDirs - android.sourceSets.main.java.srcDirs = [] - for (oldDir in oldDirs) { - if (oldDir != jvmKotlinFolder.path) { - android.sourceSets.main.java.srcDirs += oldDir - } - } - } - } - - compileSdkVersion libs.versions.android.compileSdk.get().toInteger() - buildToolsVersion libs.versions.android.buildTools.get() - - defaultConfig { - minSdkVersion libs.versions.android.minSdk.get().toInteger() - targetSdkVersion libs.versions.android.compileSdk.get().toInteger() - versionCode "${android_code_version}".toInteger() - versionName "$version" - } - buildTypes { - release { - minifyEnabled false - } - debug { - debuggable true - } - } - - packagingOptions { - exclude 'META-INF/kotlinx-serialization-runtime.kotlin_module' - exclude 'META-INF/kotlinx-serialization-cbor.kotlin_module' - exclude 'META-INF/kotlinx-serialization-properties.kotlin_module' - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - - kotlinOptions { - jvmTarget = JavaVersion.VERSION_1_8.toString() - } - - sourceSets { - String sep = File.separator - main.java.srcDirs += "src${sep}main${sep}kotlin" - } -} From eef167422e3de60fb838cc54f46b64714d8389fe Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:07:43 +0600 Subject: [PATCH 06/30] Delete mppAndroidProject.gradle --- mppAndroidProject.gradle | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 mppAndroidProject.gradle diff --git a/mppAndroidProject.gradle b/mppAndroidProject.gradle deleted file mode 100644 index ad4e0d9..0000000 --- a/mppAndroidProject.gradle +++ /dev/null @@ -1,34 +0,0 @@ -project.version = "$version" -project.group = "$group" - -// apply from: "$publishGradlePath" - -kotlin { - android { - publishAllLibraryVariants() - } - - sourceSets { - commonMain { - dependencies { - implementation libs.kotlin - api libs.kotlin.serialization - } - } - commonTest { - dependencies { - implementation libs.kotlin.test.common - implementation libs.kotlin.test.annotations.common - } - } - androidTest { - dependencies { - implementation libs.kotlin.test.junit - implementation libs.android.test.junit - implementation libs.android.test.espresso.core - } - } - } -} - -apply from: "$defaultAndroidSettingsPresetPath" From 3d5e15d5456ce48f77d16fda292736fe0c000a49 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:09:18 +0600 Subject: [PATCH 07/30] Update mppProjectWithSerialization.gradle --- mppProjectWithSerialization.gradle | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/mppProjectWithSerialization.gradle b/mppProjectWithSerialization.gradle index 2a92bfb..3535b6e 100644 --- a/mppProjectWithSerialization.gradle +++ b/mppProjectWithSerialization.gradle @@ -15,10 +15,7 @@ kotlin { browser() nodejs() } - android { - publishAllLibraryVariants() - } - + sourceSets { commonMain { dependencies { @@ -43,13 +40,7 @@ kotlin { implementation libs.kotlin.test.junit } } - androidTest { - dependencies { - implementation libs.kotlin.test.junit - implementation libs.android.test.junit - implementation libs.android.test.espresso.core - } - } + } } @@ -58,4 +49,3 @@ java { targetCompatibility = JavaVersion.VERSION_1_8 } -apply from: "$defaultAndroidSettingsPresetPath" From f4e097f7d1e14232e9b4f75affbe50c6d42e7006 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:10:34 +0600 Subject: [PATCH 08/30] Update mppProjectWithSerialization.gradle --- mppProjectWithSerialization.gradle | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/mppProjectWithSerialization.gradle b/mppProjectWithSerialization.gradle index 3535b6e..7caf028 100644 --- a/mppProjectWithSerialization.gradle +++ b/mppProjectWithSerialization.gradle @@ -4,13 +4,7 @@ project.group = "$group" // apply from: "$publishGradlePath" kotlin { - jvm { - compilations.main { - kotlinOptions { - jvmTarget = "1.8" - } - } - } + jvm() js (IR) { browser() nodejs() @@ -44,8 +38,3 @@ kotlin { } } -java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 -} - From 3e62eca8acc7054a4c01b937b2d1a71ef7d12446 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:12:27 +0600 Subject: [PATCH 09/30] Update libs.versions.toml --- gradle/libs.versions.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ceb08c3..b0b057f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,6 +13,9 @@ plagubot-plugins = "0.5.0" psql = "42.5.0" +junit_version = "4.12" +test_ext_junit_version = "1.1.3" + [libraries] kotlin = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" } From ad98ca339dd22236a4d798c647f24397eb6abb8f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:14:02 +0600 Subject: [PATCH 10/30] Update libs.versions.toml --- gradle/libs.versions.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b0b057f..8b65e71 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -24,8 +24,6 @@ kotlin-test-common = { module = "org.jetbrains.kotlin:kotlin-test-common", versi kotlin-test-annotations-common = { module = "org.jetbrains.kotlin:kotlin-test-annotations-common", version.ref = "kotlin" } kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" } kotlin-test-js = { module = "org.jetbrains.kotlin:kotlin-test-js", version.ref = "kotlin" } -android-test-junit = { module = "androidx.test.ext:junit", version.ref = "test_ext_junit_version" } -android-test-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espresso_core" } tgbotapi = { module = "dev.inmo:tgbotapi", version.ref = "tgbotapi" } plagubot-plugin = { module = "dev.inmo:plagubot.plugin", version.ref = "plagubot" } From 6389912b1d84bdda71265356e184b32f58c5fba5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:14:45 +0600 Subject: [PATCH 11/30] Update libs.versions.toml --- gradle/libs.versions.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8b65e71..419af72 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,9 +13,6 @@ plagubot-plugins = "0.5.0" psql = "42.5.0" -junit_version = "4.12" -test_ext_junit_version = "1.1.3" - [libraries] kotlin = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" } From c55376da88f35cff51bb281d1544113d4667c73c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:16:32 +0600 Subject: [PATCH 12/30] Update build.gradle --- build.gradle | 2 -- 1 file changed, 2 deletions(-) diff --git a/build.gradle b/build.gradle index 36c0e25..80d7b89 100644 --- a/build.gradle +++ b/build.gradle @@ -7,8 +7,6 @@ buildscript { } dependencies { - classpath libs.android.tools.build - classpath libs.android.dexcount classpath libs.kotlin.gradle.plugin classpath libs.kotlin.serialization.plugin classpath libs.kotlin.dokka.plugin From 6b82879a3ec0f64f368c697a5a2dcbff00ddc9d5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:17:52 +0600 Subject: [PATCH 13/30] Update build.gradle --- triggers/selector_with_timer/build.gradle | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/triggers/selector_with_timer/build.gradle b/triggers/selector_with_timer/build.gradle index eadb025..b9d3bca 100644 --- a/triggers/selector_with_timer/build.gradle +++ b/triggers/selector_with_timer/build.gradle @@ -1,7 +1,7 @@ plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.plugin.serialization" - id "com.android.library" + } apply from: "$mppProjectWithSerializationPresetPath" @@ -16,9 +16,5 @@ kotlin { api libs.krontab } } - jvmMain { - dependencies { - } - } } } From e114d74c74a18d728a635e1a92741a522fb49740 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:18:27 +0600 Subject: [PATCH 14/30] Update build.gradle --- triggers/selector_with_scheduling/build.gradle | 5 ----- 1 file changed, 5 deletions(-) diff --git a/triggers/selector_with_scheduling/build.gradle b/triggers/selector_with_scheduling/build.gradle index c3a8634..f95f579 100644 --- a/triggers/selector_with_scheduling/build.gradle +++ b/triggers/selector_with_scheduling/build.gradle @@ -1,7 +1,6 @@ plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.plugin.serialization" - id "com.android.library" } apply from: "$mppProjectWithSerializationPresetPath" @@ -13,9 +12,5 @@ kotlin { api project(":plaguposter.common") } } - jvmMain { - dependencies { - } - } } } From 1ad7988ae5d9db24962467382255c8876250723a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:18:59 +0600 Subject: [PATCH 15/30] Update build.gradle --- triggers/command/build.gradle | 5 ----- 1 file changed, 5 deletions(-) diff --git a/triggers/command/build.gradle b/triggers/command/build.gradle index 3f51e34..3c42554 100644 --- a/triggers/command/build.gradle +++ b/triggers/command/build.gradle @@ -1,7 +1,6 @@ plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.plugin.serialization" - id "com.android.library" } apply from: "$mppProjectWithSerializationPresetPath" @@ -16,9 +15,5 @@ kotlin { api project(":plaguposter.posts.panel") } } - jvmMain { - dependencies { - } - } } } From b398ad43ab85cb6446a3eaa4faf40c67d422ba8b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:20:37 +0600 Subject: [PATCH 16/30] Update build.gradle --- template/build.gradle | 5 ----- 1 file changed, 5 deletions(-) diff --git a/template/build.gradle b/template/build.gradle index c3a8634..f95f579 100644 --- a/template/build.gradle +++ b/template/build.gradle @@ -1,7 +1,6 @@ plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.plugin.serialization" - id "com.android.library" } apply from: "$mppProjectWithSerializationPresetPath" @@ -13,9 +12,5 @@ kotlin { api project(":plaguposter.common") } } - jvmMain { - dependencies { - } - } } } From 851f3a1c554e0d1781fbe9dffe45ff60f186e836 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:21:09 +0600 Subject: [PATCH 17/30] Update build.gradle --- settings/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/settings/build.gradle b/settings/build.gradle index d101bd6..a0d2361 100644 --- a/settings/build.gradle +++ b/settings/build.gradle @@ -1,7 +1,6 @@ plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.plugin.serialization" - id "com.android.library" } apply from: "$mppProjectWithSerializationPresetPath" From 8f29810291cbc16e8ff4612d4ac61b881036c6ee Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:21:37 +0600 Subject: [PATCH 18/30] Update build.gradle --- ratings/build.gradle | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ratings/build.gradle b/ratings/build.gradle index 779ca41..3793d30 100644 --- a/ratings/build.gradle +++ b/ratings/build.gradle @@ -1,7 +1,6 @@ plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.plugin.serialization" - id "com.android.library" } apply from: "$mppProjectWithSerializationPresetPath" @@ -14,9 +13,5 @@ kotlin { api project(":plaguposter.posts") } } - jvmMain { - dependencies { - } - } } } From 4aae1230bc261ae45f6dae333daba9b31d5dffa3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:22:12 +0600 Subject: [PATCH 19/30] Update build.gradle --- ratings/source/build.gradle | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ratings/source/build.gradle b/ratings/source/build.gradle index 2c08fa6..ca1b256 100644 --- a/ratings/source/build.gradle +++ b/ratings/source/build.gradle @@ -1,7 +1,6 @@ plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.plugin.serialization" - id "com.android.library" } apply from: "$mppProjectWithSerializationPresetPath" @@ -15,9 +14,5 @@ kotlin { api project(":plaguposter.posts.panel") } } - jvmMain { - dependencies { - } - } } } From a563267da06bbe56186ef1519202edfb1ffd6b0b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:22:43 +0600 Subject: [PATCH 20/30] Update build.gradle --- posts_registrar/build.gradle | 5 ----- 1 file changed, 5 deletions(-) diff --git a/posts_registrar/build.gradle b/posts_registrar/build.gradle index 054bb15..bb85922 100644 --- a/posts_registrar/build.gradle +++ b/posts_registrar/build.gradle @@ -1,7 +1,6 @@ plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.plugin.serialization" - id "com.android.library" } apply from: "$mppProjectWithSerializationPresetPath" @@ -13,9 +12,5 @@ kotlin { api project(":plaguposter.posts") } } - jvmMain { - dependencies { - } - } } } From 5ea80ca1e5067d25bb8df10f90874f991be6b7b6 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:23:08 +0600 Subject: [PATCH 21/30] Update build.gradle --- posts/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/posts/build.gradle b/posts/build.gradle index 9f6c3cb..f2974dd 100644 --- a/posts/build.gradle +++ b/posts/build.gradle @@ -1,7 +1,6 @@ plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.plugin.serialization" - id "com.android.library" } apply from: "$mppProjectWithSerializationPresetPath" From bf8436fa4b215041c5407012d6d927b5242f66a6 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:24:05 +0600 Subject: [PATCH 22/30] Update build.gradle --- inlines/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/inlines/build.gradle b/inlines/build.gradle index e7f55c0..8c6e39f 100644 --- a/inlines/build.gradle +++ b/inlines/build.gradle @@ -1,7 +1,6 @@ plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.plugin.serialization" - id "com.android.library" } apply from: "$mppProjectWithSerializationPresetPath" From 94b3c97efaa73d7672df87c78dbbd0da91587f75 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:24:38 +0600 Subject: [PATCH 23/30] Update build.gradle --- ratings/gc/build.gradle | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ratings/gc/build.gradle b/ratings/gc/build.gradle index ebfe6d4..d8e5ff2 100644 --- a/ratings/gc/build.gradle +++ b/ratings/gc/build.gradle @@ -1,7 +1,6 @@ plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.plugin.serialization" - id "com.android.library" } apply from: "$mppProjectWithSerializationPresetPath" @@ -15,9 +14,5 @@ kotlin { api libs.krontab } } - jvmMain { - dependencies { - } - } } } From 100ee1520f141421539f04bc35349ebf84d5cfc7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:25:06 +0600 Subject: [PATCH 24/30] Update build.gradle --- ratings/selector/build.gradle | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ratings/selector/build.gradle b/ratings/selector/build.gradle index ea7c956..40f207d 100644 --- a/ratings/selector/build.gradle +++ b/ratings/selector/build.gradle @@ -1,7 +1,6 @@ plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.plugin.serialization" - id "com.android.library" } apply from: "$mppProjectWithSerializationPresetPath" @@ -14,9 +13,5 @@ kotlin { api project(":plaguposter.ratings") } } - jvmMain { - dependencies { - } - } } } From 2daaf8a6b3b5c38bbb5f8570c5cb6972f0aef947 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:27:01 +0600 Subject: [PATCH 25/30] Update build.gradle --- common/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/common/build.gradle b/common/build.gradle index a210d1d..127edfe 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,7 +1,6 @@ plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.plugin.serialization" - id "com.android.library" } apply from: "$mppProjectWithSerializationPresetPath" From c8085701d4bde80cab6488818c5759803aff9fe5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:29:11 +0600 Subject: [PATCH 26/30] Update build.gradle --- posts/panel/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/posts/panel/build.gradle b/posts/panel/build.gradle index 3595568..eda422f 100644 --- a/posts/panel/build.gradle +++ b/posts/panel/build.gradle @@ -1,7 +1,6 @@ plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.plugin.serialization" - id "com.android.library" } apply from: "$mppProjectWithSerializationPresetPath" From a3ee0d4c3b5922fa8b92e8bd52798d923f852043 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 00:29:47 +0600 Subject: [PATCH 27/30] Update build.yml --- .github/workflows/build.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 105c99f..65f648c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,8 +12,5 @@ jobs: uses: actions/setup-java@v1 with: java-version: 11 - - name: Fix android 32.0.0 dx - continue-on-error: true - run: cd /usr/local/lib/android/sdk/build-tools/32.0.0/ && mv d8 dx && cd lib && mv d8.jar dx.jar - name: Build with Gradle run: ./gradlew build From 4c8c93c9f8a1831d3c375fd8a1b0c994235c60bf Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 12:43:12 +0600 Subject: [PATCH 28/30] update ExposedPostsRepo --- .../kotlin/exposed/ExposedPostsRepo.kt | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt b/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt index c509840..4ee12cf 100644 --- a/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt +++ b/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt @@ -12,8 +12,7 @@ import dev.inmo.tgbotapi.types.MessageIdentifier import kotlinx.coroutines.flow.* import kotlinx.serialization.json.Json import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.statements.InsertStatement -import org.jetbrains.exposed.sql.statements.UpdateStatement +import org.jetbrains.exposed.sql.statements.* import org.jetbrains.exposed.sql.transactions.transaction class ExposedPostsRepo( @@ -21,7 +20,7 @@ class ExposedPostsRepo( ) : PostsRepo, AbstractExposedCRUDRepo( tableName = "posts" ) { - val idColumn = text("id").clientDefault { uuid4().toString() } + val idColumn = text("id") val createdColumn = double("datetime").default(0.0) private val contentRepo by lazy { @@ -59,18 +58,6 @@ class ExposedPostsRepo( override fun InsertStatement.asObject(value: NewPost): RegisteredPost { val id = PostId(get(idColumn)) - with(contentRepo) { - value.content.forEach { contentInfo -> - insert { - it[postIdColumn] = id.string - it[chatIdColumn] = contentInfo.chatId.chatId - it[messageIdColumn] = contentInfo.messageId - it[groupColumn] = contentInfo.group - it[orderColumn] = contentInfo.order - } - } - } - return RegisteredPost( id, DateTime(get(createdColumn)), @@ -82,7 +69,14 @@ class ExposedPostsRepo( ) } - override fun update(id: PostId, value: NewPost, it: UpdateStatement) { + override fun createAndInsertId(value: NewPost, it: InsertStatement): PostId { + val id = PostId(uuid4().toString()) + it[idColumn] = id.string + return id + } + + override fun update(id: PostId?, value: NewPost, it: UpdateBuilder) { + id ?: error("Unable to find post id in update") with(contentRepo) { deleteWhere { postIdColumn.eq(id.string) } value.content.forEach { contentInfo -> @@ -98,6 +92,7 @@ class ExposedPostsRepo( } override fun insert(value: NewPost, it: InsertStatement) { + super.insert(value, it) it[createdColumn] = DateTime.now().unixMillis } From c47c7b09f435b526875bb74ec831a15b622313e5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 12:46:31 +0600 Subject: [PATCH 29/30] fixes in exposed tables --- .../kotlin/repos/ExposedPollsToMessagesInfoRepo.kt | 9 +++------ .../jvmMain/kotlin/repos/ExposedPollsToPostsIdsRepo.kt | 8 +++----- ratings/src/jvmMain/kotlin/exposed/ExposedRatingsRepo.kt | 8 +++----- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToMessagesInfoRepo.kt b/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToMessagesInfoRepo.kt index bd0f9d3..7f73962 100644 --- a/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToMessagesInfoRepo.kt +++ b/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToMessagesInfoRepo.kt @@ -6,8 +6,7 @@ import dev.inmo.plaguposter.common.ShortMessageInfo import dev.inmo.tgbotapi.types.ChatId import dev.inmo.tgbotapi.types.PollIdentifier import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.statements.InsertStatement -import org.jetbrains.exposed.sql.statements.UpdateStatement +import org.jetbrains.exposed.sql.statements.* class ExposedPollsToMessagesInfoRepo( database: Database @@ -36,14 +35,12 @@ class ExposedPollsToMessagesInfoRepo( initTable() } - override fun update(k: PollIdentifier, v: ShortMessageInfo, it: UpdateStatement) { + override fun update(k: PollIdentifier, v: ShortMessageInfo, it: UpdateBuilder) { it[chatIdColumn] = v.chatId.chatId it[messageIdColumn] = v.messageId } - override fun insert(k: PollIdentifier, v: ShortMessageInfo, it: InsertStatement) { + override fun insertKey(k: PollIdentifier, v: ShortMessageInfo, it: InsertStatement) { it[keyColumn] = k - it[chatIdColumn] = v.chatId.chatId - it[messageIdColumn] = v.messageId } } diff --git a/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToPostsIdsRepo.kt b/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToPostsIdsRepo.kt index 66a7ba4..fce2b48 100644 --- a/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToPostsIdsRepo.kt +++ b/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToPostsIdsRepo.kt @@ -5,8 +5,7 @@ import dev.inmo.micro_utils.repos.exposed.keyvalue.AbstractExposedKeyValueRepo import dev.inmo.plaguposter.posts.models.PostId import dev.inmo.tgbotapi.types.PollIdentifier import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.statements.InsertStatement -import org.jetbrains.exposed.sql.statements.UpdateStatement +import org.jetbrains.exposed.sql.statements.* class ExposedPollsToPostsIdsRepo( database: Database @@ -24,12 +23,11 @@ class ExposedPollsToPostsIdsRepo( initTable() } - override fun update(k: PollIdentifier, v: PostId, it: UpdateStatement) { + override fun update(k: PollIdentifier, v: PostId, it: UpdateBuilder) { it[postIdColumn] = v.string } - override fun insert(k: PollIdentifier, v: PostId, it: InsertStatement) { + override fun insertKey(k: PollIdentifier, v: PostId, it: InsertStatement) { it[keyColumn] = k - it[postIdColumn] = v.string } } diff --git a/ratings/src/jvmMain/kotlin/exposed/ExposedRatingsRepo.kt b/ratings/src/jvmMain/kotlin/exposed/ExposedRatingsRepo.kt index d49936e..0f0799f 100644 --- a/ratings/src/jvmMain/kotlin/exposed/ExposedRatingsRepo.kt +++ b/ratings/src/jvmMain/kotlin/exposed/ExposedRatingsRepo.kt @@ -6,8 +6,7 @@ import dev.inmo.plaguposter.posts.models.PostId import dev.inmo.plaguposter.ratings.models.Rating import dev.inmo.plaguposter.ratings.repo.RatingsRepo import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.statements.InsertStatement -import org.jetbrains.exposed.sql.statements.UpdateStatement +import org.jetbrains.exposed.sql.statements.* import org.jetbrains.exposed.sql.transactions.transaction class ExposedRatingsRepo ( @@ -25,13 +24,12 @@ class ExposedRatingsRepo ( override val ResultRow.asObject: Rating get() = get(ratingsColumn).let(::Rating) - override fun update(k: PostId, v: Rating, it: UpdateStatement) { + override fun update(k: PostId, v: Rating, it: UpdateBuilder) { it[ratingsColumn] = v.double } - override fun insert(k: PostId, v: Rating, it: InsertStatement) { + override fun insertKey(k: PostId, v: Rating, it: InsertStatement) { it[keyColumn] = k.string - it[ratingsColumn] = v.double } private fun Query.optionallyLimit(limit: Int?) = if (limit == null) { From d605c8c6503879c2ae8b83e6dc75b20eb944d182 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Oct 2022 12:51:45 +0600 Subject: [PATCH 30/30] small fixes --- ratings/source/src/jvmMain/kotlin/Plugin.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ratings/source/src/jvmMain/kotlin/Plugin.kt b/ratings/source/src/jvmMain/kotlin/Plugin.kt index 6c58f56..0f78266 100644 --- a/ratings/source/src/jvmMain/kotlin/Plugin.kt +++ b/ratings/source/src/jvmMain/kotlin/Plugin.kt @@ -38,6 +38,7 @@ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineK import dev.inmo.tgbotapi.types.message.textsources.bold import dev.inmo.tgbotapi.types.message.textsources.regular import dev.inmo.tgbotapi.utils.buildEntities +import kotlinx.coroutines.delay import kotlinx.coroutines.flow.first import kotlinx.serialization.Serializable import kotlinx.serialization.json.* @@ -108,6 +109,9 @@ object Plugin : Plugin { pollsToPostsIdsRepo.set(sent.content.poll.id, postId) pollsToMessageInfoRepo.set(sent.content.poll.id, sent.short()) }.getOrNull() ?: continue + + delay(500L) + panelApi ?.forceRefresh(postId) return true } @@ -139,6 +143,7 @@ object Plugin : Plugin { if (config.autoAttach) { postsRepo.newObjectsFlow.subscribeSafelyWithoutExceptions(this) { + delay(500L) attachPoll(it.id) } }