diff --git a/CHANGELOG.md b/CHANGELOG.md index 98ef200740..5408fc15ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * `UUID`: `0.1.1` -> `0.2.0` * `Ktor`: `1.3.2` -> `1.3.2-1.4.0-rc` * `buildMimeType` function now is cache-oriented getter which will save already got mime types into internal map + * All deprecations from previous versions were removed ## 0.27.0 diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/BotBuilder.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/BotBuilder.kt index c6af136a44..adc0c53648 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/BotBuilder.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/BotBuilder.kt @@ -13,9 +13,7 @@ import io.ktor.client.engine.* */ data class BotBuilder internal constructor( var proxy: ProxyConfig? = null, - @Deprecated("ktorClientEngineFactory parameter will be used preferable. In future this parameter will be removed") - var ktorClientEngine: HttpClientEngine? = null, - var ktorClientEngineFactory: HttpClientEngineFactory? = null, + var ktorClientEngineFactory: HttpClientEngineFactory? = null, var ktorClientConfig: (HttpClientConfig<*>.() -> Unit) ? = null ) { internal fun createHttpClient(): HttpClient = ktorClientEngineFactory ?.let { @@ -26,13 +24,6 @@ data class BotBuilder internal constructor( ) { ktorClientConfig ?.let { it() } } - } ?: ktorClientEngine ?.let { engine -> - HttpClient(engine) { - ktorClientConfig ?.let { it() } - engine { - this@engine.proxy = this@BotBuilder.proxy ?: this@engine.proxy - } - } } ?: HttpClient { ktorClientConfig ?.let { it() } engine { diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetMe.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetMe.kt deleted file mode 100644 index 889d07a6b0..0000000000 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetMe.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.extensions.api - -import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor -import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.getMe - -@Deprecated( - "Replaced", - ReplaceWith("getMe", "com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.GetMeKt.getMe") -) -suspend fun RequestsExecutor.getMe() = getMe() \ No newline at end of file diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/InternalUtils/UpdatesUtils.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/InternalUtils/UpdatesUtils.kt index a48d6695ee..9dbb93e3c2 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/InternalUtils/UpdatesUtils.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/InternalUtils/UpdatesUtils.kt @@ -16,7 +16,7 @@ internal fun Update.lastUpdateIdentifier(): UpdateIdentifier { } internal fun List.lastUpdateIdentifier(): UpdateIdentifier? { - return maxBy { it.updateId } ?.lastUpdateIdentifier() + return maxByOrNull { it.updateId } ?.lastUpdateIdentifier() } internal fun List.convertWithMediaGroupUpdates(): List { diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt deleted file mode 100644 index a27034cf96..0000000000 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt +++ /dev/null @@ -1,182 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.updates - -import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor -import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException -import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.convertWithMediaGroupUpdates -import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.lastUpdateIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.getUpdates -import com.github.insanusmokrassar.TelegramBotAPI.types.* -import com.github.insanusmokrassar.TelegramBotAPI.types.update.* -import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.* -import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update -import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.* -import com.github.insanusmokrassar.TelegramBotAPI.utils.* -import kotlinx.coroutines.* - -@Deprecated("Replaced and renamed in TelegramBotAPI-extensions-utils") -fun RequestsExecutor.startGettingOfUpdates( - timeoutSeconds: Seconds = 30, - scope: CoroutineScope = CoroutineScope(Dispatchers.Default), - exceptionsHandler: (ExceptionHandler)? = null, - allowedUpdates: List? = null, - updatesReceiver: UpdateReceiver -): Job = scope.launch { - var lastUpdateIdentifier: UpdateIdentifier? = null - - while (isActive) { - handleSafely( - { e -> - exceptionsHandler ?.invoke(e) - if (e is RequestException) { - delay(1000L) - } - } - ) { - val updates = getUpdates( - offset = lastUpdateIdentifier?.plus(1), - timeout = timeoutSeconds, - allowed_updates = allowedUpdates - ).let { originalUpdates -> - val converted = originalUpdates.convertWithMediaGroupUpdates() - /** - * Dirty hack for cases when the media group was retrieved not fully: - * - * We are throw out the last media group and will reretrieve it again in the next get updates - * and it will guarantee that it is full - */ - if (originalUpdates.size == getUpdatesLimit.last && converted.last() is SentMediaGroupUpdate) { - converted - converted.last() - } else { - converted - } - } - - handleSafely { - for (update in updates) { - updatesReceiver(update) - - lastUpdateIdentifier = update.lastUpdateIdentifier() - } - } - } - } -} - -/** - * This method will create a new one [FlowsUpdatesFilter]. This method could be unsafe due to the fact that it will start - * getting updates IMMEDIATELY. That means that your bot will be able to skip some of them until you will call - * [kotlinx.coroutines.flow.Flow.collect] on one of [FlowsUpdatesFilter] flows. To avoid it, you can pass - * [flowUpdatesPreset] lambda - it will be called BEFORE starting updates getting - */ -@FlowPreview -@PreviewFeature -@Suppress("unused") -@Deprecated("Replaced and renamed in TelegramBotAPI-extensions-utils") -fun RequestsExecutor.startGettingFlowsUpdates( - timeoutSeconds: Seconds = 30, - scope: CoroutineScope = CoroutineScope(Dispatchers.Default), - exceptionsHandler: (suspend (Exception) -> Unit)? = null, - flowsUpdatesFilterUpdatesKeeperCount: Int = 100, - flowUpdatesPreset: FlowsUpdatesFilter.() -> Unit = {} -): FlowsUpdatesFilter = FlowsUpdatesFilter(flowsUpdatesFilterUpdatesKeeperCount).apply { - flowUpdatesPreset() - startGettingOfUpdates(timeoutSeconds, scope, exceptionsHandler, allowedUpdates, asUpdateReceiver) -} - -@Deprecated("Replaced and renamed in TelegramBotAPI-extensions-utils") -fun RequestsExecutor.startGettingOfUpdates( - updatesFilter: UpdatesFilter, - timeoutSeconds: Seconds = 30, - exceptionsHandler: (suspend (Exception) -> Unit)? = null, - scope: CoroutineScope = CoroutineScope(Dispatchers.Default) -): Job = startGettingOfUpdates( - timeoutSeconds, - scope, - exceptionsHandler, - updatesFilter.allowedUpdates, - updatesFilter.asUpdateReceiver -) - -@Deprecated("Replaced and renamed in TelegramBotAPI-extensions-utils") -fun RequestsExecutor.startGettingOfUpdates( - messageCallback: UpdateReceiver? = null, - messageMediaGroupCallback: UpdateReceiver? = null, - editedMessageCallback: UpdateReceiver? = null, - editedMessageMediaGroupCallback: UpdateReceiver? = null, - channelPostCallback: UpdateReceiver? = null, - channelPostMediaGroupCallback: UpdateReceiver? = null, - editedChannelPostCallback: UpdateReceiver? = null, - editedChannelPostMediaGroupCallback: UpdateReceiver? = null, - chosenInlineResultCallback: UpdateReceiver? = null, - inlineQueryCallback: UpdateReceiver? = null, - callbackQueryCallback: UpdateReceiver? = null, - shippingQueryCallback: UpdateReceiver? = null, - preCheckoutQueryCallback: UpdateReceiver? = null, - pollCallback: UpdateReceiver? = null, - pollAnswerCallback: UpdateReceiver? = null, - timeoutSeconds: Seconds = 30, - exceptionsHandler: (suspend (Exception) -> Unit)? = null, - scope: CoroutineScope = GlobalScope -): Job { - return startGettingOfUpdates( - SimpleUpdatesFilter( - messageCallback, - messageMediaGroupCallback, - editedMessageCallback, - editedMessageMediaGroupCallback, - channelPostCallback, - channelPostMediaGroupCallback, - editedChannelPostCallback, - editedChannelPostMediaGroupCallback, - chosenInlineResultCallback, - inlineQueryCallback, - callbackQueryCallback, - shippingQueryCallback, - preCheckoutQueryCallback, - pollCallback, - pollAnswerCallback - ), - timeoutSeconds, - exceptionsHandler, - scope - ) -} - -@Suppress("unused") -@Deprecated("Replaced and renamed in TelegramBotAPI-extensions-utils") -fun RequestsExecutor.startGettingOfUpdates( - messageCallback: UpdateReceiver? = null, - mediaGroupCallback: UpdateReceiver? = null, - editedMessageCallback: UpdateReceiver? = null, - channelPostCallback: UpdateReceiver? = null, - editedChannelPostCallback: UpdateReceiver? = null, - chosenInlineResultCallback: UpdateReceiver? = null, - inlineQueryCallback: UpdateReceiver? = null, - callbackQueryCallback: UpdateReceiver? = null, - shippingQueryCallback: UpdateReceiver? = null, - preCheckoutQueryCallback: UpdateReceiver? = null, - pollCallback: UpdateReceiver? = null, - pollAnswerCallback: UpdateReceiver? = null, - timeoutSeconds: Seconds = 30, - exceptionsHandler: (suspend (Exception) -> Unit)? = null, - scope: CoroutineScope = CoroutineScope(Dispatchers.Default) -): Job = startGettingOfUpdates( - messageCallback = messageCallback, - messageMediaGroupCallback = mediaGroupCallback, - editedMessageCallback = editedMessageCallback, - editedMessageMediaGroupCallback = mediaGroupCallback, - channelPostCallback = channelPostCallback, - channelPostMediaGroupCallback = mediaGroupCallback, - editedChannelPostCallback = editedChannelPostCallback, - editedChannelPostMediaGroupCallback = mediaGroupCallback, - chosenInlineResultCallback = chosenInlineResultCallback, - inlineQueryCallback = inlineQueryCallback, - callbackQueryCallback = callbackQueryCallback, - shippingQueryCallback = shippingQueryCallback, - preCheckoutQueryCallback = preCheckoutQueryCallback, - pollCallback = pollCallback, - pollAnswerCallback = pollAnswerCallback, - timeoutSeconds = timeoutSeconds, - exceptionsHandler = exceptionsHandler, - scope = scope -) diff --git a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/formatting/LinksFormatting.kt b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/formatting/LinksFormatting.kt index 3959d7a9b2..8e72db2b47 100644 --- a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/formatting/LinksFormatting.kt +++ b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/formatting/LinksFormatting.kt @@ -5,7 +5,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.UsernameChat import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat -import com.github.insanusmokrassar.TelegramBotAPI.utils.link private const val internalLinkBeginning = "https://t.me" diff --git a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/shortcuts/FlowsUpdatesFilter.kt b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/shortcuts/FlowsUpdatesFilter.kt index ff7a3705f1..5896b59a2e 100644 --- a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/shortcuts/FlowsUpdatesFilter.kt +++ b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/shortcuts/FlowsUpdatesFilter.kt @@ -18,6 +18,7 @@ import kotlinx.coroutines.flow.* inline fun filterForContentMessage(): suspend (ContentMessage<*>) -> ContentMessage? = { if (it.content is T) { + @Suppress("UNCHECKED_CAST") it as ContentMessage } else { null @@ -32,6 +33,7 @@ inline fun Flow.filterMedi ): Flow>> = map { it.data.mapNotNull { message -> if (message.content is T) { + @Suppress("UNCHECKED_CAST") message as CommonMessage } else { null @@ -83,7 +85,10 @@ fun FlowsUpdatesFilter.sentMessagesWithMediaGroups( ): Flow> = merge( sentMessages(scopeToIncludeChannels), mediaGroupMessages(scopeToIncludeChannels).flatMap { - it.mapNotNull { it as? ContentMessage } + it.mapNotNull { + @Suppress("UNCHECKED_CAST") + it as? ContentMessage + } } ) diff --git a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/UpdatesChatFilters.kt b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/UpdatesChatFilters.kt index 1812a94ec1..247e63d2e3 100644 --- a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/UpdatesChatFilters.kt +++ b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/UpdatesChatFilters.kt @@ -15,16 +15,6 @@ fun Flow.filterBaseMessageUpdatesByChatId(chatId: Cha * [Flow.filter] incoming [BaseMessageUpdate]s by their [ChatId] using [Chat.id] of [chat] */ fun Flow.filterBaseMessageUpdatesByChat(chat: Chat): Flow = filterBaseMessageUpdatesByChatId(chat.id) -/** - * [Flow.filter] incoming [BaseMessageUpdate]s by their [ChatId] - */ -@Deprecated("Renamed", ReplaceWith("filterBaseMessageUpdatesByChatId")) -fun Flow.filterBaseMessageUpdates(chatId: ChatId): Flow = filterBaseMessageUpdatesByChatId(chatId) -/** - * [Flow.filter] incoming [BaseMessageUpdate]s by their [ChatId] using [Chat.id] of [chat] - */ -@Deprecated("Renamed", ReplaceWith("filterBaseMessageUpdatesByChat")) -fun Flow.filterBaseMessageUpdates(chat: Chat): Flow = filterBaseMessageUpdatesByChatId(chat.id) /** @@ -35,13 +25,3 @@ fun Flow.filterSentMediaGroupUpdatesByChatId(chatI * [Flow.filter] incoming [SentMediaGroupUpdate]s by their [ChatId] using [Chat.id] of [chat] */ fun Flow.filterSentMediaGroupUpdatesByChat(chat: Chat): Flow = filterSentMediaGroupUpdatesByChatId(chat.id) -/** - * [Flow.filter] incoming [SentMediaGroupUpdate]s by their [ChatId] - */ -@Deprecated("Renamed", ReplaceWith("filterSentMediaGroupUpdatesByChatId")) -fun Flow.filterSentMediaGroupUpdates(chatId: ChatId): Flow = filterSentMediaGroupUpdatesByChatId(chatId) -/** - * [Flow.filter] incoming [SentMediaGroupUpdate]s by their [ChatId] using [Chat.id] of [chat] - */ -@Deprecated("Renamed", ReplaceWith("filterSentMediaGroupUpdatesByChat")) -fun Flow.filterSentMediaGroupUpdates(chat: Chat): Flow = filterSentMediaGroupUpdatesByChatId(chat.id) diff --git a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/UpdatesUtils.kt b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/UpdatesUtils.kt index 6aa7bc6ba9..b72f398530 100644 --- a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/UpdatesUtils.kt +++ b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/UpdatesUtils.kt @@ -24,7 +24,7 @@ fun Update.lastUpdateIdentifier(): UpdateIdentifier { * @see [Update.lastUpdateIdentifier] */ fun List.lastUpdateIdentifier(): UpdateIdentifier? { - return maxBy { it.updateId } ?.lastUpdateIdentifier() + return maxByOrNull { it.updateId } ?.lastUpdateIdentifier() } /** diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt deleted file mode 100644 index 4c4dab284b..0000000000 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.requests - -import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe - -@Deprecated( - "Replaced", - ReplaceWith( - "GetMe", "com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe" - ) -) -typealias GetMe = GetMe diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendMediaGroup.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendMediaGroup.kt index 43841c3869..878cc01a6f 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendMediaGroup.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendMediaGroup.kt @@ -13,11 +13,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls import kotlinx.serialization.* import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.json.buildJsonArray -import kotlinx.serialization.json.jsonArray - -@Deprecated("Replaced and renamed", ReplaceWith("mediaCountInMediaGroup", "com.github.insanusmokrassar.TelegramBotAPI.types.mediaCountInMediaGroup")) -val membersCountInMediaGroup - get() = mediaCountInMediaGroup fun SendMediaGroup( chatId: ChatIdentifier, diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt index 662d1c69e4..c0d02096e3 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt @@ -212,15 +212,11 @@ data class SendQuizPoll( override val replyToMessageId: MessageIdentifier? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null -) : SendPoll(), CaptionedOutput, ExplainedOutput { +) : SendPoll(), ExplainedOutput { override val type: String = quizPollType override val requestSerializer: SerializationStrategy<*> get() = serializer() - @Deprecated("Will be removed in near updates", ReplaceWith("explanation")) - override val caption: String? - get() = explanation - @SerialName(openPeriodField) override val openPeriod: LongSeconds? = (closeInfo as? ApproximateScheduledCloseInfo) ?.openDuration ?.millisecondsLong ?.div(1000) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt index 769cd69e55..6deb5916f8 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt @@ -24,24 +24,6 @@ fun AddStaticStickerToSet( } } -@Deprecated( - "Renamed", - ReplaceWith("AddStaticStickerToSet", "com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.AddStaticStickerToSet") -) -fun AddStickerToSet( - userId: UserId, - stickerSetName: String, - sticker: InputFile, - emojis: String, - maskPosition: MaskPosition? = null -) = AddStaticStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) - -@Deprecated( - "Renamed", - ReplaceWith("AddStaticStickerToSet", "com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.AddStaticStickerToSet") -) -typealias AddStickerToSet = AddStaticStickerToSet - @Serializable data class AddStaticStickerToSet internal constructor( @SerialName(userIdField) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt index 2fda4511cc..06801854ea 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt @@ -34,12 +34,6 @@ fun CreateNewStickerSet( maskPosition: MaskPosition? = null ): Request = CreateNewStaticStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) -@Deprecated( - "Renamed", - ReplaceWith("CreateNewStaticStickerSet", "com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.CreateNewStaticStickerSet") -) -typealias CreateNewStickerSet = CreateNewStaticStickerSet - @Serializable data class CreateNewStaticStickerSet internal constructor( @SerialName(userIdField) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index f1ad390052..915e9bb031 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -62,8 +62,6 @@ val botCommandsLimit = 0 .. 100 val mediaCountInMediaGroup: IntRange = 2 .. 10 val explanationLimit = 0 .. 200 -@Deprecated("Will be removed in near updates", ReplaceWith("explanationLimit")) -val quizPollExplanationLimit = explanationLimit val openPeriodPollSecondsLimit = 5 .. 600 diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Dice.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Dice.kt deleted file mode 100644 index 428e9c2d91..0000000000 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Dice.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.types - -import com.github.insanusmokrassar.TelegramBotAPI.types.dice.Dice - -@Deprecated( - "Replaced", - ReplaceWith("Dice", "com.github.insanusmokrassar.TelegramBotAPI.types.dice.Dice") -) -typealias Dice = Dice diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InlineQueries/InlineQueryResult/abstracts/PositionedInlineQueryResult.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InlineQueries/InlineQueryResult/abstracts/PositionedInlineQueryResult.kt deleted file mode 100644 index f385dc4fb5..0000000000 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InlineQueries/InlineQueryResult/abstracts/PositionedInlineQueryResult.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts - -import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.Locationed - -@Deprecated("Will be removed due to useless") -interface PositionedInlineQueryResult : InlineQueryResult, Locationed \ No newline at end of file diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Venue.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Venue.kt deleted file mode 100644 index 6d6adef5e5..0000000000 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Venue.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.types - -import com.github.insanusmokrassar.TelegramBotAPI.types.venue.Venue - -@Deprecated("Replaced", ReplaceWith("Venue", "com.github.insanusmokrassar.TelegramBotAPI.types.venue.Venue")) -typealias Venue = Venue diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/dice/DiceAnimationType.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/dice/DiceAnimationType.kt index 5591aee613..9524bb2d4e 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/dice/DiceAnimationType.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/dice/DiceAnimationType.kt @@ -25,8 +25,6 @@ object BasketballDiceAnimationType : DiceAnimationType() { data class CustomDiceAnimationType( override val emoji: String ) : DiceAnimationType() -@Deprecated("Renamed", ReplaceWith("CustomDiceAnimationType")) -typealias UnknownDiceAnimationType = CustomDiceAnimationType @Serializer(DiceAnimationType::class) internal object DiceAnimationTypeSerializer : KSerializer { diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/PhotoSize.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/PhotoSize.kt index a79862a075..58022354c2 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/PhotoSize.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/PhotoSize.kt @@ -9,7 +9,7 @@ import kotlinx.serialization.builtins.ListSerializer typealias Photo = List -fun Photo.biggest(): PhotoSize? = maxBy { +fun Photo.biggest(): PhotoSize? = maxByOrNull { it.resolution } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/Poll.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/Poll.kt index 21a1636277..318b97030d 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/Poll.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/Poll.kt @@ -136,14 +136,7 @@ data class QuizPoll( override val isClosed: Boolean = false, override val isAnonymous: Boolean = false, override val scheduledCloseInfo: ScheduledCloseInfo? = null -) : Poll(), CaptionedInput, ExplainedInput { - @Deprecated("Will be removed in near updates", ReplaceWith("explanation")) - override val caption: String? - get() = explanation - @Deprecated("Will be removed in near updates", ReplaceWith("explanationEntities")) - override val captionEntities: List - get() = explanationEntities -} +) : Poll(), ExplainedInput @Serializer(Poll::class) internal object PollSerializer : KSerializer { diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt index 3a5212438b..d8059c667b 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt @@ -19,8 +19,6 @@ data class UnknownUpdate( override val data: String, val rawJson: JsonElement ) : Update -@Deprecated("Renamed", ReplaceWith("UnknownUpdate")) -typealias UnknownUpdateType = UnknownUpdate internal object UpdateSerializerWithoutSerialization : KSerializer { override val descriptor: SerialDescriptor = JsonElement.serializer().descriptor diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/CaptionAndTextSourcesToText.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/CaptionAndTextSourcesToText.kt index cc6003d826..ca75e16968 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/CaptionAndTextSourcesToText.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/CaptionAndTextSourcesToText.kt @@ -6,8 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.fullEntitiesList -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun createFormattedText( +internal fun createFormattedText( entities: FullTextSourcesList, partLength: Int = textLength.last, mode: ParseMode = MarkdownParseMode @@ -48,96 +47,63 @@ fun createFormattedText( } -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun createMarkdownText( +internal fun createMarkdownText( entities: FullTextSourcesList, partLength: Int = textLength.last ): List = createFormattedText(entities, partLength, MarkdownParseMode) -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun FullTextSourcesList.toMarkdownCaptions(): List = createMarkdownText( - this, - captionLength.last -) -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun CaptionedInput.toMarkdownCaptions(): List = fullEntitiesList().toMarkdownCaptions() - -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun FullTextSourcesList.toMarkdownTexts(): List = createMarkdownText( +internal fun FullTextSourcesList.toMarkdownTexts(): List = createMarkdownText( this, textLength.last ) -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun TextContent.toMarkdownTexts(): List = fullEntitiesList().toMarkdownTexts() +internal fun TextContent.toMarkdownTexts(): List = fullEntitiesList().toMarkdownTexts() -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun FullTextSourcesList.toMarkdownExplanations(): List = createMarkdownText( +internal fun FullTextSourcesList.toMarkdownExplanations(): List = createMarkdownText( this, explanationLimit.last ) -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun ExplainedInput.toMarkdownExplanations(): List = fullEntitiesList().toMarkdownTexts() +internal fun ExplainedInput.toMarkdownExplanations(): List = fullEntitiesList().toMarkdownTexts() -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun createMarkdownV2Text( +internal fun createMarkdownV2Text( entities: FullTextSourcesList, partLength: Int = textLength.last ): List = createFormattedText(entities, partLength, MarkdownV2ParseMode) -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun FullTextSourcesList.toMarkdownV2Captions(): List = createMarkdownV2Text( +internal fun FullTextSourcesList.toMarkdownV2Captions(): List = createMarkdownV2Text( this, captionLength.last ) -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun CaptionedInput.toMarkdownV2Captions(): List = fullEntitiesList().toMarkdownV2Captions() +internal fun CaptionedInput.toMarkdownV2Captions(): List = fullEntitiesList().toMarkdownV2Captions() -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun FullTextSourcesList.toMarkdownV2Texts(): List = createMarkdownV2Text( +internal fun FullTextSourcesList.toMarkdownV2Texts(): List = createMarkdownV2Text( this, textLength.last ) -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun TextContent.toMarkdownV2Texts(): List = fullEntitiesList().toMarkdownV2Texts() +internal fun TextContent.toMarkdownV2Texts(): List = fullEntitiesList().toMarkdownV2Texts() -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun FullTextSourcesList.toMarkdownV2Explanations(): List = createMarkdownV2Text( +internal fun FullTextSourcesList.toMarkdownV2Explanations(): List = createMarkdownV2Text( this, explanationLimit.last ) -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun ExplainedInput.toMarkdownV2Explanations(): List = fullEntitiesList().toMarkdownV2Texts() +internal fun ExplainedInput.toMarkdownV2Explanations(): List = fullEntitiesList().toMarkdownV2Texts() -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun createHtmlText( +internal fun createHtmlText( entities: FullTextSourcesList, partLength: Int = textLength.last ): List = createFormattedText(entities, partLength, HTMLParseMode) -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun FullTextSourcesList.toHtmlCaptions(): List = createHtmlText( +internal fun FullTextSourcesList.toHtmlCaptions(): List = createHtmlText( this, captionLength.last ) -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun CaptionedInput.toHtmlCaptions(): List = fullEntitiesList().toHtmlCaptions() +internal fun CaptionedInput.toHtmlCaptions(): List = fullEntitiesList().toHtmlCaptions() -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun FullTextSourcesList.toHtmlTexts(): List = createHtmlText( +internal fun FullTextSourcesList.toHtmlTexts(): List = createHtmlText( this, textLength.last ) -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun TextContent.toHtmlTexts(): List = fullEntitiesList().toHtmlTexts() - -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun FullTextSourcesList.toHtmlExplanations(): List = createHtmlText( - this, - explanationLimit.last -) -@Deprecated("Replaced into TelegramBotAPI-extensions-utils") -fun ExplainedInput.toHtmlExplanations(): List = fullEntitiesList().toHtmlTexts() +internal fun TextContent.toHtmlTexts(): List = fullEntitiesList().toHtmlTexts() diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/LinksFormatting.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/LinksFormatting.kt deleted file mode 100644 index 9bacaf0dc4..0000000000 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/LinksFormatting.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.utils - -import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.UsernameChat -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat - -private const val internalLinkBeginning = "https://t.me" - -@Deprecated("Replaced into TelegramBotAPI-extensions-utils project") -fun makeLinkToMessage( - username: String, - messageId: MessageIdentifier -): String = "$internalLinkBeginning/$username/$messageId" - -private val linkIdRedundantPartRegex = Regex("^-100") -private val usernameBeginSymbolRegex = Regex("^@") - -@Deprecated("Replaced into TelegramBotAPI-extensions-utils project") -fun makeLinkToMessage( - chat: ExtendedChat, - messageId: MessageIdentifier -): String? { - return when { - chat is UsernameChat && chat.username != null -> { - "$internalLinkBeginning/${chat.username ?.username ?.replace(usernameBeginSymbolRegex, "")}/$messageId" - } - chat !is PrivateChat -> chat.id.chatId.toString().replace( - linkIdRedundantPartRegex, - "" - ).let { bareId -> - "$internalLinkBeginning/c/$bareId/$messageId" - } - else -> return null - } -} diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/MediaGroupList.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/MediaGroupList.kt deleted file mode 100644 index fef1514452..0000000000 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/MediaGroupList.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.utils - -import com.github.insanusmokrassar.TelegramBotAPI.types.MediaGroupIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat -import com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardInfo -import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* -import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate - -@Deprecated("Replaced and updated inside of TelegramBotAPI-extensions-utils") -val List.forwarded: ForwardInfo? - get() = first().let { - (it as? PossiblyForwardedMessage) ?.forwardInfo - } - -@Deprecated("Replaced and updated inside of TelegramBotAPI-extensions-utils") -val List.replyTo: Message? - get() = first().let { - (it as? PossiblyReplyMessage) ?.replyTo - } - -@Deprecated("Replaced and updated inside of TelegramBotAPI-extensions-utils") -val List.chat: Chat? - get() = first().data.chat - -@Deprecated("Replaced and updated inside of TelegramBotAPI-extensions-utils") -val List.mediaGroupId: MediaGroupIdentifier? - get() = (first().data as? MediaGroupMessage) ?.mediaGroupId diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/StringFormatting.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/StringFormatting.kt index 0dbb355654..1431381d95 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/StringFormatting.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/StringFormatting.kt @@ -36,72 +36,45 @@ private fun String.htmlDefault( closeControlSymbol: String = openControlSymbol ) = "<$openControlSymbol>${toHtml()}" -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.linkMarkdown(link: String): String = "[${toMarkdown()}](${link.toMarkdown()})" -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.linkMarkdownV2(link: String): String = "[${escapeMarkdownV2Common()}](${link.escapeMarkdownV2Link()})" -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.linkHTML(link: String): String = "${toHtml()}" +internal fun String.linkMarkdown(link: String): String = "[${toMarkdown()}](${link.toMarkdown()})" +internal fun String.linkMarkdownV2(link: String): String = "[${escapeMarkdownV2Common()}](${link.escapeMarkdownV2Link()})" +internal fun String.linkHTML(link: String): String = "${toHtml()}" -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.boldMarkdown(): String = markdownDefault(markdownBoldControl) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.boldMarkdownV2(): String = markdownV2Default(markdownBoldControl) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.boldHTML(): String = htmlDefault(htmlBoldControl) +internal fun String.boldMarkdown(): String = markdownDefault(markdownBoldControl) - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.italicMarkdown(): String = markdownDefault(markdownItalicControl) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.italicMarkdownV2(): String = markdownV2Default(markdownItalicControl, markdownV2ItalicEndControl) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.italicHTML(): String = htmlDefault(htmlItalicControl) +internal fun String.italicMarkdown(): String = markdownDefault(markdownItalicControl) /** * Crutch for support of strikethrough in default markdown. Simply add modifier, but it will not look like correct */ -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.strikethroughMarkdown(): String = map { it + "\u0336" }.joinToString("") -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.strikethroughMarkdownV2(): String = markdownV2Default(markdownV2StrikethroughControl) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.strikethroughHTML(): String = htmlDefault(htmlStrikethroughControl) + +internal fun String.strikethroughMarkdown(): String = map { it + "\u0336" }.joinToString("") +internal fun String.strikethroughMarkdownV2(): String = markdownV2Default(markdownV2StrikethroughControl) /** * Crutch for support of underline in default markdown. Simply add modifier, but it will not look like correct */ -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.underlineMarkdown(): String = map { it + "\u0347" }.joinToString("") -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.underlineMarkdownV2(): String = markdownV2Default(markdownV2UnderlineControl, markdownV2UnderlineEndControl) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.underlineHTML(): String = htmlDefault(htmlUnderlineControl) +internal fun String.underlineMarkdown(): String = map { it + "\u0347" }.joinToString("") +internal fun String.underlineMarkdownV2(): String = markdownV2Default(markdownV2UnderlineControl, markdownV2UnderlineEndControl) +internal fun String.underlineHTML(): String = htmlDefault(htmlUnderlineControl) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.codeMarkdown(): String = markdownDefault(markdownCodeControl) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.codeMarkdownV2(): String = markdownV2Default(markdownCodeControl, escapeFun = String::escapeMarkdownV2PreAndCode) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.codeHTML(): String = htmlDefault(htmlCodeControl) +internal fun String.codeMarkdown(): String = markdownDefault(markdownCodeControl) +internal fun String.codeMarkdownV2(): String = markdownV2Default(markdownCodeControl, escapeFun = String::escapeMarkdownV2PreAndCode) +internal fun String.codeHTML(): String = htmlDefault(htmlCodeControl) - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.preMarkdown(language: String? = null): String = markdownDefault( +internal fun String.preMarkdown(language: String? = null): String = markdownDefault( "$markdownPreControl${language ?: ""}\n", "\n$markdownPreControl" ) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.preMarkdownV2(language: String? = null): String = markdownV2Default( +internal fun String.preMarkdownV2(language: String? = null): String = markdownV2Default( "$markdownPreControl${language ?: ""}\n", "\n$markdownPreControl", String::escapeMarkdownV2PreAndCode ) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.preHTML(language: String? = null): String = htmlDefault( +internal fun String.preHTML(language: String? = null): String = htmlDefault( language ?.let { "$htmlPreControl><$htmlCodeControl class=\"language-$language\"" } ?: htmlPreControl, @@ -110,198 +83,68 @@ fun String.preHTML(language: String? = null): String = htmlDefault( } ?: htmlPreControl ) +internal fun String.emailMarkdown(): String = linkMarkdown("mailto://$${toMarkdown()}") -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.emailMarkdown(): String = linkMarkdown("mailto://$${toMarkdown()}") -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.emailMarkdownV2(): String = linkMarkdownV2("mailto://$${toMarkdown()}") -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.emailHTML(): String = linkHTML("mailto://$${toHtml()}") - - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") private inline fun String.mention(adapt: String.() -> String): String = if (startsWith("@")) { adapt() } else { "@${adapt()}" } - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") private inline fun String.hashTag(adapt: String.() -> String): String = if (startsWith("#")) { adapt() } else { "#${adapt()}" } +internal fun String.textMentionMarkdown(userId: UserId): String = linkMarkdown(userId.link) +internal fun String.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.textMentionMarkdown(userId: UserId): String = linkMarkdown(userId.link) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.textMentionHTML(userId: UserId): String = linkHTML(userId.link) +internal fun String.mentionMarkdown(): String = mention(String::toMarkdown) +internal fun String.hashTagMarkdown(): String = hashTag(String::toMarkdown) +internal fun String.hashTagHTML(): String = hashTag(String::toHtml) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.mentionMarkdown(): String = mention(String::toMarkdown) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.mentionMarkdownV2(): String = mention(String::escapeMarkdownV2Common) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.mentionHTML(): String = mention(String::toHtml) +internal fun String.phoneMarkdown(): String = toMarkdown() - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.hashTagMarkdown(): String = hashTag(String::toMarkdown) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.hashTagMarkdownV2(): String = hashTag(String::escapeMarkdownV2Common).escapeMarkdownV2Common() -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.hashTagHTML(): String = hashTag(String::toHtml) - - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.phoneMarkdown(): String = toMarkdown() -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.phoneMarkdownV2(): String = escapeMarkdownV2Common() -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.phoneHTML(): String = toHtml() - - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.command(adapt: String.() -> String): String = if (startsWith("/")) { +internal fun String.command(adapt: String.() -> String): String = if (startsWith("/")) { adapt() } else { "/${adapt()}" } -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.commandMarkdown(): String = command(String::toMarkdown) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.commandMarkdownV2(): String = command(String::escapeMarkdownV2Common) -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.commandHTML(): String = command(String::toHtml) +internal fun String.commandMarkdown(): String = command(String::toMarkdown) +internal fun String.commandMarkdownV2(): String = command(String::escapeMarkdownV2Common) +internal fun String.commandHTML(): String = command(String::toHtml) +internal fun String.regularMarkdown(): String = toMarkdown() +internal fun String.regularMarkdownV2(): String = escapeMarkdownV2Common() +internal fun String.regularHtml(): String = toHtml() -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.regularMarkdown(): String = toMarkdown() -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.regularMarkdownV2(): String = escapeMarkdownV2Common() -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.regularHtml(): String = toHtml() +internal fun String.cashTagMarkdown(): String = toMarkdown() - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.cashTagMarkdown(): String = toMarkdown() -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.cashTagMarkdownV2(): String = escapeMarkdownV2Common() -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.cashTagHtml(): String = toHtml() - - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -infix fun String.bold(parseMode: ParseMode): String = when (parseMode) { - is HTML -> boldHTML() - is Markdown -> boldMarkdown() - is MarkdownV2 -> boldMarkdownV2() -} - - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -infix fun String.italic(parseMode: ParseMode): String = when (parseMode) { - is HTML -> italicHTML() - is Markdown -> italicMarkdown() - is MarkdownV2 -> italicMarkdownV2() -} - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -infix fun String.hashTag(parseMode: ParseMode): String = when (parseMode) { - is HTML -> hashTagHTML() - is Markdown -> hashTagMarkdown() - is MarkdownV2 -> hashTagMarkdownV2() -} - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -infix fun String.code(parseMode: ParseMode): String = when (parseMode) { +internal infix fun String.code(parseMode: ParseMode): String = when (parseMode) { is HTML -> codeHTML() is Markdown -> codeMarkdown() is MarkdownV2 -> codeMarkdownV2() } -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -fun String.pre(parseMode: ParseMode, language: String? = null): String = when (parseMode) { - is HTML -> preHTML(language) - is Markdown -> preMarkdown(language) - is MarkdownV2 -> preMarkdownV2(language) -} -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -infix fun String.pre(parseMode: ParseMode): String = pre(parseMode, null) - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -infix fun String.email(parseMode: ParseMode): String = when (parseMode) { - is HTML -> emailHTML() - is Markdown -> emailMarkdown() - is MarkdownV2 -> emailMarkdownV2() -} - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -infix fun Pair.link(parseMode: ParseMode): String = when (parseMode) { +internal infix fun Pair.link(parseMode: ParseMode): String = when (parseMode) { is HTML -> first.linkHTML(second) is Markdown -> first.linkMarkdown(second) is MarkdownV2 -> first.linkMarkdownV2(second) } -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -infix fun String.mention(parseMode: ParseMode): String = when (parseMode) { - is HTML -> mentionHTML() - is Markdown -> mentionMarkdown() - is MarkdownV2 -> mentionMarkdownV2() -} -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -infix fun Pair.mention(parseMode: ParseMode): String = when (parseMode) { - is HTML -> first.textMentionHTML(second) - is Markdown -> first.textMentionMarkdown(second) - is MarkdownV2 -> first.textMentionMarkdownV2(second) -} - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -infix fun String.phone(parseMode: ParseMode): String = when (parseMode) { - is HTML -> phoneHTML() - is Markdown -> phoneMarkdown() - is MarkdownV2 -> phoneMarkdownV2() -} - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -infix fun String.command(parseMode: ParseMode): String = when (parseMode) { +internal infix fun String.command(parseMode: ParseMode): String = when (parseMode) { is HTML -> commandHTML() is Markdown -> commandMarkdown() is MarkdownV2 -> commandMarkdownV2() } -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -infix fun String.underline(parseMode: ParseMode): String = when (parseMode) { + +internal infix fun String.underline(parseMode: ParseMode): String = when (parseMode) { is HTML -> underlineHTML() is Markdown -> underlineMarkdown() is MarkdownV2 -> underlineMarkdownV2() } - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -infix fun String.strikethrough(parseMode: ParseMode): String = when (parseMode) { - is HTML -> strikethroughHTML() - is Markdown -> strikethroughMarkdown() - is MarkdownV2 -> strikethroughMarkdownV2() -} - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -infix fun String.regular(parseMode: ParseMode): String = when (parseMode) { - is HTML -> regularHtml() - is Markdown -> regularMarkdown() - is MarkdownV2 -> regularMarkdownV2() -} - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -infix fun String.cashtag(parseMode: ParseMode): String = when (parseMode) { - is HTML -> cashTagHtml() - is Markdown -> cashTagMarkdown() - is MarkdownV2 -> cashTagMarkdownV2() -} diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Executes.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Executes.kt deleted file mode 100644 index 84904405af..0000000000 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Executes.kt +++ /dev/null @@ -1,58 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.utils.extensions - -import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor -import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException -import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request -import com.github.insanusmokrassar.TelegramBotAPI.types.Response -import com.github.insanusmokrassar.TelegramBotAPI.utils.handleSafely -import kotlinx.coroutines.* - -@Deprecated("Will be removed in next major update") -fun RequestsExecutor.executeAsync( - request: Request, - onFail: (suspend (Response) -> Unit)? = null, - scope: CoroutineScope = GlobalScope, - onSuccess: (suspend (T) -> Unit)? = null -): Job { - return scope.launch { - try { - val result = execute(request) - onSuccess ?.invoke(result) - } catch (e: RequestException) { - onFail ?.invoke(e.response) - } - } -} - -@Deprecated("Replaced and modified inside of TelegramBotAPI-extensions-utils") -fun RequestsExecutor.executeAsync( - request: Request, - scope: CoroutineScope = GlobalScope -): Deferred { - return scope.async { execute(request) } -} - -@Deprecated("Replaced and modified inside of TelegramBotAPI-extensions-utils") -suspend fun RequestsExecutor.executeUnsafe( - request: Request, - retries: Int = 0, - retriesDelay: Long = 1000L, - onAllFailed: (suspend (exceptions: Array) -> Unit)? = null -): T? { - var leftRetries = retries - val exceptions = onAllFailed ?.let { mutableListOf() } - do { - handleSafely( - { - leftRetries-- - delay(retriesDelay) - exceptions ?.add(it) - null - } - ) { - execute(request) - } ?.let { return it } - } while(leftRetries >= 0) - onAllFailed ?.invoke(exceptions ?.toTypedArray() ?: emptyArray()) - return null -} diff --git a/TelegramBotAPI/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt b/TelegramBotAPI/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt deleted file mode 100644 index 322cfb8f28..0000000000 --- a/TelegramBotAPI/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt +++ /dev/null @@ -1,218 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.utils.extensions - -import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor -import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.InputFile -import com.github.insanusmokrassar.TelegramBotAPI.requests.webhook.SetWebhook -import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage -import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.* -import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdateReceiver -import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdatesFilter -import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.webhook.WebhookPrivateKeyConfig -import com.github.insanusmokrassar.TelegramBotAPI.utils.* -import io.ktor.application.call -import io.ktor.request.receiveText -import io.ktor.response.respond -import io.ktor.routing.post -import io.ktor.routing.routing -import io.ktor.server.engine.* -import kotlinx.coroutines.* -import kotlinx.coroutines.channels.Channel -import java.util.concurrent.Executors -import java.util.concurrent.TimeUnit - -/** - * Reverse proxy webhook. - * - * @param url URL of webhook WITHOUT including of [port] - * @param port port which will be listen by bot - * @param listenRoute address to listen by bot - * @param certificate [com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile] or [com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId] - * which will be used by telegram to send encrypted messages - * @param scope Scope which will be used for - */ -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -suspend fun RequestsExecutor.setWebhook( - url: String, - port: Int, - engineFactory: ApplicationEngineFactory<*, *>, - listenHost: String = "0.0.0.0", - listenRoute: String = "/", - certificate: InputFile? = null, - privateKeyConfig: WebhookPrivateKeyConfig? = null, - scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), - allowedUpdates: List? = null, - maxAllowedConnections: Int? = null, - exceptionsHandler: (ExceptionHandler)? = null, - block: UpdateReceiver -): Job { - val executeDeferred = certificate ?.let { - executeAsync( - SetWebhook( - url, - certificate, - maxAllowedConnections, - allowedUpdates - ) - ) - } ?: executeAsync( - SetWebhook( - url, - maxAllowedConnections, - allowedUpdates - ) - ) - val updatesChannel = Channel(Channel.UNLIMITED) - val mediaGroupChannel = Channel>(Channel.UNLIMITED) - val mediaGroupAccumulatedChannel = mediaGroupChannel.accumulateByKey( - 1000L, - scope = scope - ) - val env = applicationEngineEnvironment { - - module { - routing { - post(listenRoute) { - handleSafely( - { - exceptionsHandler ?.invoke(it) - } - ) { - val asJson = nonstrictJsonFormat.parseToJsonElement(call.receiveText()) - val update = nonstrictJsonFormat.decodeFromJsonElement( - UpdateDeserializationStrategy, - asJson - ) - updatesChannel.send(update) - } - call.respond("Ok") - } - } - } - privateKeyConfig ?.let { - sslConnector( - privateKeyConfig.keyStore, - privateKeyConfig.aliasName, - privateKeyConfig::keyStorePassword, - privateKeyConfig::aliasPassword - ) { - host = listenHost - this.port = port - } - } ?: connector { - host = listenHost - this.port = port - } - - } - val engine = embeddedServer(engineFactory, env) - - try { - executeDeferred.await() - } catch (e: Exception) { - env.stop() - throw e - } - - return scope.launch { - launch { - for (update in updatesChannel) { - val data = update.data - when (data) { - is MediaGroupMessage -> mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate) - else -> block(update) - } - } - } - launch { - for ((_, mediaGroup) in mediaGroupAccumulatedChannel) { - mediaGroup.convertWithMediaGroupUpdates().forEach { - block(it) - } - } - } - engine.start(false) - }.also { - it.invokeOnCompletion { - engine.stop(1000L, 0L, TimeUnit.MILLISECONDS) - } - } -} - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -suspend fun RequestsExecutor.setWebhook( - url: String, - port: Int, - engineFactory: ApplicationEngineFactory<*, *>, - listenHost: String = "0.0.0.0", - listenRoute: String = "/", - certificate: InputFile? = null, - privateKeyConfig: WebhookPrivateKeyConfig? = null, - scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), - allowedUpdates: List? = null, - maxAllowedConnections: Int? = null, - block: UpdateReceiver -) = setWebhook( - url, - port, - engineFactory, - listenHost, - listenRoute, - certificate, - privateKeyConfig, - scope, - allowedUpdates, - maxAllowedConnections, - null, - block -) - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -suspend fun RequestsExecutor.setWebhook( - url: String, - port: Int, - engineFactory: ApplicationEngineFactory<*, *>, - certificate: InputFile? = null, - privateKeyConfig: WebhookPrivateKeyConfig? = null, - scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), - allowedUpdates: List? = null, - maxAllowedConnections: Int? = null, - block: UpdateReceiver -) = setWebhook( - url, - port, - engineFactory, - certificate ?.let { "0.0.0.0" } ?: "localhost", - "/", - certificate, - privateKeyConfig, - scope, - allowedUpdates, - maxAllowedConnections, - block -) - -@Deprecated("Replaced into project TelegramBotAPI-extensions-utils") -suspend fun RequestsExecutor.setWebhook( - url: String, - port: Int, - filter: UpdatesFilter, - engineFactory: ApplicationEngineFactory<*, *>, - certificate: InputFile? = null, - privateKeyConfig: WebhookPrivateKeyConfig? = null, - scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), - maxAllowedConnections: Int? = null, - listenHost: String = certificate ?.let { "0.0.0.0" } ?: "localhost", - listenRoute: String = "/" -): Job = setWebhook( - url, - port, - engineFactory, - listenHost, - listenRoute, - certificate, - privateKeyConfig, - scope, - filter.allowedUpdates, - maxAllowedConnections, - filter.asUpdateReceiver -) diff --git a/gradle.properties b/gradle.properties index 6167792c3d..bd84d78e5d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,7 @@ kotlin.code.style=official org.gradle.parallel=true +kotlin.js.generate.externals=true + kotlin_version=1.4.0 kotlin_coroutines_version=1.3.9 kotlin_serialisation_runtime_version=1.0.0-RC