From 7964dc4eea92f7ad6b1f07d480eb9259c1466bcb Mon Sep 17 00:00:00 2001 From: bpavuk Date: Wed, 10 Jul 2024 19:23:36 +0300 Subject: [PATCH] code cleanup optimized imports here and there, made CustomBot working as intended --- BoostsInfoBot/src/main/kotlin/BoostsInfo.kt | 6 +-- .../src/main/kotlin/BusinessConnectionsBot.kt | 20 ++++----- .../src/main/kotlin/ChatAvatarSetter.kt | 4 +- CustomBot/src/main/kotlin/CustomBot.kt | 22 +++++++--- DeepLinksBot/src/main/kotlin/DeepLinksBot.kt | 6 +-- FSMBot/src/main/kotlin/SimpleFSMBot.kt | 15 +++---- .../src/main/kotlin/FilesLoaderBot.kt | 25 +---------- GetMeBot/src/main/kotlin/GetMeBot.kt | 4 +- HelloBot/src/main/kotlin/HelloBot.kt | 15 ++----- .../src/jvmMain/kotlin/InlineQueriesBot.kt | 2 - .../src/commonMain/kotlin/KeyboardsBot.kt | 21 +++++----- .../src/main/kotlin/LinkPreviewsBot.kt | 19 +++------ .../src/main/kotlin/LiveLocationsBot.kt | 3 +- PollsBot/src/main/kotlin/PollsBot.kt | 41 ++++++++----------- .../src/commonMain/kotlin/PickFile.kt | 0 .../src/main/kotlin/ReactionsInfoBot.kt | 1 - .../src/commonMain/kotlin/ResenderBot.kt | 16 ++++---- .../src/main/kotlin/RightsChanger.kt | 18 ++++---- .../src/main/kotlin/StarTransactionsBot.kt | 18 ++++---- .../src/commonMain/kotlin/StickerInfoBot.kt | 27 ++++++------ .../src/main/kotlin/StickerSetHandlerBot.kt | 7 ++-- .../src/main/kotlin/TopicsHandling.kt | 12 +----- .../src/main/kotlin/UserChatShared.kt | 3 +- WebApp/src/jsMain/kotlin/main.kt | 3 +- WebApp/src/jvmMain/kotlin/WebAppServer.kt | 29 ++++++------- 25 files changed, 141 insertions(+), 196 deletions(-) delete mode 100644 RandomFileSenderBot/src/commonMain/kotlin/PickFile.kt diff --git a/BoostsInfoBot/src/main/kotlin/BoostsInfo.kt b/BoostsInfoBot/src/main/kotlin/BoostsInfo.kt index fd7f058..520603e 100644 --- a/BoostsInfoBot/src/main/kotlin/BoostsInfo.kt +++ b/BoostsInfoBot/src/main/kotlin/BoostsInfo.kt @@ -4,13 +4,13 @@ import dev.inmo.kslog.common.defaultMessageFormatter import dev.inmo.kslog.common.setDefaultKSLog import dev.inmo.tgbotapi.bot.ktor.telegramBot 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.triggers_handling.onChatBoostUpdated 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.utils.types.buttons.* -import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights +import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatReplyKeyboard +import dev.inmo.tgbotapi.extensions.utils.types.buttons.requestChannelButton import dev.inmo.tgbotapi.types.request.RequestId import dev.inmo.tgbotapi.utils.regular import korlibs.time.DateFormat diff --git a/BusinessConnectionsBot/src/main/kotlin/BusinessConnectionsBot.kt b/BusinessConnectionsBot/src/main/kotlin/BusinessConnectionsBot.kt index 49f79a1..bc16ee1 100644 --- a/BusinessConnectionsBot/src/main/kotlin/BusinessConnectionsBot.kt +++ b/BusinessConnectionsBot/src/main/kotlin/BusinessConnectionsBot.kt @@ -49,22 +49,22 @@ suspend fun main(args: Array) { } onContentMessage { - it.ifBusinessContentMessage { - val sent = execute(it.content.createResend(it.from.id)) - if (it.sentByBusinessConnectionOwner) { - reply(sent, "You have sent this message to the ${it.businessConnectionId.string} related chat") + it.ifBusinessContentMessage { businessContentMessage -> + val sent = execute(it.content.createResend(businessContentMessage.from.id)) + if (businessContentMessage.sentByBusinessConnectionOwner) { + reply(sent, "You have sent this message to the ${businessContentMessage.businessConnectionId.string} related chat") } 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 { - it.ifBusinessContentMessage { - val sent = execute(it.content.createResend(it.from.id)) - if (it.sentByBusinessConnectionOwner) { - reply(sent, "You have edited this message in the ${it.businessConnectionId.string} related chat") + it.ifBusinessContentMessage { businessContentMessage -> + val sent = execute(businessContentMessage.content.createResend(businessContentMessage.from.id)) + if (businessContentMessage.sentByBusinessConnectionOwner) { + reply(sent, "You have edited this message in the ${businessContentMessage.businessConnectionId.string} related chat") } 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") } } } diff --git a/ChatAvatarSetter/src/main/kotlin/ChatAvatarSetter.kt b/ChatAvatarSetter/src/main/kotlin/ChatAvatarSetter.kt index 8fcf9dd..0c0a4f6 100644 --- a/ChatAvatarSetter/src/main/kotlin/ChatAvatarSetter.kt +++ b/ChatAvatarSetter/src/main/kotlin/ChatAvatarSetter.kt @@ -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.behaviour_builder.buildBehaviourWithLongPolling import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onPhoto -import dev.inmo.tgbotapi.extensions.utils.* import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile -import kotlinx.coroutines.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers suspend fun main(args: Array) { val bot = telegramBot(args.first()) diff --git a/CustomBot/src/main/kotlin/CustomBot.kt b/CustomBot/src/main/kotlin/CustomBot.kt index 45d3861..3cbafad 100644 --- a/CustomBot/src/main/kotlin/CustomBot.kt +++ b/CustomBot/src/main/kotlin/CustomBot.kt @@ -3,13 +3,17 @@ import dev.inmo.kslog.common.LogLevel import dev.inmo.kslog.common.defaultMessageFormatter import dev.inmo.kslog.common.setDefaultKSLog 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.utils.asMessageUpdate +import dev.inmo.tgbotapi.extensions.utils.extensions.raw.from 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) suspend fun main(vararg args: String) { @@ -26,8 +30,14 @@ suspend fun main(vararg args: String) { } telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) { - val me = getMe() - - allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { println(it) } + allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { update -> + update.asMessageUpdate()?.let { safeMessageUpdate -> + 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() } diff --git a/DeepLinksBot/src/main/kotlin/DeepLinksBot.kt b/DeepLinksBot/src/main/kotlin/DeepLinksBot.kt index 7b4f514..c7f1a63 100644 --- a/DeepLinksBot/src/main/kotlin/DeepLinksBot.kt +++ b/DeepLinksBot/src/main/kotlin/DeepLinksBot.kt @@ -1,11 +1,11 @@ -import dev.inmo.micro_utils.coroutines.subscribeSafelySkippingExceptions 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.send.reply import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitDeepLinks 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.types.message.textsources.BotCommandTextSource diff --git a/FSMBot/src/main/kotlin/SimpleFSMBot.kt b/FSMBot/src/main/kotlin/SimpleFSMBot.kt index 030299a..53751f8 100644 --- a/FSMBot/src/main/kotlin/SimpleFSMBot.kt +++ b/FSMBot/src/main/kotlin/SimpleFSMBot.kt @@ -1,23 +1,20 @@ -import dev.inmo.micro_utils.coroutines.AccumulatorFlow import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.micro_utils.fsm.common.State import dev.inmo.tgbotapi.extensions.api.send.send -import dev.inmo.tgbotapi.extensions.api.send.sendMessage -import dev.inmo.tgbotapi.extensions.behaviour_builder.* -import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.* -import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.* +import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitAnyContentMessage +import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndFSMAndStartLongPolling +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.command +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.sameThread -import dev.inmo.tgbotapi.extensions.utils.formatting.* import dev.inmo.tgbotapi.extensions.utils.textContentOrNull import dev.inmo.tgbotapi.extensions.utils.withContentOrNull 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.content.TextContent import dev.inmo.tgbotapi.utils.botCommand -import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull -import kotlinx.coroutines.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.first diff --git a/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt b/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt index f477391..8744ada 100644 --- a/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt +++ b/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt @@ -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.downloadFileToTemp import dev.inmo.tgbotapi.extensions.api.get.getFileAdditionalInfo -import dev.inmo.tgbotapi.extensions.api.send.reply -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.api.send.* 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.onContentMessage import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMedia 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.media.TelegramMediaAudio import dev.inmo.tgbotapi.types.media.TelegramMediaDocument import dev.inmo.tgbotapi.types.media.TelegramMediaPhoto import dev.inmo.tgbotapi.types.media.TelegramMediaVideo -import dev.inmo.tgbotapi.types.message.content.AnimationContent -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.types.message.content.* import dev.inmo.tgbotapi.utils.filenameFromUrl import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers diff --git a/GetMeBot/src/main/kotlin/GetMeBot.kt b/GetMeBot/src/main/kotlin/GetMeBot.kt index 460b48c..eec6881 100644 --- a/GetMeBot/src/main/kotlin/GetMeBot.kt +++ b/GetMeBot/src/main/kotlin/GetMeBot.kt @@ -1,15 +1,13 @@ import dev.inmo.kslog.common.KSLog import dev.inmo.kslog.common.LogLevel import dev.inmo.kslog.common.defaultMessageFormatter -import dev.inmo.kslog.common.filter.filtered import dev.inmo.kslog.common.setDefaultKSLog import dev.inmo.tgbotapi.bot.ktor.telegramBot import dev.inmo.tgbotapi.extensions.api.bot.getMe 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) { val botToken = args.first() diff --git a/HelloBot/src/main/kotlin/HelloBot.kt b/HelloBot/src/main/kotlin/HelloBot.kt index fb95839..48ccd69 100644 --- a/HelloBot/src/main/kotlin/HelloBot.kt +++ b/HelloBot/src/main/kotlin/HelloBot.kt @@ -1,23 +1,18 @@ 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.api.send.reply 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 -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.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.utils.PreviewFeature 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 @@ -29,8 +24,6 @@ suspend fun main(vararg args: String) { telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) { val me = getMe() onMentionWithAnyContent(me) { message -> - val chat = message.chat - val answerText = when (val chat = message.chat) { is PreviewChannelChat -> { val answer = "Hi everybody in this channel \"${chat.title}\"" @@ -42,7 +35,7 @@ suspend fun main(vararg args: String) { return@onMentionWithAnyContent } is PreviewGroupChat -> { - message.ifFromChannelGroupContentMessage { + message.ifFromChannelGroupContentMessage { val answer = "Hi, ${it.senderChat.title}" reply(message, answer, MarkdownV2) return@onMentionWithAnyContent diff --git a/InlineQueriesBot/src/jvmMain/kotlin/InlineQueriesBot.kt b/InlineQueriesBot/src/jvmMain/kotlin/InlineQueriesBot.kt index 2d20c79..82382b8 100644 --- a/InlineQueriesBot/src/jvmMain/kotlin/InlineQueriesBot.kt +++ b/InlineQueriesBot/src/jvmMain/kotlin/InlineQueriesBot.kt @@ -1,5 +1,3 @@ -import dev.inmo.micro_utils.common.MPPFile - suspend fun main(args: Array) { doInlineQueriesBot(args.first()) } diff --git a/KeyboardsBot/KeyboardsBotLib/src/commonMain/kotlin/KeyboardsBot.kt b/KeyboardsBot/KeyboardsBotLib/src/commonMain/kotlin/KeyboardsBot.kt index 3b8155b..1873050 100644 --- a/KeyboardsBot/KeyboardsBotLib/src/commonMain/kotlin/KeyboardsBot.kt +++ b/KeyboardsBot/KeyboardsBotLib/src/commonMain/kotlin/KeyboardsBot.kt @@ -1,14 +1,12 @@ 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.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.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.send.* -import dev.inmo.tgbotapi.extensions.behaviour_builder.* +import dev.inmo.tgbotapi.extensions.api.send.reply +import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.* import dev.inmo.tgbotapi.extensions.utils.types.buttons.* 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.InlineQueryId import dev.inmo.tgbotapi.types.message.content.TextContent -import dev.inmo.tgbotapi.utils.* -import kotlinx.coroutines.* - -private const val nextPageData = "next" -private const val previousPageData = "previous" +import dev.inmo.tgbotapi.utils.PreviewFeature +import dev.inmo.tgbotapi.utils.botCommand +import dev.inmo.tgbotapi.utils.regular +import dev.inmo.tgbotapi.utils.row +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.currentCoroutineContext fun String.parsePageAndCount(): Pair? { 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( token: String, print: (Any) -> Unit diff --git a/LinkPreviewsBot/src/main/kotlin/LinkPreviewsBot.kt b/LinkPreviewsBot/src/main/kotlin/LinkPreviewsBot.kt index cc85073..49226c7 100644 --- a/LinkPreviewsBot/src/main/kotlin/LinkPreviewsBot.kt +++ b/LinkPreviewsBot/src/main/kotlin/LinkPreviewsBot.kt @@ -3,24 +3,15 @@ import dev.inmo.kslog.common.LogLevel import dev.inmo.kslog.common.defaultMessageFormatter import dev.inmo.kslog.common.setDefaultKSLog 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.send -import dev.inmo.tgbotapi.extensions.api.send.setMessageReaction 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.utils.textLinkTextSourceOrNull import dev.inmo.tgbotapi.extensions.utils.uRLTextSourceOrNull import dev.inmo.tgbotapi.extensions.utils.withContentOrNull 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.reactions.Reaction -import dev.inmo.tgbotapi.utils.customEmoji import dev.inmo.tgbotapi.utils.regular /** @@ -41,17 +32,17 @@ suspend fun main(vararg args: String) { val bot = telegramBot(botToken) bot.buildBehaviourWithLongPolling { - onContentMessage { - val url = it.withContentOrNull() ?.let { - it.content.textSources.firstNotNullOfOrNull { + onContentMessage { contentMessage -> + val url = contentMessage.withContentOrNull() ?.let { message -> + message.content.textSources.firstNotNullOfOrNull { it.textLinkTextSourceOrNull() ?.url ?: it.uRLTextSourceOrNull() ?.source } } ?: null.apply { - reply(it) { + reply(contentMessage) { regular("I am support only content with text contains url only") } } ?: return@onContentMessage - it.withContentOrNull() ?.let { + contentMessage.withContentOrNull() ?.let { send( it.chat, it.content.textSources, diff --git a/LiveLocationsBot/src/main/kotlin/LiveLocationsBot.kt b/LiveLocationsBot/src/main/kotlin/LiveLocationsBot.kt index 6815e79..8614366 100644 --- a/LiveLocationsBot/src/main/kotlin/LiveLocationsBot.kt +++ b/LiveLocationsBot/src/main/kotlin/LiveLocationsBot.kt @@ -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.types.buttons.dataButton 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.content.LocationContent import kotlinx.coroutines.* @@ -47,7 +46,7 @@ suspend fun main(vararg args: String) { handleLiveLocation( it.chat.id, locationsFlow, - sentMessageFlow = FlowCollector { currentMessageState.emit(it) }, + sentMessageFlow = { currentMessageState.emit(it) }, ) } diff --git a/PollsBot/src/main/kotlin/PollsBot.kt b/PollsBot/src/main/kotlin/PollsBot.kt index e7f885c..c15675c 100644 --- a/PollsBot/src/main/kotlin/PollsBot.kt +++ b/PollsBot/src/main/kotlin/PollsBot.kt @@ -1,46 +1,41 @@ -import com.benasher44.uuid.uuid4 import dev.inmo.kslog.common.KSLog import dev.inmo.kslog.common.LogLevel import dev.inmo.kslog.common.defaultMessageFormatter import dev.inmo.kslog.common.setDefaultKSLog 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.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.sendRegularPoll +import dev.inmo.tgbotapi.extensions.api.send.send 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.extensions.parseCommandsWithArgsSources -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 -import dev.inmo.tgbotapi.extensions.utils.ifChannelChat -import dev.inmo.tgbotapi.extensions.utils.ifFromChannelGroupContentMessage -import dev.inmo.tgbotapi.types.* -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.polls.* -import dev.inmo.tgbotapi.utils.* -import dev.inmo.tgbotapi.utils.extensions.escapeMarkdownV2Common -import kotlinx.coroutines.* +import dev.inmo.tgbotapi.types.BotCommand +import dev.inmo.tgbotapi.types.IdChatIdentifier +import dev.inmo.tgbotapi.types.PollId +import dev.inmo.tgbotapi.types.ReplyParameters +import dev.inmo.tgbotapi.types.polls.InputPollOption +import dev.inmo.tgbotapi.types.polls.PollAnswer +import dev.inmo.tgbotapi.utils.buildEntities +import dev.inmo.tgbotapi.utils.customEmoji +import dev.inmo.tgbotapi.utils.regular +import dev.inmo.tgbotapi.utils.underline +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlin.random.Random /** * 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 `/public` to take public regular poll */ -@OptIn(PreviewFeature::class) suspend fun main(vararg args: String) { val botToken = args.first() val isDebug = args.any { it == "debug" } @@ -54,8 +49,6 @@ suspend fun main(vararg args: String) { } telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) { - val me = getMe() - val pollToChat = mutableMapOf() val pollToChatMutex = Mutex() diff --git a/RandomFileSenderBot/src/commonMain/kotlin/PickFile.kt b/RandomFileSenderBot/src/commonMain/kotlin/PickFile.kt deleted file mode 100644 index e69de29..0000000 diff --git a/ReactionsInfoBot/src/main/kotlin/ReactionsInfoBot.kt b/ReactionsInfoBot/src/main/kotlin/ReactionsInfoBot.kt index 7bfe094..46ad255 100644 --- a/ReactionsInfoBot/src/main/kotlin/ReactionsInfoBot.kt +++ b/ReactionsInfoBot/src/main/kotlin/ReactionsInfoBot.kt @@ -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.send.reply 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.triggers_handling.onChatMessageReactionUpdatedByUser import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMessageReactionsCountUpdated diff --git a/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt b/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt index 215bc4b..69fb356 100644 --- a/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt +++ b/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt @@ -1,21 +1,19 @@ 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.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.api.send.withTypingAction 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.shortcuts.* +import dev.inmo.tgbotapi.extensions.utils.shortcuts.executeUnsafe import dev.inmo.tgbotapi.extensions.utils.withContentOrNull import dev.inmo.tgbotapi.types.ReplyParameters import dev.inmo.tgbotapi.types.message.abstracts.BusinessContentMessage import dev.inmo.tgbotapi.types.message.content.TextContent -import dev.inmo.tgbotapi.types.quoteEntitiesField 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( token: String, diff --git a/RightsChangerBot/src/main/kotlin/RightsChanger.kt b/RightsChangerBot/src/main/kotlin/RightsChanger.kt index dad7585..9381a29 100644 --- a/RightsChangerBot/src/main/kotlin/RightsChanger.kt +++ b/RightsChangerBot/src/main/kotlin/RightsChanger.kt @@ -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.behaviour_builder.BehaviourContext 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.onMessageDataCallbackQuery 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.ChatPermissions 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.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.request.RequestId import dev.inmo.tgbotapi.utils.* -import dev.inmo.tgbotapi.utils.mention import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.mapNotNull @@ -52,6 +54,7 @@ sealed interface UserRetrievingStep : State { ) : UserRetrievingStep } +@OptIn(PreviewFeature::class) suspend fun main(args: Array) { val botToken = args.first() @@ -194,7 +197,7 @@ suspend fun main(args: Array) { } } - bot.buildBehaviourWithFSMAndStartLongPolling( + bot.buildBehaviourWithFSMAndStartLongPolling( defaultExceptionsHandler = { it.printStackTrace() }, @@ -224,7 +227,6 @@ suspend fun main(args: Array) { } ) { val replyMessage = it.replyTo - val usernameInText = it.content.textSources.firstNotNullOfOrNull { it.mentionTextSourceOrNull() } ?.username val userInReply = replyMessage?.fromUserMessageOrNull()?.user?.id ?: return@onCommand if (replyMessage is AccessibleMessage) { @@ -381,7 +383,6 @@ suspend fun main(args: Array) { val userId = ChatId(RawChatId(userIdString.toLong())) val chatMember = getChatMember(channelId, userId) val asAdmin = chatMember.administratorChatMemberOrNull() - val asMember = chatMember.memberChatMemberOrNull() val realData = it.data.takeWhile { it != ' ' } @@ -503,10 +504,7 @@ suspend fun main(args: Array) { strictlyOn { state -> val chatMember = getChatMember(state.channelId, state.userId).administratorChatMemberOrNull() - if (chatMember == null) { - - return@strictlyOn null - } + ?: return@strictlyOn null send( state.context, replyMarkup = buildAdminRightsKeyboard( diff --git a/StarTransactionsBot/src/main/kotlin/StarTransactionsBot.kt b/StarTransactionsBot/src/main/kotlin/StarTransactionsBot.kt index 6d0de74..daf5b75 100644 --- a/StarTransactionsBot/src/main/kotlin/StarTransactionsBot.kt +++ b/StarTransactionsBot/src/main/kotlin/StarTransactionsBot.kt @@ -3,9 +3,7 @@ import dev.inmo.kslog.common.LogLevel import dev.inmo.kslog.common.defaultMessageFormatter import dev.inmo.kslog.common.setDefaultKSLog 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.bot.getMe import dev.inmo.tgbotapi.extensions.api.edit.edit import dev.inmo.tgbotapi.extensions.api.files.downloadFile 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.toTelegramPaidMediaVideo 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.textSourcesOrElse import dev.inmo.tgbotapi.types.payments.LabeledPrice import dev.inmo.tgbotapi.types.payments.stars.StarTransaction -import dev.inmo.tgbotapi.utils.* -import kotlinx.coroutines.* +import dev.inmo.tgbotapi.utils.bold +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) { val botToken = args.first() 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) { - val me = getMe() - val payload = "sample payload" command("start") { reply( diff --git a/StickerInfoBot/StickerInfoBotLib/src/commonMain/kotlin/StickerInfoBot.kt b/StickerInfoBot/StickerInfoBotLib/src/commonMain/kotlin/StickerInfoBot.kt index 9b1dc06..e0d541e 100644 --- a/StickerInfoBot/StickerInfoBotLib/src/commonMain/kotlin/StickerInfoBot.kt +++ b/StickerInfoBot/StickerInfoBotLib/src/commonMain/kotlin/StickerInfoBot.kt @@ -1,22 +1,25 @@ import dev.inmo.micro_utils.coroutines.defaultSafelyWithoutExceptionHandler 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.extensions.api.get.* -import dev.inmo.tgbotapi.extensions.api.send.* -import dev.inmo.tgbotapi.extensions.behaviour_builder.* -import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.* -import dev.inmo.tgbotapi.types.StickerFormat +import dev.inmo.tgbotapi.extensions.api.bot.getMe +import dev.inmo.tgbotapi.extensions.api.get.getCustomEmojiStickerOrNull +import dev.inmo.tgbotapi.extensions.api.get.getStickerSet +import dev.inmo.tgbotapi.extensions.api.get.getStickerSetOrNull +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.message.textsources.* -import dev.inmo.tgbotapi.types.stickers.CustomEmojiStickerSet -import dev.inmo.tgbotapi.types.stickers.MaskStickerSet -import dev.inmo.tgbotapi.types.stickers.RegularStickerSet +import dev.inmo.tgbotapi.types.message.textsources.CustomEmojiTextSource +import dev.inmo.tgbotapi.types.message.textsources.regular +import dev.inmo.tgbotapi.types.message.textsources.separateForText 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.buildEntities -import kotlinx.coroutines.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.currentCoroutineContext fun StickerSet?.buildInfo() = buildEntities { if (this@buildInfo == null) { diff --git a/StickerSetHandler/src/main/kotlin/StickerSetHandlerBot.kt b/StickerSetHandler/src/main/kotlin/StickerSetHandlerBot.kt index bb6312f..875a1a5 100644 --- a/StickerSetHandler/src/main/kotlin/StickerSetHandlerBot.kt +++ b/StickerSetHandler/src/main/kotlin/StickerSetHandlerBot.kt @@ -1,7 +1,6 @@ import dev.inmo.micro_utils.coroutines.runCatchingSafely import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions 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.get.getStickerSet 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.triggers_handling.onCommand 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.stickers.InputSticker import dev.inmo.tgbotapi.types.StickerSetName 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.utils.botCommand import kotlinx.coroutines.CoroutineScope diff --git a/TopicsHandling/src/main/kotlin/TopicsHandling.kt b/TopicsHandling/src/main/kotlin/TopicsHandling.kt index d13a2d2..5b04a82 100644 --- a/TopicsHandling/src/main/kotlin/TopicsHandling.kt +++ b/TopicsHandling/src/main/kotlin/TopicsHandling.kt @@ -1,18 +1,8 @@ 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.subscribeSafelyWithoutExceptions 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.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.chat.forum.* import dev.inmo.tgbotapi.extensions.api.send.reply import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand diff --git a/UserChatShared/src/main/kotlin/UserChatShared.kt b/UserChatShared/src/main/kotlin/UserChatShared.kt index 895d29a..1ed9554 100644 --- a/UserChatShared/src/main/kotlin/UserChatShared.kt +++ b/UserChatShared/src/main/kotlin/UserChatShared.kt @@ -6,11 +6,10 @@ import dev.inmo.micro_utils.coroutines.runCatchingSafely import dev.inmo.tgbotapi.bot.ktor.telegramBot 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.reply 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.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.utils.types.buttons.* import dev.inmo.tgbotapi.types.BotCommand diff --git a/WebApp/src/jsMain/kotlin/main.kt b/WebApp/src/jsMain/kotlin/main.kt index 2241dcc..17aed8e 100644 --- a/WebApp/src/jsMain/kotlin/main.kt +++ b/WebApp/src/jsMain/kotlin/main.kt @@ -26,6 +26,7 @@ fun HTMLElement.log(text: String) { appendElement("p", {}) } +@OptIn(ExperimentalUnsignedTypes::class) fun main() { console.log("Web app started") val client = HttpClient() @@ -38,7 +39,7 @@ fun main() { scope.launchSafelyWithoutExceptions { val response = client.post("$baseUrl/check") { setBody( - Json { }.encodeToString( + Json.encodeToString( WebAppDataWrapper.serializer(), WebAppDataWrapper(webApp.initData, webApp.initDataUnsafe.hash) ) diff --git a/WebApp/src/jvmMain/kotlin/WebAppServer.kt b/WebApp/src/jvmMain/kotlin/WebAppServer.kt index 9b73204..b50a3c9 100644 --- a/WebApp/src/jvmMain/kotlin/WebAppServer.kt +++ b/WebApp/src/jvmMain/kotlin/WebAppServer.kt @@ -1,16 +1,20 @@ import dev.inmo.kslog.common.* import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions 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.bot.getMe 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.behaviour_builder.* -import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.* -import dev.inmo.tgbotapi.extensions.utils.formatting.makeTelegramStartattach -import dev.inmo.tgbotapi.extensions.utils.types.buttons.* +import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onBaseInlineQuery +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand +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.types.BotCommand 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.utils.* 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.request.receiveText -import io.ktor.server.response.respond -import io.ktor.server.routing.post -import io.ktor.server.routing.routing +import io.ktor.server.request.* +import io.ktor.server.response.* +import io.ktor.server.routing.* import kotlinx.coroutines.Dispatchers import kotlinx.serialization.json.Json import java.io.File -import java.nio.charset.Charset /** * Accepts two parameters: @@ -100,7 +102,7 @@ suspend fun main(vararg args: String) { } post("check") { 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) @@ -112,7 +114,6 @@ suspend fun main(vararg args: String) { bot.buildBehaviourWithLongPolling( defaultExceptionsHandler = { it.printStackTrace() } ) { - val me = getMe() onCommand("reply_markup") { reply( it,