From 1cf7ae7438f79ea0999e59f896c6e5a63bcdc2b3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 7 Nov 2020 13:42:10 +0600 Subject: [PATCH] add micro_utils and deprecate old coroutine methods --- CHANGELOG.md | 2 ++ gradle.properties | 2 ++ tgbotapi.core/build.gradle | 2 ++ .../dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt | 2 +- .../dev/inmo/tgbotapi/CommonAbstracts/Explained.kt | 2 +- .../dev/inmo/tgbotapi/CommonAbstracts/Texted.kt | 2 +- .../inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt | 3 ++- .../Ktor/base/DownloadFileRequestCallFactory.kt | 4 ++-- .../types/MessageEntity/RawMessageEntity.kt | 4 ++-- .../MessageEntity/textsources/BoldTextSource.kt | 4 +++- .../textsources/BotCommandTextSource.kt | 4 +++- .../MessageEntity/textsources/CashTagTextSource.kt | 3 +++ .../MessageEntity/textsources/CodeTextSource.kt | 3 +++ .../MessageEntity/textsources/EMailTextSource.kt | 3 +++ .../MessageEntity/textsources/HashTagTextSource.kt | 3 +++ .../MessageEntity/textsources/ItalicTextSource.kt | 3 +++ .../MessageEntity/textsources/MentionTextSource.kt | 4 +++- .../textsources/PhoneNumberTextSource.kt | 3 +++ .../MessageEntity/textsources/PreTextSource.kt | 3 +++ .../MessageEntity/textsources/RegularTextSource.kt | 3 +++ .../textsources/StrikethroughTextSource.kt | 3 +++ .../textsources/TextLinkTextSource.kt | 3 +++ .../textsources/TextMentionTextSource.kt | 3 +++ .../MessageEntity/textsources/URLTextSource.kt | 3 +++ .../textsources/UnderlineTextSource.kt | 3 +++ .../dev/inmo/tgbotapi/types/message/RawMessage.kt | 1 - .../tgbotapi/types/message/content/TextContent.kt | 4 +++- .../message/content/media/AnimationContent.kt | 4 ++-- .../types/message/content/media/AudioContent.kt | 2 +- .../types/message/content/media/DocumentContent.kt | 2 +- .../types/message/content/media/PhotoContent.kt | 2 +- .../types/message/content/media/VideoContent.kt | 2 +- .../types/message/content/media/VoiceContent.kt | 4 ++-- .../kotlin/dev/inmo/tgbotapi/utils/HandleSafely.kt | 14 ++++++-------- .../BaseMessageUpdateToMediaGroupUpdate.kt | 2 +- .../{ => internal}/CaptionAndTextSourcesToText.kt | 2 +- .../MultilevelTextSourceFormatting.kt | 2 +- .../utils/{ => internal}/StringFormatting.kt | 2 +- .../types/MessageEntity/StringFormattingTests.kt | 2 +- .../types/MessageEntity/TextPartsCreatingTests.kt | 4 ++-- .../tgbotapi/extensions/utils/SafelyShortcut.kt | 6 ++++-- .../extensions/utils/shortcuts/RequestsExecutor.kt | 6 +++--- .../utils/updates/retrieving/LongPolling.kt | 6 ++++-- .../extensions/utils/updates/retrieving/Webhook.kt | 6 +++--- 44 files changed, 101 insertions(+), 46 deletions(-) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/{ => internal}/BaseMessageUpdateToMediaGroupUpdate.kt (98%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/{ => internal}/CaptionAndTextSourcesToText.kt (98%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/{ => internal}/MultilevelTextSourceFormatting.kt (99%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/{ => internal}/StringFormatting.kt (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91a84a9ea7..3a5c441700 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * `Common`: * `Version`: * `Coroutine`: `1.4.0` -> `1.4.1` + * **NEW** `MicroUtils`: `0.2.7` * `Core`: * Support of `logOut` method (`LogOut` object as a `Request`) * Support of `close` method (`Close` object as a `Request`) @@ -77,6 +78,7 @@ * `MultilevelTextSource#textParts` has been deprecated. Now each `MultilevelTextSource` have its own `textSources` list * New dsl for creating of `TextSource` lists + * Built-in `handleSafely` and `ExceptionHandler` is deprecated * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` diff --git a/gradle.properties b/gradle.properties index e73cbad343..42d720c08a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,6 +12,8 @@ klock_version=1.12.1 uuid_version=0.2.2 ktor_version=1.4.1 +micro_utils_version=0.2.7 + javax_activation_version=1.1.1 library_group=dev.inmo diff --git a/tgbotapi.core/build.gradle b/tgbotapi.core/build.gradle index eaf93b61f8..e0248e76d1 100644 --- a/tgbotapi.core/build.gradle +++ b/tgbotapi.core/build.gradle @@ -47,6 +47,8 @@ kotlin { api "com.soywiz.korlibs.klock:klock:$klock_version" api "com.benasher44:uuid:$uuid_version" + api "dev.inmo:micro_utils.coroutines:$micro_utils_version" + api "io.ktor:ktor-client-core:$ktor_version" } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt index 81cbcdca86..139ae89e82 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.CommonAbstracts import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.utils.fullListOfSubSource +import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource interface Captioned { val caption: String? diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt index 54fcb6b158..fb837163fd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.CommonAbstracts import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.utils.fullListOfSubSource +import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource interface Explained { val explanation: String? diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt index 059575534f..4ff32e73de 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.CommonAbstracts import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.utils.fullListOfSubSource +import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource interface Texted { val text: String? diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt index 780c39992a..949c55caf0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.bot.Ktor +import dev.inmo.micro_utils.coroutines.safely import dev.inmo.tgbotapi.bot.BaseRequestsExecutor import dev.inmo.tgbotapi.bot.Ktor.base.* import dev.inmo.tgbotapi.bot.exceptions.newRequestException @@ -36,7 +37,7 @@ class KtorRequestsExecutor( } override suspend fun execute(request: Request): T { - return handleSafely( + return safely( { e -> throw if (e is ClientRequestException) { val content = e.response ?.readText() ?: throw e diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileRequestCallFactory.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileRequestCallFactory.kt index 05d3874332..cbccc36e5c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileRequestCallFactory.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileRequestCallFactory.kt @@ -1,10 +1,10 @@ package dev.inmo.tgbotapi.bot.Ktor.base +import dev.inmo.micro_utils.coroutines.safely import dev.inmo.tgbotapi.bot.Ktor.KtorCallFactory import dev.inmo.tgbotapi.requests.DownloadFile import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper -import dev.inmo.tgbotapi.utils.handleSafely import io.ktor.client.HttpClient import io.ktor.client.request.get import kotlinx.serialization.json.Json @@ -18,7 +18,7 @@ object DownloadFileRequestCallFactory : KtorCallFactory { ): T? = (request as? DownloadFile) ?.let { val fullUrl = "${urlsKeeper.fileBaseUrl}/${it.filePath}" - return handleSafely { + return safely { @Suppress("UNCHECKED_CAST") client.get(fullUrl) as T // always ByteArray } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt index e41728b732..d8bff5f11d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt @@ -3,8 +3,8 @@ package dev.inmo.tgbotapi.types.MessageEntity import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.* import dev.inmo.tgbotapi.types.User -import dev.inmo.tgbotapi.utils.fullListOfSubSource -import dev.inmo.tgbotapi.utils.shiftSourcesToTheLeft +import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource +import dev.inmo.tgbotapi.utils.internal.shiftSourcesToTheLeft import kotlinx.serialization.Serializable @Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt index 41345fe1e0..64c1d3dee4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt @@ -1,8 +1,10 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* -import dev.inmo.tgbotapi.types.MessageEntity.toTextParts import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.boldMarkdown +import dev.inmo.tgbotapi.utils.internal.boldMarkdownV2 /** * @see bold diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt index ed79857629..8ca260ddf2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt @@ -1,8 +1,10 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* -import dev.inmo.tgbotapi.types.MessageEntity.removeLeading import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.commandMarkdown +import dev.inmo.tgbotapi.utils.internal.commandMarkdownV2 private val commandRegex = Regex("[/!][^@\\s]*") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt index 504a5ebe2f..221fd5712e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.cashTagMarkdown +import dev.inmo.tgbotapi.utils.internal.cashTagMarkdownV2 /** * @see cashTag diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt index d4102a622e..86d4aae7cd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt @@ -3,6 +3,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.codeMarkdown +import dev.inmo.tgbotapi.utils.internal.codeMarkdownV2 /** * @see code diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt index 9fceafd296..77704d1e69 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.emailMarkdown +import dev.inmo.tgbotapi.utils.internal.emailMarkdownV2 /** * @see email diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt index f7f2787c07..37ecbe8861 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.hashTagMarkdown +import dev.inmo.tgbotapi.utils.internal.hashTagMarkdownV2 /** * @see hashtag diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt index 8821e1a05b..887238f2bb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.italicMarkdown +import dev.inmo.tgbotapi.utils.internal.italicMarkdownV2 /** * @see italic diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt index 0c6a168053..ef17ac5632 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt @@ -1,8 +1,10 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* -import dev.inmo.tgbotapi.types.MessageEntity.removeLeading import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.mentionMarkdown +import dev.inmo.tgbotapi.utils.internal.mentionMarkdownV2 private val String.withoutCommercialAt get() = if (startsWith("@")) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt index dada89e413..321fb3f6f5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.phoneMarkdown +import dev.inmo.tgbotapi.utils.internal.phoneMarkdownV2 /** * @see phone diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt index 62e4371746..8ec55f8deb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.preMarkdown +import dev.inmo.tgbotapi.utils.internal.preMarkdownV2 /** * @see pre diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt index 87807b935d..d70f3d1129 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.regularMarkdown +import dev.inmo.tgbotapi.utils.internal.regularMarkdownV2 /** * @see regular diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt index 34a5cb9775..b273b012c0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.strikethroughMarkdown +import dev.inmo.tgbotapi.utils.internal.strikethroughMarkdownV2 /** * @see strikethrough diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt index 0a8a3c512b..c0e3098dba 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.linkMarkdown +import dev.inmo.tgbotapi.utils.internal.linkMarkdownV2 /** * @see link diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt index 086e232510..4ef48dbee6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt @@ -3,6 +3,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.textMentionMarkdown +import dev.inmo.tgbotapi.utils.internal.textMentionMarkdownV2 /** * @see mention diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt index 806d54cde9..4a5fb0825b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.linkMarkdown +import dev.inmo.tgbotapi.utils.internal.linkMarkdownV2 /** * @see link diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt index ef6250b253..3523f12496 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.underlineMarkdown +import dev.inmo.tgbotapi.utils.internal.underlineMarkdownV2 /** * @see underline diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index 644e441646..cfccea7958 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -22,7 +22,6 @@ import dev.inmo.tgbotapi.types.payments.Invoice import dev.inmo.tgbotapi.types.payments.SuccessfulPayment import dev.inmo.tgbotapi.types.polls.Poll import dev.inmo.tgbotapi.types.venue.Venue -import dev.inmo.tgbotapi.utils.fullListOfSubSource import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlin.reflect.KClass diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt index 4fbe499201..08a2d23a34 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt @@ -10,7 +10,9 @@ import dev.inmo.tgbotapi.types.ParseMode.* import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent -import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource +import dev.inmo.tgbotapi.utils.internal.toMarkdownTexts data class TextContent( val text: String, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt index c7b1f6c662..f0cf652083 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt @@ -14,8 +14,8 @@ import dev.inmo.tgbotapi.types.files.AnimationFile import dev.inmo.tgbotapi.types.files.DocumentFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent -import dev.inmo.tgbotapi.utils.toHtmlCaptions -import dev.inmo.tgbotapi.utils.toMarkdownV2Captions +import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions +import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Captions data class AnimationContent( override val media: AnimationFile, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt index 3e93231ffc..b326522b96 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt @@ -12,7 +12,7 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.AudioFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.AudioMediaGroupContent -import dev.inmo.tgbotapi.utils.toHtmlCaptions +import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions data class AudioContent( override val media: AudioFile, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt index 21975585e6..8ff70ac761 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt @@ -15,7 +15,7 @@ import dev.inmo.tgbotapi.types.files.asDocumentFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.DocumentMediaGroupContent import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent -import dev.inmo.tgbotapi.utils.toHtmlCaptions +import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions data class DocumentContent( override val media: DocumentFile, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt index 958477102a..9a7ceabb4c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt @@ -13,7 +13,7 @@ import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MediaCollectionContent import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent -import dev.inmo.tgbotapi.utils.toHtmlCaptions +import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions data class PhotoContent( override val mediaCollection: Photo, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt index 9931dee306..aa5b4185bb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt @@ -12,7 +12,7 @@ import dev.inmo.tgbotapi.types.files.VideoFile import dev.inmo.tgbotapi.types.files.toInputMediaVideo import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent -import dev.inmo.tgbotapi.utils.toHtmlCaptions +import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions data class VideoContent( override val media: VideoFile, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt index 1d2b2dd4ce..6a9894444f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt @@ -13,8 +13,8 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.VoiceFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent -import dev.inmo.tgbotapi.utils.toHtmlCaptions -import dev.inmo.tgbotapi.utils.toMarkdownV2Captions +import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions +import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Captions data class VoiceContent( override val media: VoiceFile, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/HandleSafely.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/HandleSafely.kt index 148d08835d..6f93f28984 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/HandleSafely.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/HandleSafely.kt @@ -1,23 +1,21 @@ package dev.inmo.tgbotapi.utils +import dev.inmo.micro_utils.coroutines.ExceptionHandler +import dev.inmo.micro_utils.coroutines.safely import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.supervisorScope -typealias ExceptionHandler = suspend (Throwable) -> T +@Deprecated("In future will be used typealias from micro_utils", ReplaceWith("ExceptionHandler", "dev.inmo.micro_utils.coroutines.ExceptionHandler")) +typealias ExceptionHandler = ExceptionHandler /** * It will run [block] inside of [supervisorScope] to avoid problems with catching of exceptions * * @param [onException] Will be called when happen exception inside of [block]. By default will throw exception - this * exception will be available for catching */ +@Deprecated("In future will be used typealias from micro_utils", ReplaceWith("safely", "dev.inmo.micro_utils.coroutines.safely")) suspend inline fun handleSafely( noinline onException: ExceptionHandler = { throw it }, noinline block: suspend CoroutineScope.() -> T -): T { - return try { - supervisorScope(block) - } catch (e: Throwable) { - onException(e) - } -} +): T = safely(onException, block) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/BaseMessageUpdateToMediaGroupUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/BaseMessageUpdateToMediaGroupUpdate.kt similarity index 98% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/BaseMessageUpdateToMediaGroupUpdate.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/BaseMessageUpdateToMediaGroupUpdate.kt index 07efbe4b31..5e4cc86d4f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/BaseMessageUpdateToMediaGroupUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/BaseMessageUpdateToMediaGroupUpdate.kt @@ -1,4 +1,4 @@ -package dev.inmo.tgbotapi.utils +package dev.inmo.tgbotapi.utils.internal import dev.inmo.tgbotapi.types.MediaGroupIdentifier import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/CaptionAndTextSourcesToText.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt similarity index 98% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/CaptionAndTextSourcesToText.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt index be317d0bf3..a1c9d049af 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/CaptionAndTextSourcesToText.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt @@ -1,4 +1,4 @@ -package dev.inmo.tgbotapi.utils +package dev.inmo.tgbotapi.utils.internal import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MultilevelTextSourceFormatting.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt similarity index 99% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MultilevelTextSourceFormatting.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt index 0c6ed5bf1b..69e44e5d6c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MultilevelTextSourceFormatting.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt @@ -1,4 +1,4 @@ -package dev.inmo.tgbotapi.utils +package dev.inmo.tgbotapi.utils.internal import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StringFormatting.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/StringFormatting.kt similarity index 99% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StringFormatting.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/StringFormatting.kt index abe06bf13a..2c3b8e8076 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StringFormatting.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/StringFormatting.kt @@ -1,4 +1,4 @@ -package dev.inmo.tgbotapi.utils +package dev.inmo.tgbotapi.utils.internal import dev.inmo.tgbotapi.types.ParseMode.* import dev.inmo.tgbotapi.types.UserId diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/StringFormattingTests.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/StringFormattingTests.kt index b5c16de001..34a7e66975 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/StringFormattingTests.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/StringFormattingTests.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.types.MessageEntity import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.types.MessageEntity.textsources.* import dev.inmo.tgbotapi.CommonAbstracts.plus -import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* import kotlin.test.Test import kotlin.test.assertEquals diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt index d1721cc2fb..a4150e0d3d 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt @@ -1,8 +1,8 @@ package dev.inmo.tgbotapi.types.MessageEntity import dev.inmo.tgbotapi.CommonAbstracts.justTextSources -import dev.inmo.tgbotapi.types.MessageEntity.textsources.* -import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.toHtmlTexts +import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Texts import kotlin.test.* class TextPartsCreatingTests { diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SafelyShortcut.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SafelyShortcut.kt index ad8ab08006..6add07d0b8 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SafelyShortcut.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SafelyShortcut.kt @@ -1,16 +1,18 @@ package dev.inmo.tgbotapi.extensions.utils +import dev.inmo.micro_utils.coroutines.ExceptionHandler import dev.inmo.tgbotapi.utils.* import kotlinx.coroutines.CoroutineScope /** - * Shortcut for [handleSafely]. It was created for more comfortable way of handling different things + * Shortcut for [dev.inmo.micro_utils.coroutines.safely]. It was created for more comfortable way of handling different things */ @PreviewFeature +@Deprecated("In future will be used typealias from micro_utils", ReplaceWith("safely", "dev.inmo.micro_utils.coroutines.safely")) suspend inline fun safely( noinline onException: ExceptionHandler = { throw it }, noinline block: suspend CoroutineScope.() -> T -): T = handleSafely( +): T = dev.inmo.micro_utils.coroutines.safely( onException, block ) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/RequestsExecutor.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/RequestsExecutor.kt index aa4d9b225c..f3ba0f62e7 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/RequestsExecutor.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/RequestsExecutor.kt @@ -1,15 +1,15 @@ package dev.inmo.tgbotapi.extensions.utils.shortcuts +import dev.inmo.micro_utils.coroutines.safely import dev.inmo.tgbotapi.bot.RequestsExecutor import dev.inmo.tgbotapi.requests.abstracts.Request -import dev.inmo.tgbotapi.utils.handleSafely import kotlinx.coroutines.* fun RequestsExecutor.executeAsync( request: Request, scope: CoroutineScope ): Deferred = scope.async { - handleSafely { + safely { execute(request) } } @@ -29,7 +29,7 @@ suspend fun RequestsExecutor.executeUnsafe( var leftRetries = retries val exceptions = onAllFailed ?.let { mutableListOf() } do { - return handleSafely( + return safely ( { leftRetries-- delay(retriesDelay) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt index 03a16b401b..f6802145d1 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt @@ -1,5 +1,7 @@ package dev.inmo.tgbotapi.extensions.utils.updates.retrieving +import dev.inmo.micro_utils.coroutines.ExceptionHandler +import dev.inmo.micro_utils.coroutines.safely import dev.inmo.tgbotapi.bot.RequestsExecutor import dev.inmo.tgbotapi.bot.exceptions.RequestException import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates @@ -23,7 +25,7 @@ fun RequestsExecutor.startGettingOfUpdatesByLongPolling( var lastUpdateIdentifier: UpdateIdentifier? = null while (isActive) { - handleSafely( + safely( { e -> exceptionsHandler ?.invoke(e) if (e is RequestException) { @@ -52,7 +54,7 @@ fun RequestsExecutor.startGettingOfUpdatesByLongPolling( } } - handleSafely { + safely { for (update in updates) { updatesReceiver(update) diff --git a/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt b/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt index 68594fca19..92c50173d4 100644 --- a/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt +++ b/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt @@ -1,5 +1,7 @@ package dev.inmo.tgbotapi.extensions.utils.updates.retrieving +import dev.inmo.micro_utils.coroutines.ExceptionHandler +import dev.inmo.micro_utils.coroutines.safely import dev.inmo.tgbotapi.bot.RequestsExecutor import dev.inmo.tgbotapi.extensions.utils.nonstrictJsonFormat import dev.inmo.tgbotapi.extensions.utils.updates.flowsUpdatesFilter @@ -11,8 +13,6 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.types.update.abstracts.UpdateDeserializationStrategy import dev.inmo.tgbotapi.updateshandlers.* import dev.inmo.tgbotapi.updateshandlers.webhook.WebhookPrivateKeyConfig -import dev.inmo.tgbotapi.utils.ExceptionHandler -import dev.inmo.tgbotapi.utils.handleSafely import io.ktor.application.call import io.ktor.request.receiveText import io.ktor.response.respond @@ -41,7 +41,7 @@ fun Route.includeWebhookHandlingInRoute( ) { val transformer = scope.updateHandlerWithMediaGroupsAdaptation(block) post { - handleSafely( + safely( exceptionsHandler ?: {} ) { val asJson =