mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-11-22 08:13:53 +00:00
reverted CustomBot body
This commit is contained in:
parent
7964dc4eea
commit
358f2d27d3
@ -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()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user