From a4e7fda416977ee46ac662431adf10a6e8415313 Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 14 Jun 2022 11:18:22 +0100 Subject: [PATCH] Raise deprecation level for 2.12 --- .../src/extension/ExtensionPoint.kt | 39 +------------------ .../src/util/CoroutineScopeUtils.kt | 30 +++++++------- .../android/api/android.api | 4 +- .../compatibility-validation/jvm/api/jvm.api | 4 +- .../commonMain/kotlin/contact/Exceptions.kt | 4 +- .../commonMain/kotlin/event/EventChannel.kt | 4 +- .../kotlin/event/deprecated.nextEvent.kt | 16 ++++---- .../kotlin/event/deprecated.nextEventAsync.kt | 16 ++++---- .../kotlin/event/deprecated.syncFromEvent.kt | 15 ++++--- .../kotlin/utils/BotConfiguration.kt | 34 ++++++---------- .../kotlin/utils/ExternalResource.kt | 14 ++++--- .../commonMain/kotlin/utils/LoginSolver.kt | 4 +- .../kotlin/contact/GroupSettingsImpl.kt | 4 +- .../network/components/ContactCacheService.kt | 15 ++++++- .../network/impl/netty/NettyNetworkHandler.kt | 1 + .../commonMain/kotlin/utils/RemoteFileImpl.kt | 20 ++++++++++ .../commonTest/kotlin/event/NextEventTest.kt | 9 +++-- 17 files changed, 110 insertions(+), 123 deletions(-) diff --git a/mirai-console/backend/mirai-console/src/extension/ExtensionPoint.kt b/mirai-console/backend/mirai-console/src/extension/ExtensionPoint.kt index 381164338..7db1a27f1 100644 --- a/mirai-console/backend/mirai-console/src/extension/ExtensionPoint.kt +++ b/mirai-console/backend/mirai-console/src/extension/ExtensionPoint.kt @@ -61,44 +61,7 @@ public abstract class AbstractInstanceExtensionPoint, T @ConsoleExperimentalApi public constructor( extensionType: KClass -) : AbstractExtensionPoint(extensionType) { - - /** - * @since 2.10 - */ - @Deprecated( - "Default(builtin) implementations are not allowed any more. " + - "For plugin authors, provide them with lower priority when plugin being loaded(through the ComponentScope). " + - "For frontend implementers, provide them by `BackendAccess.globalComponentScope.contribute`. ", - replaceWith = ReplaceWith("AbstractInstanceExtensionPoint(extensionType)"), - level = DeprecationLevel.ERROR, - ) - @DeprecatedSinceMirai(errorSince = "2.11") // for removal - @ConsoleExperimentalApi - public constructor( - extensionType: KClass, - /** - * 内建的实现列表. - */ - @Suppress("UNUSED_PARAMETER") builtinImplementations: () -> E, - ) : this(extensionType) - - /** - * @since 2.0 - */ - @Deprecated( - "Default(builtin) implementations are not allowed any more. " + - "For plugin authors, provide them with lower priority when plugin being loaded(through the ComponentScope). " + - "For frontend implementers, provide them by `BackendAccess.globalComponentScope.contribute`. ", - replaceWith = ReplaceWith("AbstractInstanceExtensionPoint(extensionType)"), - level = DeprecationLevel.ERROR - ) - @DeprecatedSinceMirai(errorSince = "2.11") // for removal - @ConsoleExperimentalApi // was experimental since 2.0 - public constructor(extensionType: KClass, @Suppress("UNUSED_PARAMETER") vararg builtinImplementations: E) : this( - extensionType, - ) -} +) : AbstractExtensionPoint(extensionType) @Deprecated( "Please use AbstractInstanceExtensionPoint instead.", diff --git a/mirai-console/backend/mirai-console/src/util/CoroutineScopeUtils.kt b/mirai-console/backend/mirai-console/src/util/CoroutineScopeUtils.kt index 485ac8509..8a5989ad3 100644 --- a/mirai-console/backend/mirai-console/src/util/CoroutineScopeUtils.kt +++ b/mirai-console/backend/mirai-console/src/util/CoroutineScopeUtils.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.console.util @@ -18,20 +18,20 @@ import net.mamoe.mirai.utils.currentTimeMillis import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext -@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith") -@Deprecated("No longer supported, deprecated for removal.") -@DeprecatedSinceMirai(warningSince = "2.10.0-RC") +@Suppress("DEPRECATION", "DEPRECATION_ERROR", "DeprecatedCallableAddReplaceWith") +@Deprecated("No longer supported, deprecated for removal.", level = DeprecationLevel.ERROR) +@DeprecatedSinceMirai(warningSince = "2.10.0-RC", errorSince = "2.12") @ConsoleExperimentalApi public object CoroutineScopeUtils { - @Deprecated("No longer supported, deprecated for removal.") - @DeprecatedSinceMirai(warningSince = "2.10.0-RC") + @Deprecated("No longer supported, deprecated for removal.", level = DeprecationLevel.ERROR) + @DeprecatedSinceMirai(warningSince = "2.10.0-RC", errorSince = "2.12") @JvmStatic @ConsoleExperimentalApi public fun CoroutineContext.overrideWithSupervisorJob(name: String? = null): CoroutineContext = this + NamedSupervisorJob(name ?: "", this[Job]) - @Deprecated("No longer supported, deprecated for removal.") - @DeprecatedSinceMirai(warningSince = "2.10.0-RC") + @Deprecated("No longer supported, deprecated for removal.", level = DeprecationLevel.ERROR) + @DeprecatedSinceMirai(warningSince = "2.10.0-RC", errorSince = "2.12") @JvmStatic @ConsoleExperimentalApi public fun CoroutineScope.childScope( @@ -40,8 +40,8 @@ public object CoroutineScopeUtils { ): CoroutineScope = CoroutineScope(this.childScopeContext(name, context)) - @Deprecated("No longer supported, deprecated for removal.") - @DeprecatedSinceMirai(warningSince = "2.10.0-RC") + @Deprecated("No longer supported, deprecated for removal.", level = DeprecationLevel.ERROR) + @DeprecatedSinceMirai(warningSince = "2.10.0-RC", errorSince = "2.12") @JvmStatic @ConsoleExperimentalApi public fun CoroutineScope.childScopeContext( @@ -100,8 +100,8 @@ internal fun CoroutineScope.launchTimedTask( action: suspend CoroutineScope.() -> Unit, ) = TimedTask(this, coroutineContext, intervalMillis, action) -@Deprecated("No longer supported, deprecated for removal.") -@DeprecatedSinceMirai(warningSince = "2.10.0-RC") +@Deprecated("No longer supported, deprecated for removal.", level = DeprecationLevel.ERROR) +@DeprecatedSinceMirai(warningSince = "2.10.0-RC", errorSince = "2.12") @ConsoleExperimentalApi public class NamedSupervisorJob @JvmOverloads constructor( private val name: String, diff --git a/mirai-core-api/compatibility-validation/android/api/android.api b/mirai-core-api/compatibility-validation/android/api/android.api index ed569af4b..da33732d2 100644 --- a/mirai-core-api/compatibility-validation/android/api/android.api +++ b/mirai-core-api/compatibility-validation/android/api/android.api @@ -199,7 +199,7 @@ public final class net/mamoe/mirai/contact/AvatarSpec : java/lang/Enum, java/lan } public final class net/mamoe/mirai/contact/BotIsBeingMutedException : net/mamoe/mirai/contact/SendMessageFailedException { - public fun (Lnet/mamoe/mirai/contact/Group;)V + public synthetic fun (Lnet/mamoe/mirai/contact/Group;)V public fun getMessage ()Ljava/lang/String; public synthetic fun getTarget ()Lnet/mamoe/mirai/contact/Contact; public fun getTarget ()Lnet/mamoe/mirai/contact/Group; @@ -5733,7 +5733,6 @@ public class net/mamoe/mirai/utils/BotConfiguration { public final fun getHeartbeatStrategy ()Lnet/mamoe/mirai/utils/BotConfiguration$HeartbeatStrategy; public final fun getHeartbeatTimeoutMillis ()J public final fun getHighwayUploadCoroutineCount ()I - public final fun getJson ()Lkotlinx/serialization/json/Json; public final fun getLoginCacheEnabled ()Z public final fun getLoginSolver ()Lnet/mamoe/mirai/utils/LoginSolver; public final fun getNetworkLoggerSupplier ()Lkotlin/jvm/functions/Function1; @@ -5779,7 +5778,6 @@ public class net/mamoe/mirai/utils/BotConfiguration { public final fun setHeartbeatStrategy (Lnet/mamoe/mirai/utils/BotConfiguration$HeartbeatStrategy;)V public final fun setHeartbeatTimeoutMillis (J)V public final fun setHighwayUploadCoroutineCount (I)V - public final fun setJson (Lkotlinx/serialization/json/Json;)V public final fun setLoginCacheEnabled (Z)V public final fun setLoginSolver (Lnet/mamoe/mirai/utils/LoginSolver;)V public final fun setNetworkLoggerSupplier (Lkotlin/jvm/functions/Function1;)V diff --git a/mirai-core-api/compatibility-validation/jvm/api/jvm.api b/mirai-core-api/compatibility-validation/jvm/api/jvm.api index d75ec443f..128269dc1 100644 --- a/mirai-core-api/compatibility-validation/jvm/api/jvm.api +++ b/mirai-core-api/compatibility-validation/jvm/api/jvm.api @@ -199,7 +199,7 @@ public final class net/mamoe/mirai/contact/AvatarSpec : java/lang/Enum, java/lan } public final class net/mamoe/mirai/contact/BotIsBeingMutedException : net/mamoe/mirai/contact/SendMessageFailedException { - public fun (Lnet/mamoe/mirai/contact/Group;)V + public synthetic fun (Lnet/mamoe/mirai/contact/Group;)V public fun getMessage ()Ljava/lang/String; public synthetic fun getTarget ()Lnet/mamoe/mirai/contact/Contact; public fun getTarget ()Lnet/mamoe/mirai/contact/Group; @@ -5733,7 +5733,6 @@ public class net/mamoe/mirai/utils/BotConfiguration { public final fun getHeartbeatStrategy ()Lnet/mamoe/mirai/utils/BotConfiguration$HeartbeatStrategy; public final fun getHeartbeatTimeoutMillis ()J public final fun getHighwayUploadCoroutineCount ()I - public final fun getJson ()Lkotlinx/serialization/json/Json; public final fun getLoginCacheEnabled ()Z public final fun getLoginSolver ()Lnet/mamoe/mirai/utils/LoginSolver; public final fun getNetworkLoggerSupplier ()Lkotlin/jvm/functions/Function1; @@ -5779,7 +5778,6 @@ public class net/mamoe/mirai/utils/BotConfiguration { public final fun setHeartbeatStrategy (Lnet/mamoe/mirai/utils/BotConfiguration$HeartbeatStrategy;)V public final fun setHeartbeatTimeoutMillis (J)V public final fun setHighwayUploadCoroutineCount (I)V - public final fun setJson (Lkotlinx/serialization/json/Json;)V public final fun setLoginCacheEnabled (Z)V public final fun setLoginSolver (Lnet/mamoe/mirai/utils/LoginSolver;)V public final fun setNetworkLoggerSupplier (Lkotlin/jvm/functions/Function1;)V diff --git a/mirai-core-api/src/commonMain/kotlin/contact/Exceptions.kt b/mirai-core-api/src/commonMain/kotlin/contact/Exceptions.kt index 2e7891f9c..aff615cf0 100644 --- a/mirai-core-api/src/commonMain/kotlin/contact/Exceptions.kt +++ b/mirai-core-api/src/commonMain/kotlin/contact/Exceptions.kt @@ -48,10 +48,10 @@ public class BotIsBeingMutedException @MiraiInternalApi constructor( public override val target: Group, originalMessage: Message, ) : SendMessageFailedException(target, Reason.BOT_MUTED, originalMessage) { - @DeprecatedSinceMirai(warningSince = "2.9", errorSince = "2.11") + @DeprecatedSinceMirai(warningSince = "2.9", errorSince = "2.11", hiddenSince = "2.12") @Deprecated( "Deprecated without replacement. Please consider copy this exception to your code.", - level = DeprecationLevel.ERROR + level = DeprecationLevel.HIDDEN ) // this constructor is since 2.0 public constructor( diff --git a/mirai-core-api/src/commonMain/kotlin/event/EventChannel.kt b/mirai-core-api/src/commonMain/kotlin/event/EventChannel.kt index 396ac5fe5..5d52db850 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/EventChannel.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/EventChannel.kt @@ -101,9 +101,9 @@ public abstract class EventChannel @MiraiInternalApi publ "Channel(capacity).apply { forwardToChannel(this, coroutineContext, priority) }", "kotlinx.coroutines.channels.Channel" ), - level = DeprecationLevel.WARNING, + level = DeprecationLevel.ERROR, ) - @DeprecatedSinceMirai(warningSince = "2.10") + @DeprecatedSinceMirai(warningSince = "2.10", errorSince = "2.12") @MiraiExperimentalApi public fun asChannel( capacity: Int = Channel.RENDEZVOUS, diff --git a/mirai-core-api/src/commonMain/kotlin/event/deprecated.nextEvent.kt b/mirai-core-api/src/commonMain/kotlin/event/deprecated.nextEvent.kt index ca791d96c..11b21decc 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/deprecated.nextEvent.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/deprecated.nextEvent.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 */ @file:Suppress("unused", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") @@ -37,7 +37,7 @@ import kotlin.reflect.KClass * @throws TimeoutCancellationException 在超时后抛出. */ @JvmSynthetic -@DeprecatedSinceMirai(warningSince = "2.10") +@DeprecatedSinceMirai(warningSince = "2.10", errorSince = "2.12") @Deprecated( "Use GlobalEventChannel.nextEvent", ReplaceWith( @@ -45,7 +45,7 @@ import kotlin.reflect.KClass "net.mamoe.mirai.event.GlobalEventChannel", "kotlinx.coroutines.withTimeout", ), - level = DeprecationLevel.WARNING + level = DeprecationLevel.ERROR ) public suspend inline fun nextEvent( timeoutMillis: Long = -1, @@ -74,7 +74,7 @@ public suspend inline fun nextEvent( * @return 事件实例, 在超时后返回 `null` */ @JvmSynthetic -@DeprecatedSinceMirai(warningSince = "2.10") +@DeprecatedSinceMirai(warningSince = "2.10", errorSince = "2.12") @Deprecated( "Use GlobalEventChannel.nextEvent", ReplaceWith( @@ -84,7 +84,7 @@ public suspend inline fun nextEvent( "net.mamoe.mirai.event.GlobalEventChannel", "net.mamoe.mirai.event.nextEvent" ), - level = DeprecationLevel.WARNING + level = DeprecationLevel.ERROR ) public suspend inline fun nextEventOrNull( timeoutMillis: Long, diff --git a/mirai-core-api/src/commonMain/kotlin/event/deprecated.nextEventAsync.kt b/mirai-core-api/src/commonMain/kotlin/event/deprecated.nextEventAsync.kt index 6781f5896..afb522632 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/deprecated.nextEventAsync.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/deprecated.nextEventAsync.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 */ @file:Suppress("unused", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") @@ -52,9 +52,9 @@ import kotlin.coroutines.EmptyCoroutineContext "net.mamoe.mirai.event.GlobalEventChannel", "net.mamoe.mirai.event.nextEvent" ), - level = DeprecationLevel.WARNING + level = DeprecationLevel.ERROR ) -@DeprecatedSinceMirai(warningSince = "2.10") +@DeprecatedSinceMirai(warningSince = "2.10", errorSince = "2.12") @MiraiExperimentalApi public inline fun CoroutineScope.nextEventAsync( timeoutMillis: Long = -1, @@ -106,9 +106,9 @@ public inline fun CoroutineScope.nextEventAsync( "net.mamoe.mirai.event.GlobalEventChannel", "net.mamoe.mirai.event.nextEvent" ), - level = DeprecationLevel.WARNING + level = DeprecationLevel.ERROR ) -@DeprecatedSinceMirai(warningSince = "2.10") +@DeprecatedSinceMirai(warningSince = "2.10", errorSince = "2.12") @JvmSynthetic public inline fun CoroutineScope.nextEventOrNullAsync( timeoutMillis: Long, diff --git a/mirai-core-api/src/commonMain/kotlin/event/deprecated.syncFromEvent.kt b/mirai-core-api/src/commonMain/kotlin/event/deprecated.syncFromEvent.kt index 5b2abe61b..dcbd18927 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/deprecated.syncFromEvent.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/deprecated.syncFromEvent.kt @@ -33,7 +33,7 @@ import kotlin.reflect.KClass * @throws TimeoutCancellationException 在超时后抛出. * @throws Throwable 当 [mapper] 抛出任何异常时, 本函数会抛出该异常 */ -@DeprecatedSinceMirai(warningSince = "2.10") +@DeprecatedSinceMirai(warningSince = "2.10", errorSince = "2.12") @Deprecated( "Use GlobalEventChannel.syncFromEvent", ReplaceWith( @@ -42,7 +42,7 @@ import kotlin.reflect.KClass "net.mamoe.mirai.event.GlobalEventChannel", "net.mamoe.mirai.event.syncFromEvent" ), - level = DeprecationLevel.WARNING + level = DeprecationLevel.ERROR ) @JvmSynthetic public suspend inline fun syncFromEvent( @@ -79,11 +79,11 @@ public suspend inline fun syncFromEvent( * @throws Throwable 当 [mapper] 抛出任何异常时, 本函数会抛出该异常 */ @JvmSynthetic -@DeprecatedSinceMirai(warningSince = "2.10") +@DeprecatedSinceMirai(warningSince = "2.10", errorSince = "2.12") @Deprecated( "Use GlobalEventChannel.syncFromEvent", ReplaceWith("withTimeoutOrNull(timeoutMillis) { GlobalEventChannel.syncFromEvent(priority) { event -> with(event) { mapper(event) } }"), - level = DeprecationLevel.WARNING + level = DeprecationLevel.ERROR ) public suspend inline fun syncFromEventOrNull( timeoutMillis: Long, @@ -125,8 +125,10 @@ public suspend inline fun syncFromEventOrNull( "net.mamoe.mirai.event.globalEventChannel", "net.mamoe.mirai.event.syncFromEvent" ), + level = DeprecationLevel.ERROR ) @JvmSynthetic +@DeprecatedSinceMirai(warningSince = "2.10", errorSince = "2.12") @Suppress("DeferredIsResult") public inline fun CoroutineScope.asyncFromEventOrNull( timeoutMillis: Long, @@ -175,8 +177,9 @@ public inline fun CoroutineScope.asyncFromEventOrNu "net.mamoe.mirai.event.globalEventChannel", "net.mamoe.mirai.event.syncFromEvent" ), + level = DeprecationLevel.ERROR ) -@DeprecatedSinceMirai("2.10") +@DeprecatedSinceMirai(warningSince = "2.10", errorSince = "2.12") @JvmSynthetic @Suppress("DeferredIsResult") public inline fun CoroutineScope.asyncFromEvent( @@ -201,7 +204,7 @@ public inline fun CoroutineScope.asyncFromEvent( ////////////// @Deprecated("Deprecated since its usages are deprecated") -@DeprecatedSinceMirai("2.10") +@DeprecatedSinceMirai(warningSince = "2.10") @JvmSynthetic @PublishedApi internal suspend inline fun syncFromEventImpl( diff --git a/mirai-core-api/src/commonMain/kotlin/utils/BotConfiguration.kt b/mirai-core-api/src/commonMain/kotlin/utils/BotConfiguration.kt index 87b5a776d..9acdd9e39 100644 --- a/mirai-core-api/src/commonMain/kotlin/utils/BotConfiguration.kt +++ b/mirai-core-api/src/commonMain/kotlin/utils/BotConfiguration.kt @@ -59,26 +59,6 @@ public open class BotConfiguration { // open for Java */ public var workingDir: File = File(".") - /** - * Json 序列化器, 使用 'kotlinx.serialization' - */ - @MiraiExperimentalApi - @Deprecated( - "Changing serial format is going to be forbidden. Deprecated for removal. ", - level = DeprecationLevel.ERROR - ) - @DeprecatedSinceMirai(errorSince = "2.11") // was experimental - public var json: Json = kotlin.runCatching { - Json { - isLenient = true - ignoreUnknownKeys = true - prettyPrint = true - } - }.getOrElse { - @Suppress("JSON_FORMAT_REDUNDANT_DEFAULT") // compatible for older versions - Json {} - } - /////////////////////////////////////////////////////////////////////////// // Coroutines /////////////////////////////////////////////////////////////////////////// @@ -340,7 +320,7 @@ public open class BotConfiguration { // open for Java @ConfigurationDsl public fun loadDeviceInfoJson(json: String) { deviceInfo = { - this.json.decodeFromString(DeviceInfo.serializer(), json) + Companion.json.decodeFromString(DeviceInfo.serializer(), json) } } @@ -602,7 +582,6 @@ public open class BotConfiguration { // open for Java // To structural order new.workingDir = workingDir @Suppress("DEPRECATION_ERROR") - new.json = json new.parentCoroutineContext = parentCoroutineContext new.heartbeatPeriodMillis = heartbeatPeriodMillis new.heartbeatTimeoutMillis = heartbeatTimeoutMillis @@ -644,6 +623,17 @@ public open class BotConfiguration { // open for Java /** 默认的配置实例. 可以进行修改 */ @JvmStatic public val Default: BotConfiguration = BotConfiguration() + + internal val json: Json = kotlin.runCatching { + Json { + isLenient = true + ignoreUnknownKeys = true + prettyPrint = true + } + }.getOrElse { + @Suppress("JSON_FORMAT_REDUNDANT_DEFAULT") // compatibility for older versions + Json {} + } } } diff --git a/mirai-core-api/src/commonMain/kotlin/utils/ExternalResource.kt b/mirai-core-api/src/commonMain/kotlin/utils/ExternalResource.kt index 3bfe51003..50ded4b29 100644 --- a/mirai-core-api/src/commonMain/kotlin/utils/ExternalResource.kt +++ b/mirai-core-api/src/commonMain/kotlin/utils/ExternalResource.kt @@ -26,7 +26,6 @@ import net.mamoe.mirai.message.MessageReceipt import net.mamoe.mirai.message.data.FileMessage import net.mamoe.mirai.message.data.Image import net.mamoe.mirai.message.data.sendTo -import net.mamoe.mirai.message.data.toVoice import net.mamoe.mirai.utils.AbstractExternalResource.ResourceCleanCallback import net.mamoe.mirai.utils.ExternalResource.Companion.sendAsImageTo import net.mamoe.mirai.utils.ExternalResource.Companion.toExternalResource @@ -547,12 +546,13 @@ public interface ExternalResource : Closeable { @Suppress("DEPRECATION_ERROR", "DEPRECATION") @Deprecated( "Deprecated. Please use AbsoluteFolder.uploadNewFile", - ReplaceWith("contact.files.uploadNewFile(path, this, callback)") + ReplaceWith("contact.files.uploadNewFile(path, this, callback)"), + level = DeprecationLevel.ERROR, ) // deprecated since 2.8.0-RC @JvmStatic @JvmBlockingBridge @JvmOverloads - @DeprecatedSinceMirai(warningSince = "2.8") + @DeprecatedSinceMirai(warningSince = "2.8", errorSince = "2.12") public suspend fun File.sendTo( contact: C, path: String, @@ -574,13 +574,14 @@ public interface ExternalResource : Closeable { @Suppress("DEPRECATION", "DEPRECATION_ERROR") @Deprecated( "Deprecated. Please use AbsoluteFolder.uploadNewFile", - ReplaceWith("contact.files.uploadNewFile(path, this, callback)") + ReplaceWith("contact.files.uploadNewFile(path, this, callback)"), + level = DeprecationLevel.ERROR, ) // deprecated since 2.8.0-RC @JvmStatic @JvmBlockingBridge @JvmName("sendAsFile") @JvmOverloads - @DeprecatedSinceMirai(warningSince = "2.8") + @DeprecatedSinceMirai(warningSince = "2.8", errorSince = "2.12") public suspend fun ExternalResource.sendAsFileTo( contact: C, path: String, @@ -605,7 +606,8 @@ public interface ExternalResource : Closeable { @DeprecatedSinceMirai(warningSince = "2.7", errorSince = "2.10", hiddenSince = "2.11") public suspend fun ExternalResource.uploadAsVoice(contact: Contact): net.mamoe.mirai.message.data.Voice { @Suppress("DEPRECATION", "DEPRECATION_ERROR") - if (contact is Group) return contact.uploadAudio(this).toVoice() + if (contact is Group) return contact.uploadAudio(this) + .let { net.mamoe.mirai.message.data.Voice.fromAudio(it) } else throw UnsupportedOperationException("Contact `$contact` is not supported uploading voice") } // endregion diff --git a/mirai-core-api/src/commonMain/kotlin/utils/LoginSolver.kt b/mirai-core-api/src/commonMain/kotlin/utils/LoginSolver.kt index a3c09cc39..b4d69cf66 100644 --- a/mirai-core-api/src/commonMain/kotlin/utils/LoginSolver.kt +++ b/mirai-core-api/src/commonMain/kotlin/utils/LoginSolver.kt @@ -82,9 +82,9 @@ public expect abstract class LoginSolver() { } -internal fun BotConfiguration.getFileBasedDeviceInfoSupplier(file: () -> File): (Bot) -> DeviceInfo { +internal fun getFileBasedDeviceInfoSupplier(file: () -> File): (Bot) -> DeviceInfo { return { @Suppress("DEPRECATION_ERROR") - file().loadAsDeviceInfo(json) + file().loadAsDeviceInfo(BotConfiguration.json) } } \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/contact/GroupSettingsImpl.kt b/mirai-core/src/commonMain/kotlin/contact/GroupSettingsImpl.kt index 49bf1fd80..7fc1dc797 100644 --- a/mirai-core/src/commonMain/kotlin/contact/GroupSettingsImpl.kt +++ b/mirai-core/src/commonMain/kotlin/contact/GroupSettingsImpl.kt @@ -17,7 +17,6 @@ import net.mamoe.mirai.data.GroupInfo import net.mamoe.mirai.event.Event import net.mamoe.mirai.event.broadcast import net.mamoe.mirai.event.events.GroupAllowMemberInviteEvent -import net.mamoe.mirai.event.events.GroupEntranceAnnouncementChangeEvent import net.mamoe.mirai.event.events.GroupMuteAllEvent import net.mamoe.mirai.event.events.GroupNameChangeEvent import net.mamoe.mirai.internal.network.QQAndroidClient @@ -65,7 +64,8 @@ internal class GroupSettingsImpl( get() = _entranceAnnouncement set(newValue) { group.setImpl(newValue, { _entranceAnnouncement }, { _entranceAnnouncement = it }, GroupOperation::memo) { - GroupEntranceAnnouncementChangeEvent(it, newValue, group, null) + @Suppress("DEPRECATION") + net.mamoe.mirai.event.events.GroupEntranceAnnouncementChangeEvent(it, newValue, group, null) } } diff --git a/mirai-core/src/commonMain/kotlin/network/components/ContactCacheService.kt b/mirai-core/src/commonMain/kotlin/network/components/ContactCacheService.kt index bdd36af34..4b3bda0b1 100644 --- a/mirai-core/src/commonMain/kotlin/network/components/ContactCacheService.kt +++ b/mirai-core/src/commonMain/kotlin/network/components/ContactCacheService.kt @@ -9,6 +9,7 @@ package net.mamoe.mirai.internal.network.components +import kotlinx.serialization.json.Json import net.mamoe.mirai.internal.QQAndroidBot import net.mamoe.mirai.internal.network.FriendListCache import net.mamoe.mirai.internal.network.GroupMemberListCaches @@ -43,8 +44,18 @@ internal class ContactCacheServiceImpl( // contact cache /////////////////////////////////////////////////////////////////////////// - @Suppress("DEPRECATION_ERROR") - inline val json get() = configuration.json + companion object { + internal val json: Json = kotlin.runCatching { + Json { + isLenient = true + ignoreUnknownKeys = true + prettyPrint = true + } + }.getOrElse { + @Suppress("JSON_FORMAT_REDUNDANT_DEFAULT") // compatibility for older versions + (Json {}) + } + } override val friendListCache: FriendListCache? by lazy { if (!configuration.contactListCache.friendListCacheEnabled) return@lazy null diff --git a/mirai-core/src/commonMain/kotlin/network/impl/netty/NettyNetworkHandler.kt b/mirai-core/src/commonMain/kotlin/network/impl/netty/NettyNetworkHandler.kt index bca7c378d..d4aa8b9f7 100644 --- a/mirai-core/src/commonMain/kotlin/network/impl/netty/NettyNetworkHandler.kt +++ b/mirai-core/src/commonMain/kotlin/network/impl/netty/NettyNetworkHandler.kt @@ -118,6 +118,7 @@ internal open class NettyNetworkHandler( protected open fun setupChannelPipeline(pipeline: ChannelPipeline, decodePipeline: PacketDecodePipeline) { pipeline .addLast(object : ChannelInboundHandlerAdapter() { + @Suppress("OVERRIDE_DEPRECATION") override fun exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable) { handlePipelineException(ctx, cause) } diff --git a/mirai-core/src/commonMain/kotlin/utils/RemoteFileImpl.kt b/mirai-core/src/commonMain/kotlin/utils/RemoteFileImpl.kt index bbc1d1b07..01a5b0005 100644 --- a/mirai-core/src/commonMain/kotlin/utils/RemoteFileImpl.kt +++ b/mirai-core/src/commonMain/kotlin/utils/RemoteFileImpl.kt @@ -557,6 +557,11 @@ internal class RemoteFileImpl( ) } + @Deprecated( + "Use uploadAndSend instead.", + replaceWith = ReplaceWith("this.uploadAndSend(resource, callback)"), + level = DeprecationLevel.ERROR + ) override suspend fun upload( resource: ExternalResource, callback: RemoteFile.ProgressionCallback?, @@ -567,17 +572,32 @@ internal class RemoteFileImpl( } // compiler bug + @Deprecated( + "Use uploadAndSend instead.", + replaceWith = ReplaceWith("this.uploadAndSend(resource)"), + level = DeprecationLevel.ERROR + ) @Suppress("DEPRECATION_ERROR") override suspend fun upload(resource: ExternalResource): FileMessage { return upload(resource, null) } // compiler bug + @Deprecated( + "Use uploadAndSend instead.", + replaceWith = ReplaceWith("this.uploadAndSend(file, callback)"), + level = DeprecationLevel.ERROR + ) @Suppress("DEPRECATION_ERROR") override suspend fun upload(file: File, callback: RemoteFile.ProgressionCallback?): FileMessage = file.toExternalResource().use { upload(it, callback) } //compiler bug + @Deprecated( + "Use sendFile instead.", + replaceWith = ReplaceWith("this.uploadAndSend(file)"), + level = DeprecationLevel.ERROR + ) @Suppress("DEPRECATION_ERROR") override suspend fun upload(file: File): FileMessage { // Dear compiler: diff --git a/mirai-core/src/commonTest/kotlin/event/NextEventTest.kt b/mirai-core/src/commonTest/kotlin/event/NextEventTest.kt index d79ca444a..ec1214283 100644 --- a/mirai-core/src/commonTest/kotlin/event/NextEventTest.kt +++ b/mirai-core/src/commonTest/kotlin/event/NextEventTest.kt @@ -139,7 +139,7 @@ internal class NextEventTest : AbstractEventTest() { suspend fun `nextEventOrNull can receive`() { withContext(dispatcher) { val deferred = async(start = CoroutineStart.UNDISPATCHED) { - nextEventOrNull(5000) + withTimeoutOrNull(5000) { globalEventChannel().nextEvent(EventPriority.MONITOR) } } TE(1).broadcast() @@ -153,7 +153,7 @@ internal class NextEventTest : AbstractEventTest() { suspend fun `nextEventOrNull can filter type`() { withContext(dispatcher) { val deferred = async(start = CoroutineStart.UNDISPATCHED) { - nextEventOrNull(5000) + withTimeoutOrNull(5000) { globalEventChannel().nextEvent(EventPriority.MONITOR) } } TE2(1).broadcast() @@ -171,7 +171,7 @@ internal class NextEventTest : AbstractEventTest() { suspend fun `nextEventOrNull can filter by filter`() { withContext(dispatcher) { val deferred = async(start = CoroutineStart.UNDISPATCHED) { - nextEventOrNull(5000) { it.x == 2 } + withTimeoutOrNull(5000) { globalEventChannel().nextEvent(EventPriority.MONITOR) { it.x == 2 } } } TE(1).broadcast() @@ -188,7 +188,8 @@ internal class NextEventTest : AbstractEventTest() { @Test suspend fun `nextEventOrNull can timeout`() { withContext(dispatcher) { - assertEquals(null, nextEventOrNull(timeoutMillis = 1)) + assertEquals(null, + withTimeoutOrNull(timeMillis = 1) { globalEventChannel().nextEvent(EventPriority.MONITOR) }) } } } \ No newline at end of file