mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-11-22 16:23:54 +00:00
small fixes
This commit is contained in:
parent
9fa3690db6
commit
0ebfb3c44a
@ -3,8 +3,11 @@ import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
|||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
import dev.inmo.tgbotapi.extensions.api.send.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
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.onContentMessage
|
||||||
|
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.linkMarkdownV2
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2
|
import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.ifChannelChat
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.ifFromChannelGroupContentMessage
|
||||||
import dev.inmo.tgbotapi.types.chat.*
|
import dev.inmo.tgbotapi.types.chat.*
|
||||||
import dev.inmo.tgbotapi.types.chat.GroupChat
|
import dev.inmo.tgbotapi.types.chat.GroupChat
|
||||||
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
||||||
@ -24,21 +27,35 @@ suspend fun main(vararg args: String) {
|
|||||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
onContentMessage { message ->
|
onContentMessage { message ->
|
||||||
val chat = message.chat
|
val chat = message.chat
|
||||||
if (chat is ChannelChat) {
|
|
||||||
|
val answerText = when (val chat = message.chat) {
|
||||||
|
is ChannelChat -> {
|
||||||
val answer = "Hi everybody in this channel \"${chat.title}\""
|
val answer = "Hi everybody in this channel \"${chat.title}\""
|
||||||
send(chat, answer, MarkdownV2)
|
reply(message, answer, MarkdownV2)
|
||||||
return@onContentMessage
|
return@onContentMessage
|
||||||
}
|
}
|
||||||
val answerText = "Oh, hi, " + when (chat) {
|
is PrivateChat -> {
|
||||||
is User -> "${chat.firstName} ${chat.lastName}".textMentionMarkdownV2(chat.id)
|
reply(message, "Hi, " + "${chat.firstName} ${chat.lastName}".textMentionMarkdownV2(chat.id), MarkdownV2)
|
||||||
is PrivateChat -> "${chat.firstName} ${chat.lastName}".textMentionMarkdownV2(chat.id)
|
return@onContentMessage
|
||||||
|
}
|
||||||
|
is GroupChat -> {
|
||||||
|
message.ifFromChannelGroupContentMessage {
|
||||||
|
val answer = "Hi, ${it.senderChat.title}"
|
||||||
|
reply(message, answer, MarkdownV2)
|
||||||
|
return@onContentMessage
|
||||||
|
}
|
||||||
|
"Oh, hi, " + when (chat) {
|
||||||
is SupergroupChat -> (chat.username ?.username ?: getChat(chat).inviteLink) ?.let {
|
is SupergroupChat -> (chat.username ?.username ?: getChat(chat).inviteLink) ?.let {
|
||||||
chat.title.linkMarkdownV2(it)
|
chat.title.linkMarkdownV2(it)
|
||||||
} ?: chat.title
|
} ?: chat.title
|
||||||
is GroupChat -> bot.getChat(chat).inviteLink ?.let {
|
else -> bot.getChat(chat).inviteLink ?.let {
|
||||||
chat.title.linkMarkdownV2(it)
|
chat.title.linkMarkdownV2(it)
|
||||||
} ?: chat.title
|
} ?: chat.title
|
||||||
else -> "Unknown :(".escapeMarkdownV2Common()
|
}
|
||||||
|
}
|
||||||
|
is UnknownExtendedChat,
|
||||||
|
is UnknownChatType -> "Unknown :(".escapeMarkdownV2Common()
|
||||||
|
else -> error("Something went wrong: unknown type of chat $chat")
|
||||||
}
|
}
|
||||||
reply(
|
reply(
|
||||||
message,
|
message,
|
||||||
|
Loading…
Reference in New Issue
Block a user