mirror of
https://github.com/InsanusMokrassar/PlaguPoster.git
synced 2024-12-22 14:07:14 +00:00
commit
65f613fd97
3
.github/workflows/build.yml
vendored
3
.github/workflows/build.yml
vendored
@ -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
|
||||
|
@ -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
|
||||
|
@ -1,7 +1,6 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -1,27 +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"
|
||||
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" }
|
||||
@ -30,12 +21,11 @@ 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" }
|
||||
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" }
|
||||
@ -47,8 +37,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" }
|
||||
|
@ -1,7 +1,6 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
@ -15,6 +14,7 @@ kotlin {
|
||||
}
|
||||
jvmMain {
|
||||
dependencies {
|
||||
api libs.plagubot.plugins.inline.queries
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
package dev.inmo.plaguposter.inlines
|
||||
package dev.inmo.plagubot.plugins.inline.queries
|
||||
|
@ -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<OfferTemplate>
|
||||
)
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
single { get<Json>().decodeFromJsonElement(Config.serializer(), params["inlines"] ?: return@single Config(emptyList())) }
|
||||
single { InlineTemplatesRepo(getOrNull<Config>() ?.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<InlineTemplatesRepo>()
|
||||
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<InlineTemplatesRepo>() ?.apply {
|
||||
addTemplate(
|
||||
OfferTemplate(
|
||||
"Trigger help button",
|
||||
listOf(Format("/help"))
|
||||
)
|
||||
)
|
||||
with(actualPlugin) {
|
||||
setupBotPlugin(koin)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
@ -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<Format> = 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
|
||||
)
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package dev.inmo.plaguposter.inlines.repos
|
||||
|
||||
import dev.inmo.plaguposter.inlines.models.OfferTemplate
|
||||
|
||||
class InlineTemplatesRepo(
|
||||
private val _templates: MutableSet<OfferTemplate>
|
||||
) {
|
||||
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)
|
||||
}
|
||||
}
|
@ -1 +1 @@
|
||||
<manifest package="dev.inmo.plaguposter.inlines"/>
|
||||
<manifest package="dev.inmo.plagubot.plugins.inline.queries"/>
|
||||
|
@ -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"
|
@ -4,20 +4,11 @@ project.group = "$group"
|
||||
// apply from: "$publishGradlePath"
|
||||
|
||||
kotlin {
|
||||
jvm {
|
||||
compilations.main {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
}
|
||||
jvm()
|
||||
js (IR) {
|
||||
browser()
|
||||
nodejs()
|
||||
}
|
||||
android {
|
||||
publishAllLibraryVariants()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
@ -43,19 +34,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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
apply from: "$defaultAndroidSettingsPresetPath"
|
||||
|
@ -1,7 +1,6 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
|
@ -1,7 +1,6 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
|
@ -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
|
||||
|
@ -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<RegisteredPost, PostId, NewPost>(
|
||||
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<Number>.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<Number>): PostId {
|
||||
val id = PostId(uuid4().toString())
|
||||
it[idColumn] = id.string
|
||||
return id
|
||||
}
|
||||
|
||||
override fun update(id: PostId?, value: NewPost, it: UpdateBuilder<Int>) {
|
||||
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<Number>) {
|
||||
super.insert(value, it)
|
||||
it[createdColumn] = DateTime.now().unixMillis
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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<Int>) {
|
||||
it[chatIdColumn] = v.chatId.chatId
|
||||
it[messageIdColumn] = v.messageId
|
||||
}
|
||||
|
||||
override fun insert(k: PollIdentifier, v: ShortMessageInfo, it: InsertStatement<Number>) {
|
||||
override fun insertKey(k: PollIdentifier, v: ShortMessageInfo, it: InsertStatement<Number>) {
|
||||
it[keyColumn] = k
|
||||
it[chatIdColumn] = v.chatId.chatId
|
||||
it[messageIdColumn] = v.messageId
|
||||
}
|
||||
}
|
||||
|
@ -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<Int>) {
|
||||
it[postIdColumn] = v.string
|
||||
}
|
||||
|
||||
override fun insert(k: PollIdentifier, v: PostId, it: InsertStatement<Number>) {
|
||||
override fun insertKey(k: PollIdentifier, v: PostId, it: InsertStatement<Number>) {
|
||||
it[keyColumn] = k
|
||||
it[postIdColumn] = v.string
|
||||
}
|
||||
}
|
||||
|
@ -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<Int>) {
|
||||
it[ratingsColumn] = v.double
|
||||
}
|
||||
|
||||
override fun insert(k: PostId, v: Rating, it: InsertStatement<Number>) {
|
||||
override fun insertKey(k: PostId, v: Rating, it: InsertStatement<Number>) {
|
||||
it[keyColumn] = k.string
|
||||
it[ratingsColumn] = v.double
|
||||
}
|
||||
|
||||
private fun Query.optionallyLimit(limit: Int?) = if (limit == null) {
|
||||
|
@ -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"
|
||||
],
|
||||
|
@ -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": {
|
||||
|
@ -11,6 +11,7 @@ String[] includes = [
|
||||
":ratings:gc",
|
||||
":triggers:command",
|
||||
":triggers:selector_with_timer",
|
||||
":triggers:selector_with_scheduling",
|
||||
":inlines",
|
||||
// ":settings",
|
||||
":runner"
|
||||
|
@ -1,7 +1,6 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
|
@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
16
triggers/selector_with_scheduling/build.gradle
Normal file
16
triggers/selector_with_scheduling/build.gradle
Normal file
@ -0,0 +1,16 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api project(":plaguposter.common")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
package dev.inmo.plaguposter.triggers.selector_with_scheduling
|
@ -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) {
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
<manifest package="dev.inmo.plaguposter.triggers.selector_with_scheduling"/>
|
@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user