From 941505df4276da60500d19681fe4a1cc57d83e56 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 20 Aug 2022 00:52:31 +0600 Subject: [PATCH] preview version of registrar --- common/build.gradle | 23 +++++++++++++++++++ .../kotlin/CommonMessagesCommandsFilter.kt | 14 +++++++++++ common/src/commonMain/kotlin/PackageInfo.kt | 1 + common/src/main/AndroidManifest.xml | 1 + gradle/libs.versions.toml | 1 + posts/build.gradle | 4 +--- .../kotlin/exposed/ExposedPostsRepo.kt | 7 +++++- posts_registrar/src/jvmMain/kotlin/Plugin.kt | 3 ++- runner/build.gradle | 22 ++++++++++++++++++ runner/config.json | 21 +++++++++++++++++ settings.gradle | 4 +++- template/build.gradle | 4 +--- 12 files changed, 96 insertions(+), 9 deletions(-) create mode 100644 common/build.gradle create mode 100644 common/src/commonMain/kotlin/CommonMessagesCommandsFilter.kt create mode 100644 common/src/commonMain/kotlin/PackageInfo.kt create mode 100644 common/src/main/AndroidManifest.xml create mode 100644 runner/build.gradle create mode 100644 runner/config.json diff --git a/common/build.gradle b/common/build.gradle new file mode 100644 index 0000000..36f733d --- /dev/null +++ b/common/build.gradle @@ -0,0 +1,23 @@ +plugins { + id "org.jetbrains.kotlin.multiplatform" + id "org.jetbrains.kotlin.plugin.serialization" + id "com.android.library" +} + +apply from: "$mppProjectWithSerializationPresetPath" + +kotlin { + sourceSets { + commonMain { + dependencies { + api libs.tgbotapi + api libs.microutils.repos.common + api libs.kslog + } + } + jvmMain { + dependencies { + } + } + } +} diff --git a/common/src/commonMain/kotlin/CommonMessagesCommandsFilter.kt b/common/src/commonMain/kotlin/CommonMessagesCommandsFilter.kt new file mode 100644 index 0000000..2eac06e --- /dev/null +++ b/common/src/commonMain/kotlin/CommonMessagesCommandsFilter.kt @@ -0,0 +1,14 @@ +package dev.inmo.plaguposter.common + +import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CommonMessageFilterExcludeMediaGroups +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter +import dev.inmo.tgbotapi.extensions.utils.textContentOrNull +import dev.inmo.tgbotapi.types.BotCommand +import dev.inmo.tgbotapi.types.message.abstracts.* +import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource + +val FirstSourceIsCommandsFilter = SimpleFilter { + it is ContentMessage<*> && it.content.textContentOrNull() ?.textSources ?.firstOrNull { + it is BotCommandTextSource + } != null +} diff --git a/common/src/commonMain/kotlin/PackageInfo.kt b/common/src/commonMain/kotlin/PackageInfo.kt new file mode 100644 index 0000000..4934c93 --- /dev/null +++ b/common/src/commonMain/kotlin/PackageInfo.kt @@ -0,0 +1 @@ +package dev.inmo.plaguposter.common diff --git a/common/src/main/AndroidManifest.xml b/common/src/main/AndroidManifest.xml new file mode 100644 index 0000000..84ea0cd --- /dev/null +++ b/common/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d6cccba..067737b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -31,6 +31,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" } 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" } kslog = { module = "dev.inmo:kslog", version.ref = "kslog" } diff --git a/posts/build.gradle b/posts/build.gradle index a210d1d..8ad984c 100644 --- a/posts/build.gradle +++ b/posts/build.gradle @@ -10,9 +10,7 @@ kotlin { sourceSets { commonMain { dependencies { - api libs.tgbotapi - api libs.microutils.repos.common - api libs.kslog + api project(":plaguposter.common") } } jvmMain { diff --git a/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt b/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt index e733caa..7243e30 100644 --- a/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt +++ b/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt @@ -3,6 +3,7 @@ package dev.inmo.plaguposter.posts.exposed import com.benasher44.uuid.uuid4 import dev.inmo.micro_utils.repos.KeyValuesRepo import dev.inmo.micro_utils.repos.exposed.AbstractExposedCRUDRepo +import dev.inmo.micro_utils.repos.exposed.initTable import dev.inmo.plaguposter.posts.models.* import dev.inmo.plaguposter.posts.repo.PostsRepo import kotlinx.serialization.json.Json @@ -25,7 +26,7 @@ class ExposedPostsRepo( ) } - override val primaryKey: PrimaryKey? = PrimaryKey(idColumn) + override val primaryKey: PrimaryKey = PrimaryKey(idColumn) override val selectById: SqlExpressionBuilder.(PostId) -> Op = { idColumn.eq(it.string) } override val selectByIds: SqlExpressionBuilder.(List) -> Op = { idColumn.inList(it.map { it.string }) } @@ -42,6 +43,10 @@ class ExposedPostsRepo( ) } + init { + initTable() + } + override fun InsertStatement.asObject(value: NewPost): RegisteredPost { val id = PostId(get(idColumn)) diff --git a/posts_registrar/src/jvmMain/kotlin/Plugin.kt b/posts_registrar/src/jvmMain/kotlin/Plugin.kt index 72b7444..0ca2ed6 100644 --- a/posts_registrar/src/jvmMain/kotlin/Plugin.kt +++ b/posts_registrar/src/jvmMain/kotlin/Plugin.kt @@ -8,6 +8,7 @@ import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions 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.FirstSourceIsCommandsFilter import dev.inmo.plaguposter.posts.models.NewPost import dev.inmo.plaguposter.posts.models.PostContentInfo import dev.inmo.plaguposter.posts.registrar.state.RegistrationState @@ -142,7 +143,7 @@ object Plugin : Plugin { } onContentMessage( - initialFilter = { it.chat.id == config.sourceChatId && it.mediaGroupMessageOrNull() ?.mediaGroupId == null } + initialFilter = { it.chat.id == config.sourceChatId && it.mediaGroupMessageOrNull() ?.mediaGroupId == null && !FirstSourceIsCommandsFilter(it) } ) { startChain(RegistrationState.Finish(it.chat.id, listOf(PostContentInfo.fromMessage(it, 0)))) } diff --git a/runner/build.gradle b/runner/build.gradle new file mode 100644 index 0000000..4343e2c --- /dev/null +++ b/runner/build.gradle @@ -0,0 +1,22 @@ +plugins { + id 'org.jetbrains.kotlin.jvm' + id "org.jetbrains.kotlin.plugin.serialization" + id 'application' +} + +dependencies { + implementation libs.kotlin + api libs.plagubot.bot + + api project(":plaguposter.posts") + api project(":plaguposter.posts_registrar") +} + +application { + mainClassName = 'dev.inmo.plagubot.AppKt' +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} diff --git a/runner/config.json b/runner/config.json new file mode 100644 index 0000000..b140d31 --- /dev/null +++ b/runner/config.json @@ -0,0 +1,21 @@ +{ + "database": { + "url": "jdbc:sqlite:file:test?mode=memory&cache=shared IT IS JUST EXAMPLE", + "driver": "org.sqlite.JDBC", + "username": "OPTIONAL username", + "password": "OPTIONAL password", + "initAutomatically": false + }, + "botToken": "1234567890:ABCDEFGHIJKLMNOP_qrstuvwxyz12345678", + "plugins": [ + "dev.inmo.plaguposter.posts.Plugin", + "dev.inmo.plaguposter.posts.registrar.Plugin" + ], + "posts": { + "targetChat": 12345678, + "cacheChat": 12345678 + }, + "registrar": { + "sourceChat": 12345678 + } +} diff --git a/settings.gradle b/settings.gradle index d625beb..84e05ba 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,8 +1,10 @@ rootProject.name = 'plaguposter' String[] includes = [ + ":common", ":posts", - ":posts_registrar" + ":posts_registrar", + ":runner" ] diff --git a/template/build.gradle b/template/build.gradle index 36f733d..c3a8634 100644 --- a/template/build.gradle +++ b/template/build.gradle @@ -10,9 +10,7 @@ kotlin { sourceSets { commonMain { dependencies { - api libs.tgbotapi - api libs.microutils.repos.common - api libs.kslog + api project(":plaguposter.common") } } jvmMain {