From d1cb05025e90d2313103a575713a3fcdfe058ca2 Mon Sep 17 00:00:00 2001 From: Him188 Date: Wed, 13 Apr 2022 12:08:39 +0100 Subject: [PATCH] Deprecated IMirai.Http for future removal --- mirai-core-api/src/commonMain/kotlin/IMirai.kt | 9 ++++----- .../jvmMain/kotlin/utils/LoginSolver.TxCaptchaHelper.kt | 9 +++++---- mirai-core/src/commonMain/kotlin/MiraiImpl.kt | 8 ++++++-- mirai-core/src/commonMain/kotlin/contact/AbstractUser.kt | 4 +++- mirai-core/src/commonMain/kotlin/contact/FriendImpl.kt | 3 ++- mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt | 1 + .../network/components/EcdhInitialPublicKeyUpdater.kt | 9 +++++---- 7 files changed, 26 insertions(+), 17 deletions(-) diff --git a/mirai-core-api/src/commonMain/kotlin/IMirai.kt b/mirai-core-api/src/commonMain/kotlin/IMirai.kt index 109d5e6e0..211478569 100644 --- a/mirai-core-api/src/commonMain/kotlin/IMirai.kt +++ b/mirai-core-api/src/commonMain/kotlin/IMirai.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2022 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. @@ -30,10 +30,7 @@ import net.mamoe.mirai.message.action.Nudge import net.mamoe.mirai.message.data.* import net.mamoe.mirai.message.data.Image.Key.queryUrl import net.mamoe.mirai.message.data.MessageSource.Key.recall -import net.mamoe.mirai.utils.FileCacheStrategy -import net.mamoe.mirai.utils.MiraiExperimentalApi -import net.mamoe.mirai.utils.MiraiInternalApi -import net.mamoe.mirai.utils.NotStableForInheritance +import net.mamoe.mirai.utils.* /** * [IMirai] 实例. @@ -100,6 +97,8 @@ public interface IMirai : LowLevelApiAccessor { * * 覆盖后将会立即应用到全局. */ + @Deprecated("Mirai is not going to use ktor. This is deprecated for removal.", level = DeprecationLevel.WARNING) + @DeprecatedSinceMirai(warningSince = "2.11.0") public var Http: HttpClient /** diff --git a/mirai-core-api/src/jvmMain/kotlin/utils/LoginSolver.TxCaptchaHelper.kt b/mirai-core-api/src/jvmMain/kotlin/utils/LoginSolver.TxCaptchaHelper.kt index 93fe26ed4..c30d80971 100644 --- a/mirai-core-api/src/jvmMain/kotlin/utils/LoginSolver.TxCaptchaHelper.kt +++ b/mirai-core-api/src/jvmMain/kotlin/utils/LoginSolver.TxCaptchaHelper.kt @@ -1,10 +1,10 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2022 Mamoe Technologies and contributors. * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. * - * https://github.com/mamoe/mirai/blob/master/LICENSE + * https://github.com/mamoe/mirai/blob/dev/LICENSE */ package net.mamoe.mirai.utils @@ -22,6 +22,7 @@ internal abstract class TxCaptchaHelper { init { var newClient = false client = try { + @Suppress("DEPRECATION", "DEPRECATION_ERROR") Mirai.Http } catch (ignore: Throwable) { newClient = true diff --git a/mirai-core/src/commonMain/kotlin/MiraiImpl.kt b/mirai-core/src/commonMain/kotlin/MiraiImpl.kt index 1a2116078..bcd964b6a 100644 --- a/mirai-core/src/commonMain/kotlin/MiraiImpl.kt +++ b/mirai-core/src/commonMain/kotlin/MiraiImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2022 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. @@ -57,7 +57,6 @@ import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect import net.mamoe.mirai.internal.network.protocol.packet.summarycard.SummaryCard import net.mamoe.mirai.internal.network.psKey import net.mamoe.mirai.internal.network.sKey -import net.mamoe.mirai.internal.utils.ImagePatcher import net.mamoe.mirai.internal.utils.MiraiProtocolInternal import net.mamoe.mirai.internal.utils.crypto.TEA import net.mamoe.mirai.internal.utils.io.serialization.loadAs @@ -145,6 +144,7 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor { override var FileCacheStrategy: FileCacheStrategy = net.mamoe.mirai.utils.FileCacheStrategy.PlatformDefault + @Deprecated("Mirai is not going to use ktor. This is deprecated for removal.", level = DeprecationLevel.WARNING) override var Http: HttpClient = HttpClient(OkHttp) { install(HttpTimeout) { this.requestTimeoutMillis = 30_0000 @@ -579,6 +579,7 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor { override suspend fun getRawGroupActiveData(bot: Bot, groupId: Long, page: Int): GroupActiveData = bot.asQQAndroidBot().run { val rep = network.run { + @Suppress("DEPRECATION", "DEPRECATION_ERROR") Mirai.Http.get { url("https://qqweb.qq.com/c/activedata/get_mygroup_data") parameter("bkn", client.wLoginSigInfo.bkn) @@ -606,6 +607,7 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor { type: GroupHonorType ): GroupHonorListData? = bot.asQQAndroidBot().run { val rep = network.run { + @Suppress("DEPRECATION", "DEPRECATION_ERROR") Mirai.Http.get { url("https://qun.qq.com/interactive/honorlist") parameter("gc", groupId) @@ -735,6 +737,7 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor { seconds: Int ) { bot as QQAndroidBot + @Suppress("DEPRECATION", "DEPRECATION_ERROR") val response = Mirai.Http.post { url("https://qqweb.qq.com/c/anonymoustalk/blacklist") body = MultiPartFormDataContent(formData { @@ -883,6 +886,7 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor { bot.asQQAndroidBot() when (val resp = MultiMsg.ApplyDown(bot.client, 2, resourceId, 1).sendAndExpect(bot)) { is MultiMsg.ApplyDown.Response.RequireDownload -> { + @Suppress("DEPRECATION", "DEPRECATION_ERROR") val http = Mirai.Http val origin = resp.origin diff --git a/mirai-core/src/commonMain/kotlin/contact/AbstractUser.kt b/mirai-core/src/commonMain/kotlin/contact/AbstractUser.kt index 9b15fc7d6..c5d5cfcac 100644 --- a/mirai-core/src/commonMain/kotlin/contact/AbstractUser.kt +++ b/mirai-core/src/commonMain/kotlin/contact/AbstractUser.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2022 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. @@ -195,6 +195,7 @@ internal sealed class AbstractUser( resourceKind = PRIVATE_IMAGE, channelKind = ChannelKind.HTTP ) { ip, port -> + @Suppress("DEPRECATION", "DEPRECATION_ERROR") Mirai.Http.postImage( serverIp = ip, serverPort = port, htcmd = "0x6ff0070", @@ -206,6 +207,7 @@ internal sealed class AbstractUser( } }.recoverCatchingSuppressed { // try upload by http on fallback server + @Suppress("DEPRECATION", "DEPRECATION_ERROR") Mirai.Http.postImage( serverIp = "htdata2.qq.com", htcmd = "0x6ff0070", diff --git a/mirai-core/src/commonMain/kotlin/contact/FriendImpl.kt b/mirai-core/src/commonMain/kotlin/contact/FriendImpl.kt index 89dce8ba8..d2a2859fa 100644 --- a/mirai-core/src/commonMain/kotlin/contact/FriendImpl.kt +++ b/mirai-core/src/commonMain/kotlin/contact/FriendImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2022 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. @@ -129,6 +129,7 @@ internal class FriendImpl( ResourceKind.GROUP_AUDIO, ChannelKind.HTTP ) { ip, port -> + @Suppress("DEPRECATION", "DEPRECATION_ERROR") Mirai.Http.postPtt(ip, port, res, resp.uKey, resp.fileKey) } audio = OfflineAudioImpl( diff --git a/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt b/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt index 3aef35c34..7d387073f 100644 --- a/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt +++ b/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt @@ -321,6 +321,7 @@ internal class GroupImpl constructor( GROUP_AUDIO, ChannelKind.HTTP ) { ip, port -> + @Suppress("DEPRECATION", "DEPRECATION_ERROR") Mirai.Http.postPtt(ip, port, resource, resp.uKey, resp.fileKey) } } diff --git a/mirai-core/src/commonMain/kotlin/network/components/EcdhInitialPublicKeyUpdater.kt b/mirai-core/src/commonMain/kotlin/network/components/EcdhInitialPublicKeyUpdater.kt index 4664f0c88..065565618 100644 --- a/mirai-core/src/commonMain/kotlin/network/components/EcdhInitialPublicKeyUpdater.kt +++ b/mirai-core/src/commonMain/kotlin/network/components/EcdhInitialPublicKeyUpdater.kt @@ -1,10 +1,10 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2022 Mamoe Technologies and contributors. * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. * - * https://github.com/mamoe/mirai/blob/master/LICENSE + * https://github.com/mamoe/mirai/blob/dev/LICENSE */ package net.mamoe.mirai.internal.network.components @@ -87,6 +87,7 @@ internal class EcdhInitialPublicKeyUpdaterImpl( } else { logger.info("ECDH key is invalid, start to fetch ecdh public key from server.") val respStr = + @Suppress("DEPRECATION", "DEPRECATION_ERROR") Mirai.Http.get("https://keyrotate.qq.com/rotate_key?cipher_suite_ver=305&uin=${bot.client.uin}") val resp = json.decodeFromString(ServerRespPOJO.serializer(), respStr) resp.pubKeyMeta.let { meta ->