From 358f2d27d375cfae6f2d9892b593286ee85fc175 Mon Sep 17 00:00:00 2001 From: bpavuk Date: Wed, 10 Jul 2024 19:33:40 +0300 Subject: [PATCH] reverted CustomBot body --- CustomBot/src/main/kotlin/CustomBot.kt | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/CustomBot/src/main/kotlin/CustomBot.kt b/CustomBot/src/main/kotlin/CustomBot.kt index 3cbafad..dc7d7b2 100644 --- a/CustomBot/src/main/kotlin/CustomBot.kt +++ b/CustomBot/src/main/kotlin/CustomBot.kt @@ -3,19 +3,14 @@ import dev.inmo.kslog.common.LogLevel import dev.inmo.kslog.common.defaultMessageFormatter import dev.inmo.kslog.common.setDefaultKSLog import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions -import dev.inmo.tgbotapi.extensions.api.send.reply +import dev.inmo.tgbotapi.extensions.api.bot.getMe import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling -import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate -import dev.inmo.tgbotapi.extensions.utils.extensions.raw.from -import dev.inmo.tgbotapi.utils.PreviewFeature import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers /** - * The main purpose of this bot is just to answer "Oh, hi, " and add user mention here. - * Also, this place can be the playground for your code. + * This place can be the playground for your code. */ -@OptIn(PreviewFeature::class) suspend fun main(vararg args: String) { val botToken = args.first() @@ -30,14 +25,10 @@ suspend fun main(vararg args: String) { } telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) { - allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { update -> - update.asMessageUpdate()?.let { safeMessageUpdate -> - val user = safeMessageUpdate.data.from - val replyMessage = if (user != null) { - "Oh, hi, ${user.username ?: user.firstName}!" - } else "Oh, hi!" - reply(to = safeMessageUpdate.data, text = replyMessage) - } - } + // start here!! + val me = getMe() + println(me) + + allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { println(it) } }.second.join() }