From 323c21f415f451014f4a77a90d4d7dc24ec04b3a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 19 May 2023 22:45:46 +0600 Subject: [PATCH] upgrade of hello bot --- HelloBot/src/main/kotlin/HelloBot.kt | 11 +++++++---- gradle.properties | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/HelloBot/src/main/kotlin/HelloBot.kt b/HelloBot/src/main/kotlin/HelloBot.kt index f040c5f..10f83eb 100644 --- a/HelloBot/src/main/kotlin/HelloBot.kt +++ b/HelloBot/src/main/kotlin/HelloBot.kt @@ -1,8 +1,10 @@ import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +import dev.inmo.tgbotapi.extensions.api.bot.getMe import dev.inmo.tgbotapi.extensions.api.chat.get.getChat import dev.inmo.tgbotapi.extensions.api.send.* import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMentionWithAnyContent import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sender_chat import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2 import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2 @@ -25,24 +27,25 @@ suspend fun main(vararg args: String) { val botToken = args.first() telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) { - onContentMessage { message -> + val me = getMe() + onMentionWithAnyContent(me.username) { message -> val chat = message.chat val answerText = when (val chat = message.chat) { is ChannelChat -> { val answer = "Hi everybody in this channel \"${chat.title}\"" reply(message, answer, MarkdownV2) - return@onContentMessage + return@onMentionWithAnyContent } is PrivateChat -> { reply(message, "Hi, " + "${chat.firstName} ${chat.lastName}".textMentionMarkdownV2(chat.id), MarkdownV2) - return@onContentMessage + return@onMentionWithAnyContent } is GroupChat -> { message.ifFromChannelGroupContentMessage { val answer = "Hi, ${it.senderChat.title}" reply(message, answer, MarkdownV2) - return@onContentMessage + return@onMentionWithAnyContent } "Oh, hi, " + when (chat) { is SupergroupChat -> (chat.username ?.username ?: getChat(chat).inviteLink) ?.let { diff --git a/gradle.properties b/gradle.properties index 99f7aa0..45412cb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx2g kotlin_version=1.8.21 -telegram_bot_api_version=7.1.2 -micro_utils_version=0.18.1 -serialization_version=1.5.0 +telegram_bot_api_version=7.1.3-branch_7.1.3-build1645 +micro_utils_version=0.18.4 +serialization_version=1.5.1 ktor_version=2.3.0