mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-12-22 08:37:18 +00:00
code cleanup
optimized imports here and there, made CustomBot working as intended
This commit is contained in:
parent
9fb6570d21
commit
7964dc4eea
@ -4,13 +4,13 @@ import dev.inmo.kslog.common.defaultMessageFormatter
|
|||||||
import dev.inmo.kslog.common.setDefaultKSLog
|
import dev.inmo.kslog.common.setDefaultKSLog
|
||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.api.get.getUserChatBoosts
|
import dev.inmo.tgbotapi.extensions.api.get.getUserChatBoosts
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatBoostUpdated
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatBoostUpdated
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatShared
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatShared
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatReplyKeyboard
|
||||||
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.requestChannelButton
|
||||||
import dev.inmo.tgbotapi.types.request.RequestId
|
import dev.inmo.tgbotapi.types.request.RequestId
|
||||||
import dev.inmo.tgbotapi.utils.regular
|
import dev.inmo.tgbotapi.utils.regular
|
||||||
import korlibs.time.DateFormat
|
import korlibs.time.DateFormat
|
||||||
|
@ -49,22 +49,22 @@ suspend fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onContentMessage {
|
onContentMessage {
|
||||||
it.ifBusinessContentMessage {
|
it.ifBusinessContentMessage { businessContentMessage ->
|
||||||
val sent = execute(it.content.createResend(it.from.id))
|
val sent = execute(it.content.createResend(businessContentMessage.from.id))
|
||||||
if (it.sentByBusinessConnectionOwner) {
|
if (businessContentMessage.sentByBusinessConnectionOwner) {
|
||||||
reply(sent, "You have sent this message to the ${it.businessConnectionId.string} related chat")
|
reply(sent, "You have sent this message to the ${businessContentMessage.businessConnectionId.string} related chat")
|
||||||
} else {
|
} else {
|
||||||
reply(sent, "User have sent this message to you in the ${it.businessConnectionId.string} related chat")
|
reply(sent, "User have sent this message to you in the ${businessContentMessage.businessConnectionId.string} related chat")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onEditedContentMessage {
|
onEditedContentMessage {
|
||||||
it.ifBusinessContentMessage {
|
it.ifBusinessContentMessage { businessContentMessage ->
|
||||||
val sent = execute(it.content.createResend(it.from.id))
|
val sent = execute(businessContentMessage.content.createResend(businessContentMessage.from.id))
|
||||||
if (it.sentByBusinessConnectionOwner) {
|
if (businessContentMessage.sentByBusinessConnectionOwner) {
|
||||||
reply(sent, "You have edited this message in the ${it.businessConnectionId.string} related chat")
|
reply(sent, "You have edited this message in the ${businessContentMessage.businessConnectionId.string} related chat")
|
||||||
} else {
|
} else {
|
||||||
reply(sent, "User have edited this message to you in the ${it.businessConnectionId.string} related chat")
|
reply(sent, "User have edited this message to you in the ${businessContentMessage.businessConnectionId.string} related chat")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,9 @@ import dev.inmo.tgbotapi.extensions.api.files.downloadFile
|
|||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onPhoto
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onPhoto
|
||||||
import dev.inmo.tgbotapi.extensions.utils.*
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
|
||||||
suspend fun main(args: Array<String>) {
|
suspend fun main(args: Array<String>) {
|
||||||
val bot = telegramBot(args.first())
|
val bot = telegramBot(args.first())
|
||||||
|
@ -3,13 +3,17 @@ 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.bot.getMe
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
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 dev.inmo.tgbotapi.utils.PreviewFeature
|
||||||
import kotlinx.coroutines.*
|
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
|
* 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.
|
||||||
*/
|
*/
|
||||||
@OptIn(PreviewFeature::class)
|
@OptIn(PreviewFeature::class)
|
||||||
suspend fun main(vararg args: String) {
|
suspend fun main(vararg args: String) {
|
||||||
@ -26,8 +30,14 @@ suspend fun main(vararg args: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
val me = getMe()
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { update ->
|
||||||
|
update.asMessageUpdate()?.let { safeMessageUpdate ->
|
||||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { println(it) }
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}.second.join()
|
}.second.join()
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelySkippingExceptions
|
|
||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitDeepLinks
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitDeepLinks
|
||||||
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.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onDeepLink
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onText
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.makeTelegramDeepLink
|
import dev.inmo.tgbotapi.extensions.utils.formatting.makeTelegramDeepLink
|
||||||
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
|
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
|
||||||
|
|
||||||
|
@ -1,23 +1,20 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.AccumulatorFlow
|
|
||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.micro_utils.fsm.common.State
|
import dev.inmo.micro_utils.fsm.common.State
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.send
|
import dev.inmo.tgbotapi.extensions.api.send.send
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.sendMessage
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitAnyContentMessage
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndFSMAndStartLongPolling
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.command
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithArgs
|
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithArgs
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.sameThread
|
import dev.inmo.tgbotapi.extensions.utils.extensions.sameThread
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.textContentOrNull
|
import dev.inmo.tgbotapi.extensions.utils.textContentOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
|
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
|
||||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||||
import dev.inmo.tgbotapi.types.MessageThreadId
|
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
import dev.inmo.tgbotapi.utils.botCommand
|
import dev.inmo.tgbotapi.utils.botCommand
|
||||||
import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.filter
|
import kotlinx.coroutines.flow.filter
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
|
|
||||||
|
@ -2,38 +2,17 @@ import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
|||||||
import dev.inmo.tgbotapi.extensions.api.files.downloadFile
|
import dev.inmo.tgbotapi.extensions.api.files.downloadFile
|
||||||
import dev.inmo.tgbotapi.extensions.api.files.downloadFileToTemp
|
import dev.inmo.tgbotapi.extensions.api.files.downloadFileToTemp
|
||||||
import dev.inmo.tgbotapi.extensions.api.get.getFileAdditionalInfo
|
import dev.inmo.tgbotapi.extensions.api.get.getFileAdditionalInfo
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
import dev.inmo.tgbotapi.extensions.api.send.*
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.replyWithAnimation
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.replyWithAudio
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.replyWithDocument
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.replyWithMediaGroup
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.replyWithPhoto
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.replyWithSticker
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.replyWithVideo
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.replyWithVideoNote
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.replyWithVoice
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.withAction
|
|
||||||
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.onCommand
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMedia
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMedia
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
||||||
import dev.inmo.tgbotapi.requests.send.SendAction
|
|
||||||
import dev.inmo.tgbotapi.types.actions.BotAction
|
|
||||||
import dev.inmo.tgbotapi.types.actions.TypingAction
|
import dev.inmo.tgbotapi.types.actions.TypingAction
|
||||||
import dev.inmo.tgbotapi.types.media.TelegramMediaAudio
|
import dev.inmo.tgbotapi.types.media.TelegramMediaAudio
|
||||||
import dev.inmo.tgbotapi.types.media.TelegramMediaDocument
|
import dev.inmo.tgbotapi.types.media.TelegramMediaDocument
|
||||||
import dev.inmo.tgbotapi.types.media.TelegramMediaPhoto
|
import dev.inmo.tgbotapi.types.media.TelegramMediaPhoto
|
||||||
import dev.inmo.tgbotapi.types.media.TelegramMediaVideo
|
import dev.inmo.tgbotapi.types.media.TelegramMediaVideo
|
||||||
import dev.inmo.tgbotapi.types.message.content.AnimationContent
|
import dev.inmo.tgbotapi.types.message.content.*
|
||||||
import dev.inmo.tgbotapi.types.message.content.AudioContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.DocumentContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.PhotoContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.StickerContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.VideoContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.VideoNoteContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.VoiceContent
|
|
||||||
import dev.inmo.tgbotapi.utils.filenameFromUrl
|
import dev.inmo.tgbotapi.utils.filenameFromUrl
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
import dev.inmo.kslog.common.KSLog
|
import dev.inmo.kslog.common.KSLog
|
||||||
import dev.inmo.kslog.common.LogLevel
|
import dev.inmo.kslog.common.LogLevel
|
||||||
import dev.inmo.kslog.common.defaultMessageFormatter
|
import dev.inmo.kslog.common.defaultMessageFormatter
|
||||||
import dev.inmo.kslog.common.filter.filtered
|
|
||||||
import dev.inmo.kslog.common.setDefaultKSLog
|
import dev.inmo.kslog.common.setDefaultKSLog
|
||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
||||||
import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is one of the most easiest bot - it will just print information about itself
|
* This is one of the easiest bots - it will just print information about itself
|
||||||
*/
|
*/
|
||||||
suspend fun main(vararg args: String) {
|
suspend fun main(vararg args: String) {
|
||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
|
@ -1,23 +1,18 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
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.onMentionWithAnyContent
|
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.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.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.PrivateChat
|
|
||||||
import dev.inmo.tgbotapi.types.chat.SupergroupChat
|
|
||||||
import dev.inmo.tgbotapi.types.message.MarkdownV2
|
import dev.inmo.tgbotapi.types.message.MarkdownV2
|
||||||
import dev.inmo.tgbotapi.utils.PreviewFeature
|
import dev.inmo.tgbotapi.utils.PreviewFeature
|
||||||
import dev.inmo.tgbotapi.utils.extensions.escapeMarkdownV2Common
|
import dev.inmo.tgbotapi.utils.extensions.escapeMarkdownV2Common
|
||||||
import kotlinx.coroutines.*
|
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
|
* The main purpose of this bot is just to answer "Oh, hi, " and add user mention here
|
||||||
@ -29,8 +24,6 @@ suspend fun main(vararg args: String) {
|
|||||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
val me = getMe()
|
val me = getMe()
|
||||||
onMentionWithAnyContent(me) { message ->
|
onMentionWithAnyContent(me) { message ->
|
||||||
val chat = message.chat
|
|
||||||
|
|
||||||
val answerText = when (val chat = message.chat) {
|
val answerText = when (val chat = message.chat) {
|
||||||
is PreviewChannelChat -> {
|
is PreviewChannelChat -> {
|
||||||
val answer = "Hi everybody in this channel \"${chat.title}\""
|
val answer = "Hi everybody in this channel \"${chat.title}\""
|
||||||
@ -42,7 +35,7 @@ suspend fun main(vararg args: String) {
|
|||||||
return@onMentionWithAnyContent
|
return@onMentionWithAnyContent
|
||||||
}
|
}
|
||||||
is PreviewGroupChat -> {
|
is PreviewGroupChat -> {
|
||||||
message.ifFromChannelGroupContentMessage {
|
message.ifFromChannelGroupContentMessage<Unit> {
|
||||||
val answer = "Hi, ${it.senderChat.title}"
|
val answer = "Hi, ${it.senderChat.title}"
|
||||||
reply(message, answer, MarkdownV2)
|
reply(message, answer, MarkdownV2)
|
||||||
return@onMentionWithAnyContent
|
return@onMentionWithAnyContent
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import dev.inmo.micro_utils.common.MPPFile
|
|
||||||
|
|
||||||
suspend fun main(args: Array<String>) {
|
suspend fun main(args: Array<String>) {
|
||||||
doInlineQueriesBot(args.first())
|
doInlineQueriesBot(args.first())
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
|
||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
import dev.inmo.tgbotapi.extensions.api.edit.edit
|
import dev.inmo.tgbotapi.extensions.api.edit.edit
|
||||||
import dev.inmo.tgbotapi.extensions.api.edit.editMessageText
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.edit.reply_markup.editMessageReplyMarkup
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.edit.text.editMessageText
|
import dev.inmo.tgbotapi.extensions.api.edit.text.editMessageText
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
||||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
import dev.inmo.tgbotapi.extensions.utils.withContent
|
||||||
@ -17,11 +15,13 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResult
|
|||||||
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
||||||
import dev.inmo.tgbotapi.types.InlineQueryId
|
import dev.inmo.tgbotapi.types.InlineQueryId
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
import dev.inmo.tgbotapi.utils.*
|
import dev.inmo.tgbotapi.utils.PreviewFeature
|
||||||
import kotlinx.coroutines.*
|
import dev.inmo.tgbotapi.utils.botCommand
|
||||||
|
import dev.inmo.tgbotapi.utils.regular
|
||||||
private const val nextPageData = "next"
|
import dev.inmo.tgbotapi.utils.row
|
||||||
private const val previousPageData = "previous"
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
import kotlinx.coroutines.currentCoroutineContext
|
||||||
|
|
||||||
fun String.parsePageAndCount(): Pair<Int, Int>? {
|
fun String.parsePageAndCount(): Pair<Int, Int>? {
|
||||||
val (pageString, countString) = split(" ").takeIf { it.count() > 1 } ?: return null
|
val (pageString, countString) = split(" ").takeIf { it.count() > 1 } ?: return null
|
||||||
@ -73,6 +73,7 @@ fun InlineKeyboardBuilder.includePageButtons(page: Int, count: Int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(PreviewFeature::class)
|
||||||
suspend fun activateKeyboardsBot(
|
suspend fun activateKeyboardsBot(
|
||||||
token: String,
|
token: String,
|
||||||
print: (Any) -> Unit
|
print: (Any) -> Unit
|
||||||
|
@ -3,24 +3,15 @@ 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.tgbotapi.bot.ktor.telegramBot
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.copyMessage
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.send
|
import dev.inmo.tgbotapi.extensions.api.send.send
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.setMessageReaction
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMessageReactionUpdatedByUser
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMessageReactionsCountUpdated
|
|
||||||
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.textLinkTextSourceOrNull
|
import dev.inmo.tgbotapi.extensions.utils.textLinkTextSourceOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.uRLTextSourceOrNull
|
import dev.inmo.tgbotapi.extensions.utils.uRLTextSourceOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
|
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
|
||||||
import dev.inmo.tgbotapi.types.LinkPreviewOptions
|
import dev.inmo.tgbotapi.types.LinkPreviewOptions
|
||||||
import dev.inmo.tgbotapi.types.chat.ExtendedChat
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextedContent
|
import dev.inmo.tgbotapi.types.message.content.TextedContent
|
||||||
import dev.inmo.tgbotapi.types.reactions.Reaction
|
|
||||||
import dev.inmo.tgbotapi.utils.customEmoji
|
|
||||||
import dev.inmo.tgbotapi.utils.regular
|
import dev.inmo.tgbotapi.utils.regular
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,17 +32,17 @@ suspend fun main(vararg args: String) {
|
|||||||
val bot = telegramBot(botToken)
|
val bot = telegramBot(botToken)
|
||||||
|
|
||||||
bot.buildBehaviourWithLongPolling {
|
bot.buildBehaviourWithLongPolling {
|
||||||
onContentMessage {
|
onContentMessage { contentMessage ->
|
||||||
val url = it.withContentOrNull<TextedContent>() ?.let {
|
val url = contentMessage.withContentOrNull<TextedContent>() ?.let { message ->
|
||||||
it.content.textSources.firstNotNullOfOrNull {
|
message.content.textSources.firstNotNullOfOrNull {
|
||||||
it.textLinkTextSourceOrNull() ?.url ?: it.uRLTextSourceOrNull() ?.source
|
it.textLinkTextSourceOrNull() ?.url ?: it.uRLTextSourceOrNull() ?.source
|
||||||
}
|
}
|
||||||
} ?: null.apply {
|
} ?: null.apply {
|
||||||
reply(it) {
|
reply(contentMessage) {
|
||||||
regular("I am support only content with text contains url only")
|
regular("I am support only content with text contains url only")
|
||||||
}
|
}
|
||||||
} ?: return@onContentMessage
|
} ?: return@onContentMessage
|
||||||
it.withContentOrNull<TextedContent>() ?.let {
|
contentMessage.withContentOrNull<TextedContent>() ?.let {
|
||||||
send(
|
send(
|
||||||
it.chat,
|
it.chat,
|
||||||
it.content.textSources,
|
it.content.textSources,
|
||||||
|
@ -8,7 +8,6 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onComman
|
|||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.sameMessage
|
import dev.inmo.tgbotapi.extensions.utils.extensions.sameMessage
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.dataButton
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.dataButton
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatInlineKeyboard
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatInlineKeyboard
|
||||||
import dev.inmo.tgbotapi.types.location.LiveLocation
|
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.LocationContent
|
import dev.inmo.tgbotapi.types.message.content.LocationContent
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
@ -47,7 +46,7 @@ suspend fun main(vararg args: String) {
|
|||||||
handleLiveLocation(
|
handleLiveLocation(
|
||||||
it.chat.id,
|
it.chat.id,
|
||||||
locationsFlow,
|
locationsFlow,
|
||||||
sentMessageFlow = FlowCollector { currentMessageState.emit(it) },
|
sentMessageFlow = { currentMessageState.emit(it) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,46 +1,41 @@
|
|||||||
import com.benasher44.uuid.uuid4
|
|
||||||
import dev.inmo.kslog.common.KSLog
|
import dev.inmo.kslog.common.KSLog
|
||||||
import dev.inmo.kslog.common.LogLevel
|
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.bot.getMe
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.polls.sendQuizPoll
|
import dev.inmo.tgbotapi.extensions.api.send.polls.sendQuizPoll
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.polls.sendRegularPoll
|
import dev.inmo.tgbotapi.extensions.api.send.polls.sendRegularPoll
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.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.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onPollAnswer
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onPollUpdates
|
||||||
import dev.inmo.tgbotapi.extensions.utils.customEmojiTextSourceOrNull
|
import dev.inmo.tgbotapi.extensions.utils.customEmojiTextSourceOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithArgsSources
|
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithArgsSources
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sender_chat
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2
|
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2
|
import dev.inmo.tgbotapi.types.PollId
|
||||||
import dev.inmo.tgbotapi.extensions.utils.ifChannelChat
|
import dev.inmo.tgbotapi.types.ReplyParameters
|
||||||
import dev.inmo.tgbotapi.extensions.utils.ifFromChannelGroupContentMessage
|
import dev.inmo.tgbotapi.types.polls.InputPollOption
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.polls.PollAnswer
|
||||||
import dev.inmo.tgbotapi.types.chat.*
|
import dev.inmo.tgbotapi.utils.buildEntities
|
||||||
import dev.inmo.tgbotapi.types.chat.GroupChat
|
import dev.inmo.tgbotapi.utils.customEmoji
|
||||||
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
import dev.inmo.tgbotapi.utils.regular
|
||||||
import dev.inmo.tgbotapi.types.chat.SupergroupChat
|
import dev.inmo.tgbotapi.utils.underline
|
||||||
import dev.inmo.tgbotapi.types.message.MarkdownV2
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import dev.inmo.tgbotapi.types.polls.*
|
import kotlinx.coroutines.Dispatchers
|
||||||
import dev.inmo.tgbotapi.utils.*
|
|
||||||
import dev.inmo.tgbotapi.utils.extensions.escapeMarkdownV2Common
|
|
||||||
import kotlinx.coroutines.*
|
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This bot will answer with anonymous or public poll and send message on
|
* This bot will answer with anonymous or public poll and send message on
|
||||||
* updates of any of it.
|
* any update.
|
||||||
*
|
*
|
||||||
* * Use `/anonymous` to take anonymous regular poll
|
* * Use `/anonymous` to take anonymous regular poll
|
||||||
* * Use `/public` to take public regular poll
|
* * Use `/public` to take public regular poll
|
||||||
*/
|
*/
|
||||||
@OptIn(PreviewFeature::class)
|
|
||||||
suspend fun main(vararg args: String) {
|
suspend fun main(vararg args: String) {
|
||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
val isDebug = args.any { it == "debug" }
|
val isDebug = args.any { it == "debug" }
|
||||||
@ -54,8 +49,6 @@ suspend fun main(vararg args: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
val me = getMe()
|
|
||||||
|
|
||||||
val pollToChat = mutableMapOf<PollId, IdChatIdentifier>()
|
val pollToChat = mutableMapOf<PollId, IdChatIdentifier>()
|
||||||
val pollToChatMutex = Mutex()
|
val pollToChatMutex = Mutex()
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
|||||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.setMessageReaction
|
import dev.inmo.tgbotapi.extensions.api.send.setMessageReaction
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.setMessageReactions
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMessageReactionUpdatedByUser
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMessageReactionUpdatedByUser
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMessageReactionsCountUpdated
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMessageReactionsCountUpdated
|
||||||
|
@ -1,21 +1,19 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
import dev.inmo.tgbotapi.extensions.api.send.withTypingAction
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.media.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CommonMessageFilterExcludeMediaGroups
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage
|
||||||
import dev.inmo.tgbotapi.extensions.utils.possiblyWithEffectMessageOrNull
|
import dev.inmo.tgbotapi.extensions.utils.possiblyWithEffectMessageOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.shortcuts.*
|
import dev.inmo.tgbotapi.extensions.utils.shortcuts.executeUnsafe
|
||||||
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
|
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
|
||||||
import dev.inmo.tgbotapi.types.ReplyParameters
|
import dev.inmo.tgbotapi.types.ReplyParameters
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.BusinessContentMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.BusinessContentMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
import dev.inmo.tgbotapi.types.quoteEntitiesField
|
|
||||||
import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull
|
import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
import kotlinx.coroutines.currentCoroutineContext
|
||||||
|
|
||||||
suspend fun activateResenderBot(
|
suspend fun activateResenderBot(
|
||||||
token: String,
|
token: String,
|
||||||
|
@ -16,7 +16,9 @@ import dev.inmo.tgbotapi.extensions.api.send.reply
|
|||||||
import dev.inmo.tgbotapi.extensions.api.send.send
|
import dev.inmo.tgbotapi.extensions.api.send.send
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithFSMAndStartLongPolling
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithFSMAndStartLongPolling
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitChatSharedEventsMessages
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitCommandMessage
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitUserSharedEventsMessages
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMessageDataCallbackQuery
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMessageDataCallbackQuery
|
||||||
import dev.inmo.tgbotapi.extensions.utils.*
|
import dev.inmo.tgbotapi.extensions.utils.*
|
||||||
@ -27,12 +29,12 @@ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
|||||||
import dev.inmo.tgbotapi.types.chat.ChannelChat
|
import dev.inmo.tgbotapi.types.chat.ChannelChat
|
||||||
import dev.inmo.tgbotapi.types.chat.ChatPermissions
|
import dev.inmo.tgbotapi.types.chat.ChatPermissions
|
||||||
import dev.inmo.tgbotapi.types.chat.PublicChat
|
import dev.inmo.tgbotapi.types.chat.PublicChat
|
||||||
import dev.inmo.tgbotapi.types.chat.member.*
|
import dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember
|
||||||
|
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
||||||
import dev.inmo.tgbotapi.types.commands.BotCommandScope
|
import dev.inmo.tgbotapi.types.commands.BotCommandScope
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
|
||||||
import dev.inmo.tgbotapi.types.request.RequestId
|
import dev.inmo.tgbotapi.types.request.RequestId
|
||||||
import dev.inmo.tgbotapi.utils.*
|
import dev.inmo.tgbotapi.utils.*
|
||||||
import dev.inmo.tgbotapi.utils.mention
|
|
||||||
import kotlinx.coroutines.flow.filter
|
import kotlinx.coroutines.flow.filter
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.mapNotNull
|
import kotlinx.coroutines.flow.mapNotNull
|
||||||
@ -52,6 +54,7 @@ sealed interface UserRetrievingStep : State {
|
|||||||
) : UserRetrievingStep
|
) : UserRetrievingStep
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(PreviewFeature::class)
|
||||||
suspend fun main(args: Array<String>) {
|
suspend fun main(args: Array<String>) {
|
||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
|
|
||||||
@ -194,7 +197,7 @@ suspend fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bot.buildBehaviourWithFSMAndStartLongPolling<UserRetrievingStep>(
|
bot.buildBehaviourWithFSMAndStartLongPolling(
|
||||||
defaultExceptionsHandler = {
|
defaultExceptionsHandler = {
|
||||||
it.printStackTrace()
|
it.printStackTrace()
|
||||||
},
|
},
|
||||||
@ -224,7 +227,6 @@ suspend fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
val replyMessage = it.replyTo
|
val replyMessage = it.replyTo
|
||||||
val usernameInText = it.content.textSources.firstNotNullOfOrNull { it.mentionTextSourceOrNull() } ?.username
|
|
||||||
val userInReply = replyMessage?.fromUserMessageOrNull()?.user?.id ?: return@onCommand
|
val userInReply = replyMessage?.fromUserMessageOrNull()?.user?.id ?: return@onCommand
|
||||||
|
|
||||||
if (replyMessage is AccessibleMessage) {
|
if (replyMessage is AccessibleMessage) {
|
||||||
@ -381,7 +383,6 @@ suspend fun main(args: Array<String>) {
|
|||||||
val userId = ChatId(RawChatId(userIdString.toLong()))
|
val userId = ChatId(RawChatId(userIdString.toLong()))
|
||||||
val chatMember = getChatMember(channelId, userId)
|
val chatMember = getChatMember(channelId, userId)
|
||||||
val asAdmin = chatMember.administratorChatMemberOrNull()
|
val asAdmin = chatMember.administratorChatMemberOrNull()
|
||||||
val asMember = chatMember.memberChatMemberOrNull()
|
|
||||||
|
|
||||||
val realData = it.data.takeWhile { it != ' ' }
|
val realData = it.data.takeWhile { it != ' ' }
|
||||||
|
|
||||||
@ -503,10 +504,7 @@ suspend fun main(args: Array<String>) {
|
|||||||
|
|
||||||
strictlyOn<UserRetrievingStep.RetrievingChatInfoDoneState> { state ->
|
strictlyOn<UserRetrievingStep.RetrievingChatInfoDoneState> { state ->
|
||||||
val chatMember = getChatMember(state.channelId, state.userId).administratorChatMemberOrNull()
|
val chatMember = getChatMember(state.channelId, state.userId).administratorChatMemberOrNull()
|
||||||
if (chatMember == null) {
|
?: return@strictlyOn null
|
||||||
|
|
||||||
return@strictlyOn null
|
|
||||||
}
|
|
||||||
send(
|
send(
|
||||||
state.context,
|
state.context,
|
||||||
replyMarkup = buildAdminRightsKeyboard(
|
replyMarkup = buildAdminRightsKeyboard(
|
||||||
|
@ -3,9 +3,7 @@ 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.answers.answer
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.answers.payments.answerPreCheckoutQueryOk
|
import dev.inmo.tgbotapi.extensions.api.answers.payments.answerPreCheckoutQueryOk
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.edit.edit
|
import dev.inmo.tgbotapi.extensions.api.edit.edit
|
||||||
import dev.inmo.tgbotapi.extensions.api.files.downloadFile
|
import dev.inmo.tgbotapi.extensions.api.files.downloadFile
|
||||||
import dev.inmo.tgbotapi.extensions.api.files.downloadFileToTemp
|
import dev.inmo.tgbotapi.extensions.api.files.downloadFileToTemp
|
||||||
@ -30,18 +28,18 @@ import dev.inmo.tgbotapi.types.media.TelegramPaidMediaVideo
|
|||||||
import dev.inmo.tgbotapi.types.media.toTelegramPaidMediaPhoto
|
import dev.inmo.tgbotapi.types.media.toTelegramPaidMediaPhoto
|
||||||
import dev.inmo.tgbotapi.types.media.toTelegramPaidMediaVideo
|
import dev.inmo.tgbotapi.types.media.toTelegramPaidMediaVideo
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
import dev.inmo.tgbotapi.types.message.textsources.TextSource
|
|
||||||
import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList
|
import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList
|
||||||
import dev.inmo.tgbotapi.types.message.textsources.textSourcesOrElse
|
import dev.inmo.tgbotapi.types.message.textsources.textSourcesOrElse
|
||||||
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
||||||
import dev.inmo.tgbotapi.types.payments.stars.StarTransaction
|
import dev.inmo.tgbotapi.types.payments.stars.StarTransaction
|
||||||
import dev.inmo.tgbotapi.utils.*
|
import dev.inmo.tgbotapi.utils.bold
|
||||||
import kotlinx.coroutines.*
|
import dev.inmo.tgbotapi.utils.buildEntities
|
||||||
|
import dev.inmo.tgbotapi.utils.regular
|
||||||
|
import dev.inmo.tgbotapi.utils.row
|
||||||
|
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
|
|
||||||
*/
|
|
||||||
@OptIn(PreviewFeature::class)
|
|
||||||
suspend fun main(vararg args: String) {
|
suspend fun main(vararg args: String) {
|
||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
val adminUserId = args.getOrNull(1) ?.toLongOrNull() ?.let(::RawChatId) ?.let(::UserId) ?: error("Pass user-admin for full access to the bot")
|
val adminUserId = args.getOrNull(1) ?.toLongOrNull() ?.let(::RawChatId) ?.let(::UserId) ?: error("Pass user-admin for full access to the bot")
|
||||||
@ -58,8 +56,6 @@ suspend fun main(vararg args: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO), testServer = isTestServer) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO), testServer = isTestServer) {
|
||||||
val me = getMe()
|
|
||||||
|
|
||||||
val payload = "sample payload"
|
val payload = "sample payload"
|
||||||
command("start") {
|
command("start") {
|
||||||
reply(
|
reply(
|
||||||
|
@ -1,22 +1,25 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.defaultSafelyWithoutExceptionHandler
|
import dev.inmo.micro_utils.coroutines.defaultSafelyWithoutExceptionHandler
|
||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
|
||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.api.get.*
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
import dev.inmo.tgbotapi.extensions.api.get.getCustomEmojiStickerOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
import dev.inmo.tgbotapi.extensions.api.get.getStickerSet
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
import dev.inmo.tgbotapi.extensions.api.get.getStickerSetOrNull
|
||||||
import dev.inmo.tgbotapi.types.StickerFormat
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.withTypingAction
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onSticker
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onText
|
||||||
import dev.inmo.tgbotapi.types.StickerType
|
import dev.inmo.tgbotapi.types.StickerType
|
||||||
import dev.inmo.tgbotapi.types.message.textsources.*
|
import dev.inmo.tgbotapi.types.message.textsources.CustomEmojiTextSource
|
||||||
import dev.inmo.tgbotapi.types.stickers.CustomEmojiStickerSet
|
import dev.inmo.tgbotapi.types.message.textsources.regular
|
||||||
import dev.inmo.tgbotapi.types.stickers.MaskStickerSet
|
import dev.inmo.tgbotapi.types.message.textsources.separateForText
|
||||||
import dev.inmo.tgbotapi.types.stickers.RegularStickerSet
|
|
||||||
import dev.inmo.tgbotapi.types.stickers.StickerSet
|
import dev.inmo.tgbotapi.types.stickers.StickerSet
|
||||||
import dev.inmo.tgbotapi.types.stickers.UnknownStickerSet
|
|
||||||
import dev.inmo.tgbotapi.utils.bold
|
import dev.inmo.tgbotapi.utils.bold
|
||||||
import dev.inmo.tgbotapi.utils.buildEntities
|
import dev.inmo.tgbotapi.utils.buildEntities
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
import kotlinx.coroutines.currentCoroutineContext
|
||||||
|
|
||||||
fun StickerSet?.buildInfo() = buildEntities {
|
fun StickerSet?.buildInfo() = buildEntities {
|
||||||
if (this@buildInfo == null) {
|
if (this@buildInfo == null) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
import dev.inmo.tgbotapi.extensions.api.files.downloadFile
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.files.downloadFileToTemp
|
import dev.inmo.tgbotapi.extensions.api.files.downloadFileToTemp
|
||||||
import dev.inmo.tgbotapi.extensions.api.get.getStickerSet
|
import dev.inmo.tgbotapi.extensions.api.get.getStickerSet
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
@ -11,12 +10,14 @@ import dev.inmo.tgbotapi.extensions.api.stickers.deleteStickerSet
|
|||||||
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.onCommand
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onSticker
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onSticker
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sticker
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
||||||
import dev.inmo.tgbotapi.requests.stickers.InputSticker
|
import dev.inmo.tgbotapi.requests.stickers.InputSticker
|
||||||
import dev.inmo.tgbotapi.types.StickerSetName
|
import dev.inmo.tgbotapi.types.StickerSetName
|
||||||
import dev.inmo.tgbotapi.types.chat.Chat
|
import dev.inmo.tgbotapi.types.chat.Chat
|
||||||
import dev.inmo.tgbotapi.types.files.*
|
import dev.inmo.tgbotapi.types.files.CustomEmojiSticker
|
||||||
|
import dev.inmo.tgbotapi.types.files.MaskSticker
|
||||||
|
import dev.inmo.tgbotapi.types.files.RegularSticker
|
||||||
|
import dev.inmo.tgbotapi.types.files.UnknownSticker
|
||||||
import dev.inmo.tgbotapi.types.toChatId
|
import dev.inmo.tgbotapi.types.toChatId
|
||||||
import dev.inmo.tgbotapi.utils.botCommand
|
import dev.inmo.tgbotapi.utils.botCommand
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
@ -1,18 +1,8 @@
|
|||||||
import com.benasher44.uuid.uuid4
|
import com.benasher44.uuid.uuid4
|
||||||
import dev.inmo.micro_utils.common.repeatOnFailure
|
|
||||||
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.closeForumTopic
|
import dev.inmo.tgbotapi.extensions.api.chat.forum.*
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.closeGeneralForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.createForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.deleteForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.editForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.editGeneralForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.hideGeneralForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.reopenForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.reopenGeneralForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.unhideGeneralForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
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.onCommand
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
|
@ -6,11 +6,10 @@ import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
|||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatShared
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatShared
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUserShared
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUsersShared
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUsersShared
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
||||||
import dev.inmo.tgbotapi.types.BotCommand
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
|
@ -26,6 +26,7 @@ fun HTMLElement.log(text: String) {
|
|||||||
appendElement("p", {})
|
appendElement("p", {})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalUnsignedTypes::class)
|
||||||
fun main() {
|
fun main() {
|
||||||
console.log("Web app started")
|
console.log("Web app started")
|
||||||
val client = HttpClient()
|
val client = HttpClient()
|
||||||
@ -38,7 +39,7 @@ fun main() {
|
|||||||
scope.launchSafelyWithoutExceptions {
|
scope.launchSafelyWithoutExceptions {
|
||||||
val response = client.post("$baseUrl/check") {
|
val response = client.post("$baseUrl/check") {
|
||||||
setBody(
|
setBody(
|
||||||
Json { }.encodeToString(
|
Json.encodeToString(
|
||||||
WebAppDataWrapper.serializer(),
|
WebAppDataWrapper.serializer(),
|
||||||
WebAppDataWrapper(webApp.initData, webApp.initDataUnsafe.hash)
|
WebAppDataWrapper(webApp.initData, webApp.initDataUnsafe.hash)
|
||||||
)
|
)
|
||||||
|
@ -1,16 +1,20 @@
|
|||||||
import dev.inmo.kslog.common.*
|
import dev.inmo.kslog.common.*
|
||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.micro_utils.ktor.server.createKtorServer
|
import dev.inmo.micro_utils.ktor.server.createKtorServer
|
||||||
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.answers.answerInlineQuery
|
import dev.inmo.tgbotapi.extensions.api.answers.answerInlineQuery
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.send
|
||||||
import dev.inmo.tgbotapi.extensions.api.telegramBot
|
import dev.inmo.tgbotapi.extensions.api.telegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onBaseInlineQuery
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.makeTelegramStartattach
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUnhandledCommand
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onWriteAccessAllowed
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.webAppButton
|
||||||
import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton
|
import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton
|
||||||
import dev.inmo.tgbotapi.types.BotCommand
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
||||||
@ -21,16 +25,14 @@ import dev.inmo.tgbotapi.types.webAppQueryIdField
|
|||||||
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
||||||
import dev.inmo.tgbotapi.utils.*
|
import dev.inmo.tgbotapi.utils.*
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import io.ktor.server.application.call
|
import io.ktor.server.application.*
|
||||||
import io.ktor.server.http.content.*
|
import io.ktor.server.http.content.*
|
||||||
import io.ktor.server.request.receiveText
|
import io.ktor.server.request.*
|
||||||
import io.ktor.server.response.respond
|
import io.ktor.server.response.*
|
||||||
import io.ktor.server.routing.post
|
import io.ktor.server.routing.*
|
||||||
import io.ktor.server.routing.routing
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.charset.Charset
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accepts two parameters:
|
* Accepts two parameters:
|
||||||
@ -100,7 +102,7 @@ suspend fun main(vararg args: String) {
|
|||||||
}
|
}
|
||||||
post("check") {
|
post("check") {
|
||||||
val requestBody = call.receiveText()
|
val requestBody = call.receiveText()
|
||||||
val webAppCheckData = Json { }.decodeFromString(WebAppDataWrapper.serializer(), requestBody)
|
val webAppCheckData = Json.decodeFromString(WebAppDataWrapper.serializer(), requestBody)
|
||||||
|
|
||||||
val isSafe = telegramBotAPIUrlsKeeper.checkWebAppData(webAppCheckData.data, webAppCheckData.hash)
|
val isSafe = telegramBotAPIUrlsKeeper.checkWebAppData(webAppCheckData.data, webAppCheckData.hash)
|
||||||
|
|
||||||
@ -112,7 +114,6 @@ suspend fun main(vararg args: String) {
|
|||||||
bot.buildBehaviourWithLongPolling(
|
bot.buildBehaviourWithLongPolling(
|
||||||
defaultExceptionsHandler = { it.printStackTrace() }
|
defaultExceptionsHandler = { it.printStackTrace() }
|
||||||
) {
|
) {
|
||||||
val me = getMe()
|
|
||||||
onCommand("reply_markup") {
|
onCommand("reply_markup") {
|
||||||
reply(
|
reply(
|
||||||
it,
|
it,
|
||||||
|
Loading…
Reference in New Issue
Block a user