From 5808f45677ffbd2b6d7a66711768b043b54ed370 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 16 Sep 2022 15:32:48 +0600 Subject: [PATCH 1/4] start 0.0.3 --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index e1644be..383a2a3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,5 +10,5 @@ android.enableJetifier=true # Project data group=dev.inmo -version=0.0.2 -android_code_version=2 +version=0.0.3 +android_code_version=3 From 91221d865c8ea8fcab1ed9c2848697f0d7d5a667 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 16 Sep 2022 15:34:08 +0600 Subject: [PATCH 2/4] update dependencies --- gradle/libs.versions.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 712cfa7..3f453c9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,14 +3,14 @@ kotlin = "1.7.10" kotlin-serialization = "1.4.0" -plagubot = "2.3.1" -tgbotapi = "3.2.1" +plagubot = "2.3.2" +tgbotapi = "3.2.3" microutils = "0.12.13" kslog = "0.5.2" krontab = "0.8.1" tgbotapi-libraries = "0.5.3" -psql = "42.3.6" +psql = "42.5.0" dexcount = "3.1.0" junit_version = "4.12" From 79c195f534227b9e8bfc9100950d8a90b0cccdee Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 16 Sep 2022 16:53:57 +0600 Subject: [PATCH 3/4] small updates --- posts/panel/src/jvmMain/kotlin/Plugin.kt | 41 +++++++++++++++++---- ratings/source/src/jvmMain/kotlin/Plugin.kt | 1 + 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/posts/panel/src/jvmMain/kotlin/Plugin.kt b/posts/panel/src/jvmMain/kotlin/Plugin.kt index d06b18a..7e2c2a3 100644 --- a/posts/panel/src/jvmMain/kotlin/Plugin.kt +++ b/posts/panel/src/jvmMain/kotlin/Plugin.kt @@ -10,8 +10,10 @@ import dev.inmo.plaguposter.common.ChatConfig import dev.inmo.plaguposter.posts.models.PostId import dev.inmo.plaguposter.posts.panel.repos.PostsMessages import dev.inmo.plaguposter.posts.repo.PostsRepo +import dev.inmo.tgbotapi.extensions.api.answers.answer import dev.inmo.tgbotapi.extensions.api.delete import dev.inmo.tgbotapi.extensions.api.edit.edit +import dev.inmo.tgbotapi.extensions.api.edit.text.editMessageText import dev.inmo.tgbotapi.extensions.api.send.send import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitMessageDataCallbackQuery @@ -19,14 +21,11 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMessag 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.withContentOrNull import dev.inmo.tgbotapi.types.ChatId import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.message.ParseMode -import dev.inmo.tgbotapi.types.message.abstracts.Message -import dev.inmo.tgbotapi.types.message.content.TextContent import kotlinx.coroutines.flow.first import kotlinx.serialization.Serializable import kotlinx.serialization.json.* @@ -41,7 +40,8 @@ object Plugin : Plugin { val parseMode: ParseMode? = null, val buttonsPerRow: Int = 4, val deleteButtonText: String? = null, - val rootButtonText: String = "Return to panel" + val rootButtonText: String = "\uD83D\uDD19", + val refreshButtonText: String = "\uD83D\uDD04" ) override fun Module.setupDI(database: Database, params: JsonObject) { params["panel"] ?.let { element -> @@ -57,6 +57,14 @@ object Plugin : Plugin { "delete ${it.id.string}" ) } + }, + config.refreshButtonText.let { text -> + PanelButtonBuilder { + CallbackDataInlineKeyboardButton( + text, + "refresh ${it.id.string}" + ) + } } ) PanelButtonsAPI( @@ -97,7 +105,7 @@ object Plugin : Plugin { delete(chatId, messageId) } - suspend fun updatePost( + suspend fun refreshPostMessage( postId: PostId, chatId: ChatId, messageId: MessageIdentifier @@ -108,9 +116,10 @@ object Plugin : Plugin { builder.buildButton(post) }.takeIf { it.isNotEmpty() } } - edit( + editMessageText( chatId, messageId, + text = config.text, replyMarkup = InlineKeyboardMarkup(buttons) ) } @@ -121,7 +130,7 @@ object Plugin : Plugin { } ) { val postId = it.data.removePrefix(PanelButtonsAPI.openGlobalMenuDataPrefix).let(::PostId) - updatePost(postId, it.message.chat.id, it.message.messageId) + refreshPostMessage(postId, it.message.chat.id, it.message.messageId) } onMessageDataCallbackQuery( initialFilter = { @@ -140,6 +149,7 @@ object Plugin : Plugin { api.RootPanelButtonBuilder.buildButton(post) ?.let(::add) } ) + answer(query) val pushedButton = waitMessageDataCallbackQuery().first { it.message.sameMessage(query.message) @@ -149,10 +159,25 @@ object Plugin : Plugin { postsRepo.deleteById(postId) } } + onMessageDataCallbackQuery( + initialFilter = { + it.data.startsWith("refresh ") && it.message.chat.id == chatsConfig.sourceChatId + } + ) { query -> + val postId = query.data.removePrefix("refresh ").let(::PostId) + val (chatId, messageId) = postsMessages.get(postId) ?: return@onMessageDataCallbackQuery + + refreshPostMessage( + postId, + chatId, + messageId + ) + answer(query) + } api.forceRefreshFlow.subscribeSafelyWithoutExceptions(this) { val (chatId, messageId) = postsMessages.get(it) ?: return@subscribeSafelyWithoutExceptions - updatePost(it, chatId, messageId) + refreshPostMessage(it, chatId, messageId) } } } diff --git a/ratings/source/src/jvmMain/kotlin/Plugin.kt b/ratings/source/src/jvmMain/kotlin/Plugin.kt index 4592508..a9a2631 100644 --- a/ratings/source/src/jvmMain/kotlin/Plugin.kt +++ b/ratings/source/src/jvmMain/kotlin/Plugin.kt @@ -273,6 +273,7 @@ object Plugin : Plugin { attachPoll(postId) } } + answer(it) } } } From b9700a8fd90305ef561e579a315b809c2b83d989 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 16 Sep 2022 21:11:30 +0600 Subject: [PATCH 4/4] make force refresh button optional --- posts/panel/src/jvmMain/kotlin/Plugin.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/posts/panel/src/jvmMain/kotlin/Plugin.kt b/posts/panel/src/jvmMain/kotlin/Plugin.kt index 7e2c2a3..eee6540 100644 --- a/posts/panel/src/jvmMain/kotlin/Plugin.kt +++ b/posts/panel/src/jvmMain/kotlin/Plugin.kt @@ -41,7 +41,7 @@ object Plugin : Plugin { val buttonsPerRow: Int = 4, val deleteButtonText: String? = null, val rootButtonText: String = "\uD83D\uDD19", - val refreshButtonText: String = "\uD83D\uDD04" + val refreshButtonText: String? = "\uD83D\uDD04" ) override fun Module.setupDI(database: Database, params: JsonObject) { params["panel"] ?.let { element -> @@ -58,7 +58,7 @@ object Plugin : Plugin { ) } }, - config.refreshButtonText.let { text -> + config.refreshButtonText ?.let { text -> PanelButtonBuilder { CallbackDataInlineKeyboardButton( text,