diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c1e40fb..5c36b38 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -34,7 +34,6 @@ android-test-junit = { module = "androidx.test.ext:junit", version.ref = "test_e android-test-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espresso_core" } tgbotapi = { module = "dev.inmo:tgbotapi", version.ref = "tgbotapi" } -tgbotapi-admins = { module = "dev.inmo:tgbotapi.libraries.cache.admins.plagubot", version.ref = "tgbotapi-libraries" } 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" } diff --git a/inlines/build.gradle b/inlines/build.gradle index 89646e6..c3a8634 100644 --- a/inlines/build.gradle +++ b/inlines/build.gradle @@ -11,7 +11,6 @@ kotlin { commonMain { dependencies { api project(":plaguposter.common") - api libs.tgbotapi.admins } } jvmMain { diff --git a/inlines/src/jvmMain/kotlin/Plugin.kt b/inlines/src/jvmMain/kotlin/Plugin.kt index 2152d2f..98550a5 100644 --- a/inlines/src/jvmMain/kotlin/Plugin.kt +++ b/inlines/src/jvmMain/kotlin/Plugin.kt @@ -4,14 +4,16 @@ import dev.inmo.micro_utils.pagination.Pagination import dev.inmo.micro_utils.pagination.utils.paginate 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.libraries.cache.admins.AdminsCacheAPI -import dev.inmo.tgbotapi.libraries.cache.admins.adminsPlugin +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.* @@ -30,15 +32,10 @@ object Plugin : Plugin { } override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) { - val adminsApi = koin.get() - val chatConfig = koin.get() val templatesRepo = koin.get() onBaseInlineQuery { query -> - if (!adminsApi.isAdmin(chatConfig.sourceChatId, query.from.id)) { - answerInlineQuery(query, cachedTime = 0) - return@onBaseInlineQuery - } val page = query.offset.toIntOrNull() ?: 0 + val queryString = query.query.trim() try { answerInlineQuery( query, @@ -50,7 +47,7 @@ object Plugin : Plugin { ).results.mapIndexedNotNull { index, offerTemplate -> offerTemplate.createArticleResult( index.toString(), - query.query + queryString ) }, nextOffset = (page + 1).toString(), @@ -63,5 +60,22 @@ object Plugin : Plugin { ) } } + onCommand("help", requireOnlyCommandInMessage = true) { + reply( + it, + "Push the button above to see available commands", + replyMarkup = flatInlineKeyboard { + inlineQueryInCurrentChatButton("Toggle commands", "") + } + ) + } + koin.getOrNull() ?.apply { + addTemplate( + OfferTemplate( + "Trigger help button", + listOf(Format("/help")) + ) + ) + } } } diff --git a/posts_registrar/src/jvmMain/kotlin/Plugin.kt b/posts_registrar/src/jvmMain/kotlin/Plugin.kt index 3b42989..65eecd3 100644 --- a/posts_registrar/src/jvmMain/kotlin/Plugin.kt +++ b/posts_registrar/src/jvmMain/kotlin/Plugin.kt @@ -141,7 +141,7 @@ object Plugin : Plugin { addTemplate( OfferTemplate( "Start post", - listOf(Format("start_post")) + listOf(Format("/start_post")) ) ) } diff --git a/ratings/selector/src/commonMain/kotlin/models/RatingConfig.kt b/ratings/selector/src/commonMain/kotlin/models/RatingConfig.kt index 6b8def9..e21a9ab 100644 --- a/ratings/selector/src/commonMain/kotlin/models/RatingConfig.kt +++ b/ratings/selector/src/commonMain/kotlin/models/RatingConfig.kt @@ -109,7 +109,7 @@ data class RatingConfig( } companion object { - val values = arrayOf(Max, Min, Random) + val values: Array = arrayOf(Max, Min, Random) } } } diff --git a/ratings/source/src/jvmMain/kotlin/Plugin.kt b/ratings/source/src/jvmMain/kotlin/Plugin.kt index 9594e3c..a006328 100644 --- a/ratings/source/src/jvmMain/kotlin/Plugin.kt +++ b/ratings/source/src/jvmMain/kotlin/Plugin.kt @@ -197,14 +197,14 @@ object Plugin : Plugin { addTemplate( OfferTemplate( "Enable ratings for post", - listOf(Format("attach_ratings")), + listOf(Format("/attach_ratings")), "Require reply on post message" ) ) addTemplate( OfferTemplate( "Disable ratings for post", - listOf(Format("detach_ratings")), + listOf(Format("/detach_ratings")), "Require reply on post message" ) ) diff --git a/runner/build.gradle b/runner/build.gradle index 95abe8a..466312e 100644 --- a/runner/build.gradle +++ b/runner/build.gradle @@ -9,7 +9,6 @@ project.version = null dependencies { implementation libs.kotlin api libs.plagubot.bot - api libs.tgbotapi.admins api project(":plaguposter.posts") api project(":plaguposter.posts_registrar") diff --git a/runner/config.json b/runner/config.json index 7906d00..22676fb 100644 --- a/runner/config.json +++ b/runner/config.json @@ -14,8 +14,8 @@ "dev.inmo.plaguposter.ratings.selector.Plugin", "dev.inmo.plaguposter.triggers.selector_with_timer.Plugin", "dev.inmo.plaguposter.ratings.gc.Plugin", - "dev.inmo.tgbotapi.libraries.cache.admins.AdminsPlugin", - "dev.inmo.plaguposter.inlines.Plugin" + "dev.inmo.plaguposter.inlines.Plugin", + "dev.inmo.plaguposter.triggers.command.Plugin" ], "posts": { "targetChat": 12345678, diff --git a/triggers/command/src/jvmMain/kotlin/Plugin.kt b/triggers/command/src/jvmMain/kotlin/Plugin.kt index 9bd6123..539cd5c 100644 --- a/triggers/command/src/jvmMain/kotlin/Plugin.kt +++ b/triggers/command/src/jvmMain/kotlin/Plugin.kt @@ -45,12 +45,18 @@ object Plugin : Plugin { val selector = koin.getOrNull() onCommand("publish_post") { - val messageInReply = it.replyTo ?.contentMessageOrNull() ?: let { _ -> - reply(it, "You should reply some message of post to trigger it for posting") + val messageInReply = it.replyTo ?.contentMessageOrNull() ?: run { + if (selector == null) { + reply(it, "You should reply some message of post to trigger it for posting") - return@onCommand + return@onCommand + } else { + null + } } - val postId = postsRepo.getIdByChatAndMessage(messageInReply.chat.id, messageInReply.messageId) ?: selector ?.take(1) ?.firstOrNull() + val postId = messageInReply ?.let { + postsRepo.getIdByChatAndMessage(messageInReply.chat.id, messageInReply.messageId) + } ?: selector ?.take(1) ?.firstOrNull() if (postId == null) { reply( it, @@ -72,7 +78,7 @@ object Plugin : Plugin { addTemplate( OfferTemplate( "Publish post", - listOf(Format("publish_post")), + listOf(Format("/publish_post")), if (selector == null) { "Require reply on post message" } else {