reverted CustomBot body

This commit is contained in:
bpavuk 2024-07-10 19:33:40 +03:00
parent 7964dc4eea
commit 358f2d27d3
No known key found for this signature in database
GPG Key ID: B501D26D9DEA9CFE

View File

@ -3,19 +3,14 @@ import dev.inmo.kslog.common.LogLevel
import dev.inmo.kslog.common.defaultMessageFormatter import dev.inmo.kslog.common.defaultMessageFormatter
import dev.inmo.kslog.common.setDefaultKSLog import dev.inmo.kslog.common.setDefaultKSLog
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions 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.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.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
/** /**
* The main purpose of this bot is just to answer "Oh, hi, " and add user mention here. * This place can be the playground for your code.
* Also, this place can be the playground for your code.
*/ */
@OptIn(PreviewFeature::class)
suspend fun main(vararg args: String) { suspend fun main(vararg args: String) {
val botToken = args.first() val botToken = args.first()
@ -30,14 +25,10 @@ suspend fun main(vararg args: String) {
} }
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) { telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { update -> // start here!!
update.asMessageUpdate()?.let { safeMessageUpdate -> val me = getMe()
val user = safeMessageUpdate.data.from println(me)
val replyMessage = if (user != null) {
"Oh, hi, ${user.username ?: user.firstName}!" allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { println(it) }
} else "Oh, hi!"
reply(to = safeMessageUpdate.data, text = replyMessage)
}
}
}.second.join() }.second.join()
} }