From d6bd90267deb6bc2c5ac8b2982595e5dffdb7e36 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 28 Nov 2022 19:29:14 +0600 Subject: [PATCH 1/7] start 0.0.7 --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 0693423..114a8d3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,5 +10,5 @@ android.enableJetifier=true # Project data group=dev.inmo -version=0.0.6 -android_code_version=6 +version=0.0.7 +android_code_version=7 From 791a161f8cfe731f9a510dbc4db134b419738598 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 28 Nov 2022 19:32:51 +0600 Subject: [PATCH 2/7] update dependencies --- gradle/libs.versions.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index bacd557..8dbd3e7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,13 +3,13 @@ kotlin = "1.7.21" kotlin-serialization = "1.4.1" -plagubot = "3.1.3" -tgbotapi = "4.1.2" -microutils = "0.14.2" +plagubot = "3.1.4" +tgbotapi = "4.1.3" +microutils = "0.14.4" kslog = "0.5.3" krontab = "0.8.3" -tgbotapi-libraries = "0.6.3" -plagubot-plugins = "0.6.1" +tgbotapi-libraries = "0.6.4" +plagubot-plugins = "0.6.3" dokka = "1.7.20" From 2052d003e5be3c3dcf596d455d3a17bf732e7512 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 28 Nov 2022 19:33:58 +0600 Subject: [PATCH 3/7] update gradle wrapper version --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ae04661..070cb70 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 82640a0c5d0ed3949b798d7fd0438cf2984c20ce Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 28 Nov 2022 20:21:03 +0600 Subject: [PATCH 4/7] start adding of ratings buttons --- .../commonMain/kotlin/buttons/RootButtons.kt | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 ratings/source/src/commonMain/kotlin/buttons/RootButtons.kt diff --git a/ratings/source/src/commonMain/kotlin/buttons/RootButtons.kt b/ratings/source/src/commonMain/kotlin/buttons/RootButtons.kt new file mode 100644 index 0000000..0f369d0 --- /dev/null +++ b/ratings/source/src/commonMain/kotlin/buttons/RootButtons.kt @@ -0,0 +1,42 @@ +package dev.inmo.plaguposter.ratings.source.buttons + +import dev.inmo.micro_utils.pagination.FirstPagePagination +import dev.inmo.micro_utils.pagination.Pagination +import dev.inmo.micro_utils.pagination.isFirstPage +import dev.inmo.micro_utils.pagination.utils.paginate +import dev.inmo.plaguposter.ratings.repo.RatingsRepo +import dev.inmo.plaguposter.ratings.utils.postsByRatings +import dev.inmo.tgbotapi.extensions.utils.types.buttons.dataButton +import dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard +import dev.inmo.tgbotapi.types.buttons.inline.dataInlineButton +import dev.inmo.tgbotapi.utils.row + +const val RootButtonsShowRatingData = "ratings_buttons_show" +const val RootButtonsToPageData = "ratings_buttons_to_page" + +suspend fun RatingsRepo.buildRootButtons( + pagination: Pagination = FirstPagePagination(16), + rowSize: Int = 4 +) { + val postsByRatings = postsByRatings().toList().paginate(pagination) + inlineKeyboard { + if (postsByRatings.pagesNumber > 1) { + row { + if (postsByRatings.page > 0) { + dataButton("<", "$RootButtonsToPageData ${postsByRatings.page - 1}") + } + dataButton("${postsByRatings.page}: \uD83D\uDD04", "$RootButtonsToPageData ${postsByRatings.page}") + if (postsByRatings.pagesNumber - postsByRatings.page > 1) { + dataButton(">", "$RootButtonsToPageData ${postsByRatings.page + 1}") + } + } + } + postsByRatings.results.chunked(rowSize).map { + row { + it.forEach { (rating, posts) -> + dataButton("${rating.double}: ${posts.size}", "$RootButtonsShowRatingData ${rating.double}") + } + } + } + } +} From 74cf8c1a9a34e356c2a1844dd3ed7127624f0fe5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 2 Dec 2022 18:46:58 +0600 Subject: [PATCH 5/7] temporal progress on ratings buttons --- .../commonMain/kotlin/buttons/RootButtons.kt | 116 ++++++++++++++++-- 1 file changed, 109 insertions(+), 7 deletions(-) diff --git a/ratings/source/src/commonMain/kotlin/buttons/RootButtons.kt b/ratings/source/src/commonMain/kotlin/buttons/RootButtons.kt index 0f369d0..293d57d 100644 --- a/ratings/source/src/commonMain/kotlin/buttons/RootButtons.kt +++ b/ratings/source/src/commonMain/kotlin/buttons/RootButtons.kt @@ -1,33 +1,41 @@ package dev.inmo.plaguposter.ratings.source.buttons +import dev.inmo.micro_utils.coroutines.runCatchingSafely import dev.inmo.micro_utils.pagination.FirstPagePagination import dev.inmo.micro_utils.pagination.Pagination -import dev.inmo.micro_utils.pagination.isFirstPage +import dev.inmo.micro_utils.pagination.SimplePagination import dev.inmo.micro_utils.pagination.utils.paginate +import dev.inmo.plaguposter.ratings.models.Rating import dev.inmo.plaguposter.ratings.repo.RatingsRepo import dev.inmo.plaguposter.ratings.utils.postsByRatings +import dev.inmo.tgbotapi.extensions.api.answers.answer +import dev.inmo.tgbotapi.extensions.api.edit.edit +import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMessageDataCallbackQuery import dev.inmo.tgbotapi.extensions.utils.types.buttons.dataButton import dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard -import dev.inmo.tgbotapi.types.buttons.inline.dataInlineButton +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.utils.row const val RootButtonsShowRatingData = "ratings_buttons_show" +const val RootButtonsShowRatingPageData = "ratings_buttons_show_page" const val RootButtonsToPageData = "ratings_buttons_to_page" suspend fun RatingsRepo.buildRootButtons( pagination: Pagination = FirstPagePagination(16), rowSize: Int = 4 -) { +): InlineKeyboardMarkup { val postsByRatings = postsByRatings().toList().paginate(pagination) - inlineKeyboard { + return inlineKeyboard { if (postsByRatings.pagesNumber > 1) { row { if (postsByRatings.page > 0) { - dataButton("<", "$RootButtonsToPageData ${postsByRatings.page - 1}") + dataButton("<", "$RootButtonsToPageData ${postsByRatings.page - 1} ${postsByRatings.size}") } - dataButton("${postsByRatings.page}: \uD83D\uDD04", "$RootButtonsToPageData ${postsByRatings.page}") + dataButton("${postsByRatings.page}: \uD83D\uDD04", "$RootButtonsToPageData ${postsByRatings.page} ${postsByRatings.size}") if (postsByRatings.pagesNumber - postsByRatings.page > 1) { - dataButton(">", "$RootButtonsToPageData ${postsByRatings.page + 1}") + dataButton(">", "$RootButtonsToPageData ${postsByRatings.page + 1} ${postsByRatings.size}") } } } @@ -40,3 +48,97 @@ suspend fun RatingsRepo.buildRootButtons( } } } + +suspend fun RatingsRepo.buildRatingButtons( + rating: Rating, + pagination: Pagination = FirstPagePagination(8), + rowSize: Int = 2 +): InlineKeyboardMarkup { + val postsByRatings = getPosts(rating .. rating, true).keys.paginate(pagination) + return inlineKeyboard { + if (postsByRatings.pagesNumber > 1) { + row { + if (postsByRatings.page > 0) { + dataButton("<", "$RootButtonsShowRatingPageData ${postsByRatings.page - 1} ${postsByRatings.size}") + } + dataButton("${postsByRatings.page}: \uD83D\uDD04", "$RootButtonsShowRatingPageData ${postsByRatings.page} ${postsByRatings.size}") + if (postsByRatings.pagesNumber - postsByRatings.page > 1) { + dataButton(">", "$RootButtonsShowRatingPageData ${postsByRatings.page + 1} ${postsByRatings.size}") + } + } + } + postsByRatings.results.chunked(rowSize).map { + row { + it.forEach { (rating, posts) -> + dataButton("${rating.double}: ${posts.size}", "$RootButtonsShowRatingData ${rating.double}") + } + } + } + } +} + +suspend fun BehaviourContext.includeRootNavigationButtonsHandler( + allowedChats: Set, + ratingsRepo: RatingsRepo +) { + suspend fun registerPageQueryListener( + dataPrefix: String, + onPageUpdate: suspend (pagination: Pagination) -> InlineKeyboardMarkup? + ) { + onMessageDataCallbackQuery( + initialFilter = { it.message.chat.id in allowedChats } + ) { + val (prefix, pageRaw, sizeRaw) = it.data.split(" ").takeIf { it.size == 3 } ?: return@onMessageDataCallbackQuery + + if (prefix == dataPrefix) { + runCatchingSafely { + val page = pageRaw.toIntOrNull() ?: return@runCatchingSafely + val size = sizeRaw.toIntOrNull() ?: return@runCatchingSafely + + edit( + it.message, + onPageUpdate(SimplePagination(page, size)) ?: return@runCatchingSafely + ) + } + + answer(it) + } + } + } + registerPageQueryListener( + RootButtonsToPageData, + ratingsRepo::buildRootButtons + ) + onMessageDataCallbackQuery( + initialFilter = { it.message.chat.id in allowedChats } + ) { + val (prefix, pageRaw, sizeRaw) = it.data.split(" ").takeIf { it.size == 3 } ?: return@onMessageDataCallbackQuery + + if (prefix == RootButtonsToPageData) { + runCatchingSafely { + val page = pageRaw.toIntOrNull() ?: return@runCatchingSafely + val size = sizeRaw.toIntOrNull() ?: return@runCatchingSafely + + edit( + it.message, + ratingsRepo.buildRootButtons(SimplePagination(page, size)) + ) + } + + answer(it) + } + } + onMessageDataCallbackQuery( + initialFilter = { it.message.chat.id in allowedChats } + ) { + val (prefix, ratingRaw) = it.data.split(" ").takeIf { it.size == 2 } ?: return@onMessageDataCallbackQuery + + if (prefix == RootButtonsShowRatingData) { + runCatchingSafely { + val rating = ratingRaw.toDoubleOrNull() ?: return@runCatchingSafely + } + + answer(it) + } + } +} From 4024b040e0e2e42df08838796c9b21ec21fb384d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 5 Dec 2022 18:12:45 +0600 Subject: [PATCH 6/7] update dependencies --- gradle/libs.versions.toml | 14 +++++++------- .../src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt | 4 +++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8dbd3e7..8c2311b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,15 +1,15 @@ [versions] -kotlin = "1.7.21" +kotlin = "1.7.22" kotlin-serialization = "1.4.1" -plagubot = "3.1.4" -tgbotapi = "4.1.3" -microutils = "0.14.4" -kslog = "0.5.3" +plagubot = "3.2.0" +tgbotapi = "4.2.0" +microutils = "0.15.0" +kslog = "0.5.4" krontab = "0.8.3" -tgbotapi-libraries = "0.6.4" -plagubot-plugins = "0.6.3" +tgbotapi-libraries = "0.6.5" +plagubot-plugins = "0.6.4" dokka = "1.7.20" diff --git a/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt b/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt index 8d7ef0c..45e614e 100644 --- a/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt +++ b/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt @@ -38,9 +38,11 @@ class ExposedPostsRepo( override val selectById: ISqlExpressionBuilder.(PostId) -> Op = { idColumn.eq(it.string) } override val selectByIds: ISqlExpressionBuilder.(List) -> Op = { idColumn.inList(it.map { it.string }) } + override val ResultRow.asId: PostId + get() = PostId(get(idColumn)) override val ResultRow.asObject: RegisteredPost get() { - val id = PostId(get(idColumn)) + val id = asId return RegisteredPost( id, DateTime(get(createdColumn)), From 0dc459d5dc2ed14328830d02bc147e95330f7c4f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 8 Dec 2022 10:28:42 +0600 Subject: [PATCH 7/7] update dependencies and add interactive mode for ratings --- gradle/libs.versions.toml | 6 +- .../commonMain/kotlin/repo/ReadPostsRepo.kt | 1 + .../kotlin/exposed/ExposedPostsRepo.kt | 6 ++ .../commonMain/kotlin/buttons/RootButtons.kt | 70 ++++++++++++------- ratings/source/src/jvmMain/kotlin/Plugin.kt | 17 ++++- 5 files changed, 68 insertions(+), 32 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8c2311b..ed6924d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,10 +4,10 @@ kotlin = "1.7.22" kotlin-serialization = "1.4.1" plagubot = "3.2.0" -tgbotapi = "4.2.0" -microutils = "0.15.0" +tgbotapi = "4.2.1" +microutils = "0.16.0" kslog = "0.5.4" -krontab = "0.8.3" +krontab = "0.8.4" tgbotapi-libraries = "0.6.5" plagubot-plugins = "0.6.4" diff --git a/posts/src/commonMain/kotlin/repo/ReadPostsRepo.kt b/posts/src/commonMain/kotlin/repo/ReadPostsRepo.kt index b4391a0..7d0c5d1 100644 --- a/posts/src/commonMain/kotlin/repo/ReadPostsRepo.kt +++ b/posts/src/commonMain/kotlin/repo/ReadPostsRepo.kt @@ -10,4 +10,5 @@ import dev.inmo.tgbotapi.types.MessageIdentifier interface ReadPostsRepo : ReadCRUDRepo { suspend fun getIdByChatAndMessage(chatId: IdChatIdentifier, messageId: MessageIdentifier): PostId? suspend fun getPostCreationTime(postId: PostId): DateTime? + suspend fun getFirstMessageInfo(postId: PostId): PostContentInfo? } diff --git a/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt b/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt index 45e614e..170b505 100644 --- a/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt +++ b/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt @@ -165,4 +165,10 @@ class ExposedPostsRepo( override suspend fun getPostCreationTime(postId: PostId): DateTime? = transaction(database) { select { selectById(postId) }.limit(1).firstOrNull() ?.get(createdColumn) ?.let(::DateTime) } + + override suspend fun getFirstMessageInfo(postId: PostId): PostContentInfo? = transaction(database) { + with(contentRepo) { + select { postIdColumn.eq(postId.string) }.limit(1).firstOrNull() ?.asObject + } + } } diff --git a/ratings/source/src/commonMain/kotlin/buttons/RootButtons.kt b/ratings/source/src/commonMain/kotlin/buttons/RootButtons.kt index 293d57d..606d398 100644 --- a/ratings/source/src/commonMain/kotlin/buttons/RootButtons.kt +++ b/ratings/source/src/commonMain/kotlin/buttons/RootButtons.kt @@ -1,10 +1,12 @@ package dev.inmo.plaguposter.ratings.source.buttons +import com.soywiz.klock.DateFormat import dev.inmo.micro_utils.coroutines.runCatchingSafely import dev.inmo.micro_utils.pagination.FirstPagePagination import dev.inmo.micro_utils.pagination.Pagination import dev.inmo.micro_utils.pagination.SimplePagination import dev.inmo.micro_utils.pagination.utils.paginate +import dev.inmo.plaguposter.posts.repo.ReadPostsRepo import dev.inmo.plaguposter.ratings.models.Rating import dev.inmo.plaguposter.ratings.repo.RatingsRepo import dev.inmo.plaguposter.ratings.utils.postsByRatings @@ -12,8 +14,10 @@ import dev.inmo.tgbotapi.extensions.api.answers.answer import dev.inmo.tgbotapi.extensions.api.edit.edit import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMessageDataCallbackQuery +import dev.inmo.tgbotapi.extensions.utils.formatting.makeLinkToMessage import dev.inmo.tgbotapi.extensions.utils.types.buttons.dataButton import dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard +import dev.inmo.tgbotapi.extensions.utils.types.buttons.urlButton import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.utils.row @@ -49,46 +53,63 @@ suspend fun RatingsRepo.buildRootButtons( } } +val defaultPostCreationTimeFormat: DateFormat = DateFormat("dd.MM.yy HH:mm") + suspend fun RatingsRepo.buildRatingButtons( + postsRepo: ReadPostsRepo, rating: Rating, pagination: Pagination = FirstPagePagination(8), - rowSize: Int = 2 + rowSize: Int = 2, + postCreationTimeFormat: DateFormat = defaultPostCreationTimeFormat ): InlineKeyboardMarkup { val postsByRatings = getPosts(rating .. rating, true).keys.paginate(pagination) return inlineKeyboard { if (postsByRatings.pagesNumber > 1) { row { if (postsByRatings.page > 0) { - dataButton("<", "$RootButtonsShowRatingPageData ${postsByRatings.page - 1} ${postsByRatings.size}") + dataButton("<", "$RootButtonsShowRatingPageData ${postsByRatings.page - 1} ${postsByRatings.size} ${rating.double}") } - dataButton("${postsByRatings.page}: \uD83D\uDD04", "$RootButtonsShowRatingPageData ${postsByRatings.page} ${postsByRatings.size}") + dataButton("${postsByRatings.page}: \uD83D\uDD04", "$RootButtonsShowRatingPageData ${postsByRatings.page} ${postsByRatings.size} ${rating.double}") if (postsByRatings.pagesNumber - postsByRatings.page > 1) { - dataButton(">", "$RootButtonsShowRatingPageData ${postsByRatings.page + 1} ${postsByRatings.size}") + dataButton(">", "$RootButtonsShowRatingPageData ${postsByRatings.page + 1} ${postsByRatings.size} ${rating.double}") } } } postsByRatings.results.chunked(rowSize).map { row { - it.forEach { (rating, posts) -> - dataButton("${rating.double}: ${posts.size}", "$RootButtonsShowRatingData ${rating.double}") + it.forEach { postId -> + val firstMessageInfo = postsRepo.getFirstMessageInfo(postId) ?: return@forEach + val postCreationTime = postsRepo.getPostCreationTime(postId) ?: return@forEach + urlButton( + postCreationTime.format(postCreationTimeFormat), + makeLinkToMessage( + firstMessageInfo.chatId, + firstMessageInfo.messageId + ) + ) } } } + row { + dataButton("↩️", "$RootButtonsToPageData 0 16") + } } } suspend fun BehaviourContext.includeRootNavigationButtonsHandler( allowedChats: Set, - ratingsRepo: RatingsRepo + ratingsRepo: RatingsRepo, + postsRepo: ReadPostsRepo ) { suspend fun registerPageQueryListener( dataPrefix: String, - onPageUpdate: suspend (pagination: Pagination) -> InlineKeyboardMarkup? + onPageUpdate: suspend (pagination: Pagination, additionalParams: Array) -> InlineKeyboardMarkup? ) { onMessageDataCallbackQuery( initialFilter = { it.message.chat.id in allowedChats } ) { - val (prefix, pageRaw, sizeRaw) = it.data.split(" ").takeIf { it.size == 3 } ?: return@onMessageDataCallbackQuery + val args = it.data.split(" ").takeIf { it.size >= 3 } ?: return@onMessageDataCallbackQuery + val (prefix, pageRaw, sizeRaw) = args if (prefix == dataPrefix) { runCatchingSafely { @@ -97,7 +118,7 @@ suspend fun BehaviourContext.includeRootNavigationButtonsHandler( edit( it.message, - onPageUpdate(SimplePagination(page, size)) ?: return@runCatchingSafely + onPageUpdate(SimplePagination(page, size), args.drop(3).toTypedArray()) ?: return@runCatchingSafely ) } @@ -105,27 +126,21 @@ suspend fun BehaviourContext.includeRootNavigationButtonsHandler( } } } + suspend fun registerPageQueryListener( + dataPrefix: String, + onPageUpdate: suspend (pagination: Pagination) -> InlineKeyboardMarkup? + ) = registerPageQueryListener(dataPrefix) { pagination, _ -> + onPageUpdate(pagination) + } registerPageQueryListener( RootButtonsToPageData, ratingsRepo::buildRootButtons ) - onMessageDataCallbackQuery( - initialFilter = { it.message.chat.id in allowedChats } - ) { - val (prefix, pageRaw, sizeRaw) = it.data.split(" ").takeIf { it.size == 3 } ?: return@onMessageDataCallbackQuery - - if (prefix == RootButtonsToPageData) { - runCatchingSafely { - val page = pageRaw.toIntOrNull() ?: return@runCatchingSafely - val size = sizeRaw.toIntOrNull() ?: return@runCatchingSafely - - edit( - it.message, - ratingsRepo.buildRootButtons(SimplePagination(page, size)) - ) - } - - answer(it) + registerPageQueryListener( + RootButtonsShowRatingPageData + ) { pagination, params -> + params.firstOrNull() ?.toDoubleOrNull() ?.let { rating -> + ratingsRepo.buildRatingButtons(postsRepo, Rating(rating), pagination) } } onMessageDataCallbackQuery( @@ -136,6 +151,7 @@ suspend fun BehaviourContext.includeRootNavigationButtonsHandler( if (prefix == RootButtonsShowRatingData) { runCatchingSafely { val rating = ratingRaw.toDoubleOrNull() ?: return@runCatchingSafely + edit(it.message, ratingsRepo.buildRatingButtons(postsRepo, Rating(rating))) } answer(it) diff --git a/ratings/source/src/jvmMain/kotlin/Plugin.kt b/ratings/source/src/jvmMain/kotlin/Plugin.kt index 0f78266..9706fa9 100644 --- a/ratings/source/src/jvmMain/kotlin/Plugin.kt +++ b/ratings/source/src/jvmMain/kotlin/Plugin.kt @@ -20,6 +20,8 @@ import dev.inmo.plaguposter.posts.panel.PanelButtonsAPI import dev.inmo.plaguposter.posts.repo.PostsRepo import dev.inmo.plaguposter.ratings.models.Rating import dev.inmo.plaguposter.ratings.repo.RatingsRepo +import dev.inmo.plaguposter.ratings.source.buttons.buildRootButtons +import dev.inmo.plaguposter.ratings.source.buttons.includeRootNavigationButtonsHandler import dev.inmo.plaguposter.ratings.source.models.* import dev.inmo.plaguposter.ratings.source.repos.* import dev.inmo.plaguposter.ratings.utils.postsByRatings @@ -34,6 +36,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.* 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.extensions.utils.types.buttons.inlineKeyboard import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton import dev.inmo.tgbotapi.types.message.textsources.bold import dev.inmo.tgbotapi.types.message.textsources.regular @@ -225,13 +228,23 @@ object Plugin : Plugin { + "• " + bold("% 3.1f".format(it.first.double)) + ": " + bold(it.second.size.toString()) + "\n" } } + val keyboard = flatInlineKeyboard { + dataButton("Interactive mode", "ratings_interactive") + } runCatchingSafely { - edit(it, textSources) + edit(it, textSources, replyMarkup = keyboard) }.onFailure { _ -> - reply(it, textSources) + reply(it, textSources, replyMarkup = keyboard) } } } + includeRootNavigationButtonsHandler(setOf(chatConfig.sourceChatId), ratingsRepo, postsRepo) + onMessageDataCallbackQuery("ratings_interactive", initialFilter = { it.message.chat.id == chatConfig.sourceChatId }) { + edit( + it.message, + ratingsRepo.buildRootButtons() + ) + } koin.getOrNull() ?.apply { addTemplate(