mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-11-22 08:13:53 +00:00
commit
4addb6c755
@ -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 {
|
||||
|
@ -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
|
||||
micro_utils_version=0.18.4
|
||||
serialization_version=1.5.1
|
||||
ktor_version=2.3.0
|
||||
|
Loading…
Reference in New Issue
Block a user