From 1cd7c07d29e00646b61c4a169ca8ff42e2467dc8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 2 Oct 2022 22:41:45 +0600 Subject: [PATCH 1/5] start 0.0.4 --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 383a2a3..5a5466a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,5 +10,5 @@ android.enableJetifier=true # Project data group=dev.inmo -version=0.0.3 -android_code_version=3 +version=0.0.4 +android_code_version=4 From 4b7c2451cd44aea06994d7d403e9e44628c29742 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 2 Oct 2022 22:43:26 +0600 Subject: [PATCH 2/5] update dependencies --- gradle/libs.versions.toml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3f453c9..c5bfc92 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,12 +3,12 @@ kotlin = "1.7.10" kotlin-serialization = "1.4.0" -plagubot = "2.3.2" -tgbotapi = "3.2.3" -microutils = "0.12.13" +plagubot = "2.3.4" +tgbotapi = "3.2.7" +microutils = "0.12.16" kslog = "0.5.2" krontab = "0.8.1" -tgbotapi-libraries = "0.5.3" +tgbotapi-libraries = "0.5.5" psql = "42.5.0" @@ -19,8 +19,8 @@ espresso_core = "3.4.0" android-gradle-plugin = "7.2.2" android-minSdk = "21" -android-compileSdk = "32" -android-buildTools = "32.0.0" +android-compileSdk = "33" +android-buildTools = "33.0.0" [libraries] From 3634b9a2a2f3f2052f3c8eeb3b724ab9aa2e9bb9 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 2 Oct 2022 22:45:37 +0600 Subject: [PATCH 3/5] start implement #4 --- ratings/src/commonMain/kotlin/utils/PostsByRatings.kt | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 ratings/src/commonMain/kotlin/utils/PostsByRatings.kt diff --git a/ratings/src/commonMain/kotlin/utils/PostsByRatings.kt b/ratings/src/commonMain/kotlin/utils/PostsByRatings.kt new file mode 100644 index 0000000..2c939f0 --- /dev/null +++ b/ratings/src/commonMain/kotlin/utils/PostsByRatings.kt @@ -0,0 +1,8 @@ +package dev.inmo.plaguposter.ratings.utils + +import dev.inmo.micro_utils.pagination.utils.getAll +import dev.inmo.plaguposter.ratings.repo.RatingsRepo + +suspend fun RatingsRepo.postsByRatings() { + getAll() +} From 1d88423b031a26c4e0e23971d9a1d4affd0e3d78 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 3 Oct 2022 00:20:38 +0600 Subject: [PATCH 4/5] add opportunity to finish post creating by command --- posts_registrar/src/jvmMain/kotlin/Plugin.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/posts_registrar/src/jvmMain/kotlin/Plugin.kt b/posts_registrar/src/jvmMain/kotlin/Plugin.kt index fd950b8..8e78be3 100644 --- a/posts_registrar/src/jvmMain/kotlin/Plugin.kt +++ b/posts_registrar/src/jvmMain/kotlin/Plugin.kt @@ -18,6 +18,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextWithFSM import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.* import dev.inmo.tgbotapi.extensions.behaviour_builder.strictlyOn import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.* +import dev.inmo.tgbotapi.extensions.utils.extensions.sameChat import dev.inmo.tgbotapi.extensions.utils.extensions.sameMessage import dev.inmo.tgbotapi.extensions.utils.formatting.buildEntities import dev.inmo.tgbotapi.extensions.utils.formatting.regular @@ -80,6 +81,12 @@ object Plugin : Plugin { }.first() emptyList>() } + add { + val finishPressed = waitCommandMessage("finish_post").filter { + it.sameChat(messageToDelete) + }.first() + emptyList>() + } }.ifEmpty { edit(messageToDelete, "Ok, finishing your request") return@strictlyOn RegistrationState.Finish( @@ -135,8 +142,16 @@ object Plugin : Plugin { koin.getOrNull() ?.apply { addTemplate( OfferTemplate( - "Start post", - listOf(Format("/start_post")) + "Start post creating", + listOf(Format("/start_post")), + "Use this command to start creating of complex post with several messages" + ) + ) + addTemplate( + OfferTemplate( + "Finish post creating", + listOf(Format("/finish_post")), + "Finish creating of complex post" ) ) } From 47f9e09bd28cc0e19b5b4fa5f1a6b99ddf07f17d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 3 Oct 2022 00:51:51 +0600 Subject: [PATCH 5/5] updates --- ratings/source/src/jvmMain/kotlin/Plugin.kt | 21 ++++++++++++++++++- .../commonMain/kotlin/utils/PostsByRatings.kt | 11 ++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ratings/source/src/jvmMain/kotlin/Plugin.kt b/ratings/source/src/jvmMain/kotlin/Plugin.kt index a9a2631..9cb3228 100644 --- a/ratings/source/src/jvmMain/kotlin/Plugin.kt +++ b/ratings/source/src/jvmMain/kotlin/Plugin.kt @@ -22,6 +22,7 @@ import dev.inmo.plaguposter.ratings.models.Rating import dev.inmo.plaguposter.ratings.repo.RatingsRepo import dev.inmo.plaguposter.ratings.source.models.* import dev.inmo.plaguposter.ratings.source.repos.* +import dev.inmo.plaguposter.ratings.utils.postsByRatings import dev.inmo.tgbotapi.extensions.api.answers.answer import dev.inmo.tgbotapi.extensions.api.delete import dev.inmo.tgbotapi.extensions.api.edit.edit @@ -34,8 +35,9 @@ import dev.inmo.tgbotapi.extensions.utils.extensions.sameMessage import dev.inmo.tgbotapi.extensions.utils.types.buttons.dataButton import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatInlineKeyboard 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 kotlinx.coroutines.flow.filter +import dev.inmo.tgbotapi.utils.buildEntities import kotlinx.coroutines.flow.first import kotlinx.serialization.Serializable import kotlinx.serialization.json.* @@ -79,6 +81,7 @@ object Plugin : Plugin { val postsRepo = koin.get() val config = koin.get() val panelApi = koin.getOrNull() + val chatConfig = koin.get() onPollUpdates (markerFactory = { it.id }) { poll -> val postId = pollsToPostsIdsRepo.get(poll.id) ?: return@onPollUpdates @@ -208,6 +211,22 @@ object Plugin : Plugin { } } } + onCommand("ratings", requireOnlyCommandInMessage = true) { + if (it.chat.id == chatConfig.sourceChatId) { + val ratings = ratingsRepo.postsByRatings().toList().sortedByDescending { it.first } + val textSources = buildEntities { + + "Ratings amount: " + bold("${ratings.sumOf { it.second.size }}") + "\n\n" + ratings.forEach { + + "• " + bold("% 3.1f".format(it.first.double)) + ": " + bold(it.second.size.toString()) + "\n" + } + } + runCatchingSafely { + edit(it, textSources) + }.onFailure { _ -> + reply(it, textSources) + } + } + } koin.getOrNull() ?.apply { addTemplate( diff --git a/ratings/src/commonMain/kotlin/utils/PostsByRatings.kt b/ratings/src/commonMain/kotlin/utils/PostsByRatings.kt index 2c939f0..ab7176a 100644 --- a/ratings/src/commonMain/kotlin/utils/PostsByRatings.kt +++ b/ratings/src/commonMain/kotlin/utils/PostsByRatings.kt @@ -1,8 +1,15 @@ package dev.inmo.plaguposter.ratings.utils import dev.inmo.micro_utils.pagination.utils.getAll +import dev.inmo.micro_utils.repos.pagination.getAll +import dev.inmo.plaguposter.posts.models.PostId +import dev.inmo.plaguposter.ratings.models.Rating import dev.inmo.plaguposter.ratings.repo.RatingsRepo -suspend fun RatingsRepo.postsByRatings() { - getAll() +suspend fun RatingsRepo.postsByRatings(): Map> { + return getAll { keys(it) }.groupBy { + it.second + }.map { + it.key to it.value.map { it.first } + }.toMap() }