preview version of registrar

This commit is contained in:
InsanusMokrassar 2022-08-20 00:52:31 +06:00
parent 36bedff5f3
commit 941505df42
12 changed files with 96 additions and 9 deletions

23
common/build.gradle Normal file
View File

@ -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 {
}
}
}
}

View File

@ -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<Message> {
it is ContentMessage<*> && it.content.textContentOrNull() ?.textSources ?.firstOrNull {
it is BotCommandTextSource
} != null
}

View File

@ -0,0 +1 @@
package dev.inmo.plaguposter.common

View File

@ -0,0 +1 @@
<manifest package="dev.inmo.plaguposter.common"/>

View File

@ -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" }

View File

@ -10,9 +10,7 @@ kotlin {
sourceSets {
commonMain {
dependencies {
api libs.tgbotapi
api libs.microutils.repos.common
api libs.kslog
api project(":plaguposter.common")
}
}
jvmMain {

View File

@ -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<Boolean> = { idColumn.eq(it.string) }
override val selectByIds: SqlExpressionBuilder.(List<PostId>) -> Op<Boolean> = { idColumn.inList(it.map { it.string }) }
@ -42,6 +43,10 @@ class ExposedPostsRepo(
)
}
init {
initTable()
}
override fun InsertStatement<Number>.asObject(value: NewPost): RegisteredPost {
val id = PostId(get(idColumn))

View File

@ -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))))
}

22
runner/build.gradle Normal file
View File

@ -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
}

21
runner/config.json Normal file
View File

@ -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
}
}

View File

@ -1,8 +1,10 @@
rootProject.name = 'plaguposter'
String[] includes = [
":common",
":posts",
":posts_registrar"
":posts_registrar",
":runner"
]

View File

@ -10,9 +10,7 @@ kotlin {
sourceSets {
commonMain {
dependencies {
api libs.tgbotapi
api libs.microutils.repos.common
api libs.kslog
api project(":plaguposter.common")
}
}
jvmMain {