From 363d1f7ece068c3deb3c503bb29a632d2c4102a6 Mon Sep 17 00:00:00 2001 From: Him188 Date: Thu, 4 May 2023 15:03:44 +0100 Subject: [PATCH] Remove module-level opt-ins, add `@OptIn` explicit in use-sites; added some opt-in markers on API which should have: - `appendMiraiCodeTo` Made API stable (otherwise they require too heavy opt-ins): - MiraiConsoleImplementation$ConsoleLaunchOptions - LowLevelApi --- buildSrc/src/main/kotlin/ProjectConfigure.kt | 34 +++++----- .../src/IntegrationTestBootstrap.kt | 6 +- .../backend/integration-test/src/utils.kt | 4 +- .../backend/mirai-console/build.gradle.kts | 5 ++ .../compatibility-validation/jvm/api/jvm.api | 10 ++- .../backend/mirai-console/src/MiraiConsole.kt | 12 ++-- .../src/MiraiConsoleImplementation.kt | 20 ++++-- .../src/command/BuiltInCommands.kt | 28 +++++++- .../mirai-console/src/command/Command.kt | 11 ++-- .../src/command/CommandExecuteResult.kt | 6 +- .../src/command/CommandManager.kt | 13 +++- .../mirai-console/src/command/CommandOwner.kt | 4 +- .../src/command/CommandSender.kt | 6 +- .../src/command/SimpleCommand.kt | 3 +- .../descriptor/CommandArgumentContext.kt | 4 +- .../command/descriptor/CommandParameter.kt | 7 +- .../command/descriptor/CommandSignature.kt | 6 +- .../ExperimentalCommandDescriptors.kt | 4 +- .../src/command/parse/CommandCallParser.kt | 4 +- .../command/resolve/ResolvedCommandCall.kt | 3 +- .../src/data/AbstractPluginData.kt | 2 + .../src/data/AutoSavePluginData.kt | 19 ++++-- .../mirai-console/src/data/PluginData.kt | 5 +- .../src/data/PluginDataExtensions.kt | 17 +++-- .../src/data/ReadOnlyPluginData.kt | 3 +- .../backend/mirai-console/src/data/Value.kt | 3 +- .../src/data/java/JavaAutoSavePluginData.kt | 4 +- .../CommandCallInterceptorProvider.kt | 4 +- .../extensions/CommandCallParserProvider.kt | 4 +- .../extensions/CommandCallResolverProvider.kt | 4 +- .../extensions/PermissionServiceProvider.kt | 4 +- .../extensions/SingletonExtensionSelector.kt | 4 +- .../MiraiConsoleImplementationBridge.kt | 14 ++-- .../internal/auth/ConsoleBotAuthorization.kt | 2 + .../internal/command/CommandManagerImpl.kt | 12 ++-- .../src/internal/command/CommandReflector.kt | 4 +- .../command/builtin/LoginCommandImpl.kt | 8 ++- .../src/internal/data/CompositeValueImpl.kt | 10 +-- .../data/MemoryPluginDataStorageImpl.kt | 5 +- .../data/MultiFilePluginDataStorageImpl.kt | 4 +- .../src/internal/data/PluginDataImpl.kt | 10 +-- .../src/internal/data/_PluginData.value.kt | 5 +- .../data/_PrimitiveValueDeclarations.kt | 5 +- .../data/builtins/ConsoleDataScopeImpl.kt | 6 +- .../internal/data/builtins/LoggerConfig.kt | 5 +- .../src/internal/data/serializerHelper.kt | 7 +- .../src/internal/data/valueFromKTypeImpl.kt | 4 +- .../extension/ComponentStorageInternal.kt | 6 +- .../SingletonExtensionSelectorImpl.kt | 4 +- .../internal/logging/LoggerControllerImpl.kt | 7 +- .../internal/logging/MiraiConsoleLogger.kt | 5 +- .../slf4j/MiraiConsoleSLF4JService.kt | 6 +- .../permission/BuiltInPermissionServices.kt | 5 +- .../plugin/BuiltInJvmPluginLoaderImpl.kt | 11 ++-- .../src/internal/plugin/ExportManagerImpl.kt | 5 +- .../internal/plugin/JvmPluginClassLoader.kt | 5 +- .../plugin/JvmPluginDependencyDownload.kt | 5 +- .../src/internal/plugin/JvmPluginInternal.kt | 7 +- .../src/internal/shutdown/ShutdownDaemon.kt | 5 +- .../src/internal/util/ConsoleInputImpl.kt | 5 +- .../src/internal/util/PluginServiceHelper.kt | 4 +- .../src/permission/PermissionService.kt | 7 +- .../src/permission/PermitteeId.kt | 3 +- .../src/plugin/jvm/AbstractJvmPlugin.kt | 3 +- .../src/plugin/jvm/JvmPluginLoader.kt | 12 +++- .../src/util/AnsiMessageBuilder.kt | 6 +- .../mirai-console/src/util/MessageScope.kt | 6 +- ...tractMiraiConsoleFrontendImplementation.kt | 18 ++++- .../mirai-console-terminal/build.gradle.kts | 5 ++ .../src/ConsoleTerminalSettings.kt | 14 ++-- .../src/ConsoleThread.kt | 10 +-- .../src/JLineInputDaemon.kt | 5 +- .../src/MiraiConsoleTerminalLoader.kt | 16 +++-- .../android/api/android.api | 7 +- .../compatibility-validation/jvm/api/jvm.api | 7 +- .../src/commonMain/kotlin/IMirai.kt | 3 +- .../commonMain/kotlin/LowLevelApiAccessor.kt | 8 ++- .../kotlin/auth/BotAuthorization.kt | 1 + .../commonMain/kotlin/contact/ContactList.kt | 29 ++++++-- .../commonMain/kotlin/contact/ContactOrBot.kt | 8 ++- .../commonMain/kotlin/contact/Exceptions.kt | 6 +- .../src/commonMain/kotlin/contact/Group.kt | 20 +++--- .../commonMain/kotlin/contact/OtherClient.kt | 8 ++- .../kotlin/data/RequestEventData.kt | 12 +++- .../commonMain/kotlin/data/StrangerInfo.kt | 4 +- .../src/commonMain/kotlin/data/UserInfo.kt | 2 +- .../src/commonMain/kotlin/event/Event.kt | 8 ++- .../commonMain/kotlin/event/EventChannel.kt | 3 +- .../kotlin/event/GlobalEventChannel.kt | 3 +- .../kotlin/event/MessageSelectBuilderUnit.kt | 4 +- .../kotlin/event/events/ImageUploadEvent.kt | 2 + .../kotlin/event/events/MessageEvent.kt | 14 ++-- .../event/events/MessagePostSendEvent.kt | 2 + .../event/events/MessagePreSendEvent.kt | 2 + .../kotlin/event/events/MessageRecallEvent.kt | 10 ++- .../kotlin/event/events/MessageSyncEvent.kt | 13 ++-- .../kotlin/event/events/NudgeEvent.kt | 1 + .../kotlin/event/events/SignEvent.kt | 5 +- .../src/commonMain/kotlin/event/events/bot.kt | 10 ++- .../commonMain/kotlin/event/events/friend.kt | 6 +- .../commonMain/kotlin/event/events/group.kt | 4 +- .../kotlin/event/events/stranger.kt | 10 +-- .../commonMain/kotlin/event/events/types.kt | 3 +- .../message/AbstractPolymorphicSerializer.kt | 7 +- .../message/MessageSerializersImpl.kt | 13 ++-- .../kotlin/internal/utils/StdoutLogger.kt | 1 + .../kotlin/message/code/CodableMessage.kt | 7 +- .../kotlin/message/code/MiraiCode.kt | 8 ++- .../kotlin/message/code/internal/impl.kt | 11 ++-- .../kotlin/message/data/CustomMessage.kt | 14 ++-- .../kotlin/message/data/FileMessage.kt | 9 +-- .../kotlin/message/data/FlashImage.kt | 3 +- .../kotlin/message/data/ForwardMessage.kt | 5 +- .../commonMain/kotlin/message/data/Image.kt | 66 +++++++++++-------- .../kotlin/message/data/MarketFace.kt | 4 +- .../commonMain/kotlin/message/data/Message.kt | 14 ++-- .../kotlin/message/data/MessageSource.kt | 8 ++- .../kotlin/message/data/MusicShare.kt | 2 + .../kotlin/message/data/PokeMessage.kt | 4 +- .../kotlin/message/data/RichMessage.kt | 4 +- .../commonMain/kotlin/message/data/VipFace.kt | 7 +- .../commonMain/kotlin/message/data/Voice.kt | 21 +++--- .../commonMain/kotlin/message/data/impl.kt | 5 +- .../message/data/visitor/MessageVisitor.kt | 5 +- .../commonMain/kotlin/spi/SPIServiceLoader.kt | 3 +- .../kotlin/utils/BotConfiguration.kt | 2 +- .../src/commonMain/kotlin/utils/DeviceInfo.kt | 19 +++--- .../kotlin/utils/ExternalResource.kt | 3 +- .../commonMain/kotlin/utils/MiraiLogger.kt | 3 +- .../jvmBaseMain/kotlin/event/EventChannel.kt | 17 +++-- .../kotlin/event/MessageSelectBuilderUnit.kt | 4 +- .../internal/utils/ExternalResourceImpls.kt | 5 +- .../kotlin/message/data/FileMessage.kt | 9 +-- .../kotlin/spi/SPIServiceLoader.kt | 5 +- .../kotlin/utils/AbstractExternalResource.kt | 3 +- .../jvmBaseMain/kotlin/utils/MiraiLogger.kt | 7 +- .../jvmMain/kotlin/utils/LoginSolver.jvm.kt | 12 +++- .../kotlin/utils/PlatformLogger.jvm.kt | 15 +++-- .../kotlin/utils/SingleFileLogger.jvm.kt | 9 +-- .../nativeMain/kotlin/event/EventChannel.kt | 12 ++-- .../kotlin/event/MessageSelectBuilderUnit.kt | 4 +- .../utils/ExternalResourceImplByByteArray.kt | 3 +- .../kotlin/message/data/FileMessage.kt | 6 +- .../nativeMain/kotlin/spi/SPIServiceLoader.kt | 5 +- .../nativeMain/kotlin/utils/MiraiLogger.kt | 4 +- mirai-core-mock/build.gradle.kts | 3 + mirai-core-mock/src/MockActions.kt | 8 ++- .../src/internal/msgsrc/OnlineMsgSrc.kt | 4 +- mirai-core-mock/src/utils/NudgeDsl.kt | 4 +- .../src/commonMain/kotlin/Bytes.kt | 8 +-- .../src/commonMain/kotlin/Conversions.kt | 3 +- mirai-core-utils/src/commonMain/kotlin/IO.kt | 20 +++--- .../src/commonMain/kotlin/Serialization.kt | 7 +- .../src/commonMain/kotlin/TlvMap.kt | 8 +-- .../StructureToStringTransformerLegacy.kt | 26 ++------ mirai-core/build.gradle.kts | 5 ++ .../src/commonMain/kotlin/AbstractBot.kt | 7 +- .../kotlin/event/EventChannelImpl.kt | 4 +- .../protocol/impl/FileMessageProtocol.kt | 4 +- .../message/protocol/impl/TextProtocol.kt | 4 +- .../kotlin/network/components/PacketCodec.kt | 10 +-- .../network/notice/decoders/MsgInfoDecoder.kt | 4 +- .../group/GroupNotificationProcessor.kt | 14 ++-- .../group/GroupOrMemberListNoticeProcessor.kt | 26 ++++---- .../notice/priv/FriendNoticeProcessor.kt | 25 +++---- .../network/protocol/packet/login/WtLogin.kt | 34 +++++----- .../packet/login/wtlogin/WtLoginExt.kt | 6 +- .../src/commonMain/kotlin/utils/io/output.kt | 10 +-- .../serialization/tars/internal/TarsInput.kt | 12 ++-- .../nativeMain/kotlin/contact/GroupImpl.kt | 4 +- mirai-dokka/src/system.kt | 5 +- 171 files changed, 892 insertions(+), 505 deletions(-) diff --git a/buildSrc/src/main/kotlin/ProjectConfigure.kt b/buildSrc/src/main/kotlin/ProjectConfigure.kt index 489fa72a1..474a1aac2 100644 --- a/buildSrc/src/main/kotlin/ProjectConfigure.kt +++ b/buildSrc/src/main/kotlin/ProjectConfigure.kt @@ -32,9 +32,19 @@ private fun Project.jvmVersion(): JavaVersion { } } -fun Project.optInForAllTargets(qualifiedClassname: String) { - tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinCompile::class) { - kotlinOptions.freeCompilerArgs += "-Xopt-in=$qualifiedClassname" +fun Project.optInForAllSourceSets(qualifiedClassname: String) { + kotlinSourceSets!!.all { + languageSettings { + optIn(qualifiedClassname) + } + } +} + +fun Project.optInForTestSourceSets(qualifiedClassname: String) { + kotlinSourceSets!!.matching { it.name.contains("test", ignoreCase = true) }.all { + languageSettings { + optIn(qualifiedClassname) + } } } @@ -167,26 +177,16 @@ val testExperimentalAnnotations = arrayOf( "io.ktor.util.KtorExperimentalAPI", "kotlin.io.path.ExperimentalPathApi", "kotlinx.coroutines.ExperimentalCoroutinesApi", + "kotlinx.serialization.ExperimentalSerializationApi", + "net.mamoe.mirai.utils.TestOnly", + "net.mamoe.mirai.utils.MiraiInternalApi", + "net.mamoe.mirai.utils.MiraiExperimentalApi", ) val experimentalAnnotations = arrayOf( - "kotlin.RequiresOptIn", "kotlin.contracts.ExperimentalContracts", "kotlin.experimental.ExperimentalTypeInference", - "kotlin.ExperimentalUnsignedTypes", - - "kotlinx.serialization.ExperimentalSerializationApi", - - "net.mamoe.mirai.utils.MiraiInternalApi", - "net.mamoe.mirai.utils.MiraiExperimentalApi", - "net.mamoe.mirai.LowLevelApi", - - "net.mamoe.mirai.console.ConsoleFrontEndImplementation", - "net.mamoe.mirai.console.util.ConsoleInternalApi", - "net.mamoe.mirai.console.util.ConsoleExperimentalApi", - - "io.ktor.utils.io.core.internal.DangerousInternalIoApi" ) val testLanguageFeatures = listOf( diff --git a/mirai-console/backend/integration-test/src/IntegrationTestBootstrap.kt b/mirai-console/backend/integration-test/src/IntegrationTestBootstrap.kt index 0a3832172..b86a212c0 100644 --- a/mirai-console/backend/integration-test/src/IntegrationTestBootstrap.kt +++ b/mirai-console/backend/integration-test/src/IntegrationTestBootstrap.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -8,6 +8,7 @@ */ @file:JvmName("IntegrationTestBootstrap") +@file:OptIn(ConsoleFrontEndImplementation::class, ConsoleExperimentalApi::class, ConsoleInternalApi::class) package net.mamoe.console.integrationtest @@ -15,10 +16,13 @@ import kotlinx.coroutines.cancelAndJoin import kotlinx.coroutines.runBlocking import net.mamoe.console.integrationtest.AbstractTestPoint.Companion.internalBCS import net.mamoe.console.integrationtest.AbstractTestPoint.Companion.internalOSS +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsole import net.mamoe.mirai.console.terminal.ConsoleTerminalExperimentalApi import net.mamoe.mirai.console.terminal.ConsoleTerminalSettings import net.mamoe.mirai.console.terminal.MiraiConsoleTerminalLoader +import net.mamoe.mirai.console.util.ConsoleExperimentalApi +import net.mamoe.mirai.console.util.ConsoleInternalApi import net.mamoe.mirai.utils.cast import net.mamoe.mirai.utils.sha1 import net.mamoe.mirai.utils.toUHexString diff --git a/mirai-console/backend/integration-test/src/utils.kt b/mirai-console/backend/integration-test/src/utils.kt index 6e0909b1c..48ead853f 100644 --- a/mirai-console/backend/integration-test/src/utils.kt +++ b/mirai-console/backend/integration-test/src/utils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -10,6 +10,7 @@ package net.mamoe.console.integrationtest import net.mamoe.mirai.console.internal.plugin.ConsoleJvmPluginTestFailedError +import net.mamoe.mirai.utils.MiraiInternalApi import org.junit.jupiter.api.fail import org.objectweb.asm.ClassReader import org.objectweb.asm.ClassWriter @@ -54,6 +55,7 @@ public fun assertClassSame(expected: Class<*>?, actually: Class<*>?) { } } +@OptIn(MiraiInternalApi::class) public fun forceFail( msg: String? = null, cause: Throwable? = null, diff --git a/mirai-console/backend/mirai-console/build.gradle.kts b/mirai-console/backend/mirai-console/build.gradle.kts index 55baa189a..6598fcbeb 100644 --- a/mirai-console/backend/mirai-console/build.gradle.kts +++ b/mirai-console/backend/mirai-console/build.gradle.kts @@ -29,6 +29,11 @@ description = "Mirai Console Backend" kotlin { explicitApiWarning() + optInForAllSourceSets("kotlinx.serialization.ExperimentalSerializationApi") + + optInForTestSourceSets("net.mamoe.mirai.console.ConsoleFrontEndImplementation") + optInForTestSourceSets("net.mamoe.mirai.console.ConsoleExperimentalApi") + optInForTestSourceSets("net.mamoe.mirai.console.ConsoleInternalApi") } diff --git a/mirai-console/backend/mirai-console/compatibility-validation/jvm/api/jvm.api b/mirai-console/backend/mirai-console/compatibility-validation/jvm/api/jvm.api index 3fc767b38..4e6fc79ca 100644 --- a/mirai-console/backend/mirai-console/compatibility-validation/jvm/api/jvm.api +++ b/mirai-console/backend/mirai-console/compatibility-validation/jvm/api/jvm.api @@ -42,6 +42,11 @@ public abstract interface class net/mamoe/mirai/console/MiraiConsoleFrontEndDesc public fun render ()Ljava/lang/String; } +public final class net/mamoe/mirai/console/MiraiConsoleImplementation$ConsoleLaunchOptions { + public field crashWhenPluginLoadFailed Z + public fun ()V +} + public final class net/mamoe/mirai/console/MiraiConsoleKt { public static final fun getRootDir (Lnet/mamoe/mirai/console/MiraiConsole;)Ljava/io/File; } @@ -105,13 +110,10 @@ public final class net/mamoe/mirai/console/command/BuiltInCommands { public final class net/mamoe/mirai/console/command/BuiltInCommands$AutoLoginCommand : net/mamoe/mirai/console/command/CompositeCommand, net/mamoe/mirai/console/command/BuiltInCommandInternal { public static final field INSTANCE Lnet/mamoe/mirai/console/command/BuiltInCommands$AutoLoginCommand; - public final fun add (Lnet/mamoe/mirai/console/command/CommandSender;JLjava/lang/String;Lnet/mamoe/mirai/console/internal/data/builtins/AutoLoginConfig$Account$PasswordKind;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun add$default (Lnet/mamoe/mirai/console/command/BuiltInCommands$AutoLoginCommand;Lnet/mamoe/mirai/console/command/CommandSender;JLjava/lang/String;Lnet/mamoe/mirai/console/internal/data/builtins/AutoLoginConfig$Account$PasswordKind;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public final fun clear (Lnet/mamoe/mirai/console/command/CommandSender;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun list (Lnet/mamoe/mirai/console/command/CommandSender;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun remove (Lnet/mamoe/mirai/console/command/CommandSender;JLkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun removeConfig (Lnet/mamoe/mirai/console/command/CommandSender;JLnet/mamoe/mirai/console/internal/data/builtins/AutoLoginConfig$Account$ConfigurationKey;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun setConfig (Lnet/mamoe/mirai/console/command/CommandSender;JLnet/mamoe/mirai/console/internal/data/builtins/AutoLoginConfig$Account$ConfigurationKey;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } public final class net/mamoe/mirai/console/command/BuiltInCommands$HelpCommand : net/mamoe/mirai/console/command/SimpleCommand, net/mamoe/mirai/console/command/BuiltInCommandInternal { @@ -2157,6 +2159,7 @@ public class net/mamoe/mirai/console/util/AnsiMessageBuilder : java/io/Serializa public fun gray ()Lnet/mamoe/mirai/console/util/AnsiMessageBuilder; public fun green ()Lnet/mamoe/mirai/console/util/AnsiMessageBuilder; public fun hashCode ()I + public static final fun isAnsiSupported (Lnet/mamoe/mirai/console/command/CommandSender;)Z public fun lightBlue ()Lnet/mamoe/mirai/console/util/AnsiMessageBuilder; public fun lightCyan ()Lnet/mamoe/mirai/console/util/AnsiMessageBuilder; public fun lightGreen ()Lnet/mamoe/mirai/console/util/AnsiMessageBuilder; @@ -2180,6 +2183,7 @@ public final class net/mamoe/mirai/console/util/AnsiMessageBuilder$Companion { public final fun from (Ljava/lang/StringBuilder;)Lnet/mamoe/mirai/console/util/AnsiMessageBuilder; public final fun from (Ljava/lang/StringBuilder;Z)Lnet/mamoe/mirai/console/util/AnsiMessageBuilder; public static synthetic fun from$default (Lnet/mamoe/mirai/console/util/AnsiMessageBuilder$Companion;Ljava/lang/StringBuilder;ZILjava/lang/Object;)Lnet/mamoe/mirai/console/util/AnsiMessageBuilder; + public final fun isAnsiSupported (Lnet/mamoe/mirai/console/command/CommandSender;)Z } public final class net/mamoe/mirai/console/util/AnsiMessageBuilderKt { diff --git a/mirai-console/backend/mirai-console/src/MiraiConsole.kt b/mirai-console/backend/mirai-console/src/MiraiConsole.kt index 5dc6ab70d..4d81a849e 100644 --- a/mirai-console/backend/mirai-console/src/MiraiConsole.kt +++ b/mirai-console/backend/mirai-console/src/MiraiConsole.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -159,7 +159,10 @@ public interface MiraiConsole : CoroutineScope { * * 对象以 [bridge][MiraiConsoleImplementationBridge] 实现, 将会桥接特定前端实现的 [MiraiConsoleImplementation] 到 [MiraiConsole]. */ - public companion object INSTANCE : MiraiConsole by dynamicDelegation({ MiraiConsoleImplementation.getBridge() }) { + public companion object INSTANCE : MiraiConsole by dynamicDelegation({ + @OptIn(ConsoleFrontEndImplementation::class) + MiraiConsoleImplementation.getBridge() + }) { /** * 获取 [MiraiConsole] 的 [Job] */ // MiraiConsole.INSTANCE.getJob() @@ -207,7 +210,7 @@ public interface MiraiConsole : CoroutineScope { configuration: BotConfiguration.() -> Unit = {} ): Bot = addBotImpl(id, authorization, configuration) - @Suppress("UNREACHABLE_CODE") + @OptIn(ConsoleFrontEndImplementation::class) private fun addBotImpl(id: Long, authorization: Any, configuration: BotConfiguration.() -> Unit = {}): Bot { when (authorization) { is String -> {} @@ -285,7 +288,7 @@ public interface MiraiConsole : CoroutineScope { public fun shutdown() { val consoleJob = job if (!consoleJob.isActive) return - @OptIn(DelicateCoroutinesApi::class) + @OptIn(DelicateCoroutinesApi::class, ConsoleFrontEndImplementation::class) GlobalScope.launch { MiraiConsoleImplementation.shutdown() } @@ -307,6 +310,7 @@ public interface MiraiConsole : CoroutineScope { @ConsoleExperimentalApi @JvmStatic public fun newProcessProgress(): ProcessProgress { + @OptIn(ConsoleFrontEndImplementation::class) return MiraiConsoleImplementation.getInstance().createNewProcessProgress() } } diff --git a/mirai-console/backend/mirai-console/src/MiraiConsoleImplementation.kt b/mirai-console/backend/mirai-console/src/MiraiConsoleImplementation.kt index 40c59c7e7..751a3884a 100644 --- a/mirai-console/backend/mirai-console/src/MiraiConsoleImplementation.kt +++ b/mirai-console/backend/mirai-console/src/MiraiConsoleImplementation.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -37,6 +37,7 @@ import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.console.util.ConsoleInput +import net.mamoe.mirai.console.util.ConsoleInternalApi import net.mamoe.mirai.message.data.Message import net.mamoe.mirai.utils.* import java.nio.file.Path @@ -171,9 +172,16 @@ public interface MiraiConsoleImplementation : CoroutineScope { */ public val commandManager: CommandManager + @ConsoleExperimentalApi public val dataStorageForJvmPluginLoader: PluginDataStorage + + @ConsoleExperimentalApi public val configStorageForJvmPluginLoader: PluginDataStorage + + @ConsoleExperimentalApi public val dataStorageForBuiltIns: PluginDataStorage + + @ConsoleExperimentalApi public val configStorageForBuiltIns: PluginDataStorage /** @@ -227,6 +235,7 @@ public interface MiraiConsoleImplementation : CoroutineScope { /** * 前端预先定义的 [LoggerController], 以允许前端使用自己的配置系统 */ + @ConsoleExperimentalApi public val loggerController: LoggerController get() = LoggerControllerImpl() /////////////////////////////////////////////////////////////////////////// @@ -259,7 +268,10 @@ public interface MiraiConsoleImplementation : CoroutineScope { @ConsoleFrontEndImplementation @NotStableForInheritance public interface ConsoleDataScope { + @ConsoleExperimentalApi public val dataHolder: AutoSavePluginDataHolder + + @ConsoleExperimentalApi public val configHolder: AutoSavePluginDataHolder public fun addAndReloadConfig(config: PluginConfig) @@ -291,6 +303,7 @@ public interface MiraiConsoleImplementation : CoroutineScope { */ public inline fun ConsoleDataScope.get(): T = get(T::class) + @ConsoleExperimentalApi @JvmStatic public fun createDefault( coroutineContext: CoroutineContext, @@ -412,13 +425,11 @@ public interface MiraiConsoleImplementation : CoroutineScope { * Console 启动参数, 修改参数会改变默认行为 * @since 2.10.0-RC */ - @ConsoleExperimentalApi public class ConsoleLaunchOptions { @JvmField public var crashWhenPluginLoadFailed: Boolean = false } - @ConsoleExperimentalApi public val consoleLaunchOptions: ConsoleLaunchOptions get() = ConsoleLaunchOptions() @@ -453,7 +464,7 @@ public interface MiraiConsoleImplementation : CoroutineScope { runBlocking { shutdown() } - } catch (_ : InterruptedException) { + } catch (_: InterruptedException) { } } @@ -483,6 +494,7 @@ public interface MiraiConsoleImplementation : CoroutineScope { currentBridge ?: throw UninitializedPropertyAccessException() /** 由前端调用, 初始化 [MiraiConsole] 实例并启动 */ + @OptIn(ConsoleInternalApi::class) @JvmStatic @ConsoleFrontEndImplementation @Throws(MalformedMiraiConsoleImplementationError::class) diff --git a/mirai-console/backend/mirai-console/src/command/BuiltInCommands.kt b/mirai-console/backend/mirai-console/src/command/BuiltInCommands.kt index 0ec538bb4..6ced703ce 100644 --- a/mirai-console/backend/mirai-console/src/command/BuiltInCommands.kt +++ b/mirai-console/backend/mirai-console/src/command/BuiltInCommands.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,6 +7,8 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleFrontEndImplementation::class) + package net.mamoe.mirai.console.command import kotlinx.coroutines.DelicateCoroutinesApi @@ -15,6 +17,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import net.mamoe.mirai.Bot +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsole import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.MiraiConsoleImplementation.ConsoleDataScope.Companion.get @@ -51,6 +54,7 @@ import net.mamoe.mirai.console.plugin.version import net.mamoe.mirai.console.util.* import net.mamoe.mirai.event.events.EventCancelledException import net.mamoe.mirai.utils.BotConfiguration +import net.mamoe.mirai.utils.MiraiExperimentalApi import java.lang.management.ManagementFactory import java.lang.management.MemoryMXBean import java.lang.management.MemoryUsage @@ -64,6 +68,7 @@ import kotlin.system.exitProcess public interface BuiltInCommand : Command // for identification +@OptIn(ConsoleExperimentalApi::class) internal interface BuiltInCommandInternal : Command, BuiltInCommand /** @@ -126,7 +131,10 @@ public object BuiltInCommands { private val closingLock = Mutex() - @OptIn(DelicateCoroutinesApi::class) + @OptIn( + DelicateCoroutinesApi::class, ConsoleFrontEndImplementation::class, ConsoleExperimentalApi::class, + ConsoleInternalApi::class + ) @Handler public suspend fun CommandSender.handle() { GlobalScope.launch { @@ -162,6 +170,7 @@ public object BuiltInCommands { description = "登出一个账号", ), BuiltInCommandInternal { + @OptIn(ConsoleExperimentalApi::class) @Handler public suspend fun CommandSender.handle( @Name("qq") id: Long @@ -181,6 +190,7 @@ public object BuiltInCommands { description = loginCommandInstance.description, ), BuiltInCommandInternal { + @OptIn(ConsoleExperimentalApi::class) @Handler @JvmOverloads public suspend fun CommandSender.handle( @@ -237,6 +247,7 @@ public object BuiltInCommands { } + @OptIn(ConsoleExperimentalApi::class) @Description("授权一个权限") @SubCommand("permit", "grant", "add") public suspend fun CommandSender.permit( @@ -247,6 +258,7 @@ public object BuiltInCommands { sendMessage("OK") } + @OptIn(ConsoleExperimentalApi::class) @Description("撤销一个权限") @SubCommand("cancel", "deny", "remove") public suspend fun CommandSender.cancel( @@ -257,6 +269,7 @@ public object BuiltInCommands { sendMessage("OK") } + @OptIn(ConsoleExperimentalApi::class) @Description("撤销一个权限及其所有子权限") @SubCommand("cancelAll", "denyAll", "removeAll") public suspend fun CommandSender.cancelAll( @@ -267,6 +280,7 @@ public object BuiltInCommands { sendMessage("OK") } + @OptIn(ConsoleExperimentalApi::class) @Description("查看被授权权限列表") @SubCommand("permittedPermissions", "pp", "grantedPermissions", "gp") public suspend fun CommandSender.permittedPermissions( @@ -423,11 +437,13 @@ public object BuiltInCommands { ConsoleCommandOwner, "autoLogin", "自动登录", description = "自动登录设置", overrideContext = buildCommandArgumentContext { + @OptIn(ConsoleExperimentalApi::class) ConfigurationKey::class with ConfigurationKey.Parser } ), BuiltInCommandInternal { @Description("查看自动登录账号列表") @SubCommand + @OptIn(ConsoleExperimentalApi::class) public suspend fun CommandSender.list() { val config = DataScope.get() sendMessage(buildString { @@ -454,6 +470,7 @@ public object BuiltInCommands { @Description("添加自动登录, passwordKind 可选 PLAIN 或 MD5") @SubCommand + @ConsoleExperimentalApi public suspend fun CommandSender.add(account: Long, password: String, passwordKind: PasswordKind = PLAIN) { val config = DataScope.get() val accountStr = account.toString() @@ -465,6 +482,7 @@ public object BuiltInCommands { sendMessage("已成功添加 '$account'.") } + @OptIn(ConsoleExperimentalApi::class) @Description("清除所有配置") @SubCommand public suspend fun CommandSender.clear() { @@ -473,6 +491,7 @@ public object BuiltInCommands { sendMessage("已清除所有自动登录配置.") } + @OptIn(ConsoleExperimentalApi::class) @Description("删除一个账号") @SubCommand public suspend fun CommandSender.remove(account: Long) { @@ -485,6 +504,7 @@ public object BuiltInCommands { sendMessage("账号 '$account' 未配置自动登录.") } + @ConsoleExperimentalApi @Description("设置一个账号的一个配置项") @SubCommand public suspend fun CommandSender.setConfig(account: Long, configKey: ConfigurationKey, value: String) { @@ -509,6 +529,7 @@ public object BuiltInCommands { } @Description("删除一个账号的一个配置项") + @ConsoleExperimentalApi @SubCommand public suspend fun CommandSender.removeConfig(account: Long, configKey: ConfigurationKey) { val config = DataScope.get() @@ -583,6 +604,7 @@ public object BuiltInCommands { val max: Long, ) + @OptIn(MiraiExperimentalApi::class) @Handler public suspend fun CommandSender.handle() { sendAnsiMessage { @@ -668,9 +690,11 @@ public object BuiltInCommands { v < e50 -> { green() } + v < e90 -> { lightRed() } + else -> { red() } diff --git a/mirai-console/backend/mirai-console/src/command/Command.kt b/mirai-console/backend/mirai-console/src/command/Command.kt index 143106a53..e906d6a74 100644 --- a/mirai-console/backend/mirai-console/src/command/Command.kt +++ b/mirai-console/backend/mirai-console/src/command/Command.kt @@ -1,10 +1,10 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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("NOTHING_TO_INLINE", "MemberVisibilityCanBePrivate") @@ -19,7 +19,6 @@ import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.COMMAND_NAME import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.RESTRICTED_CONSOLE_COMMAND_OWNER import net.mamoe.mirai.console.permission.Permission import net.mamoe.mirai.console.permission.PermissionId -import net.mamoe.mirai.console.util.ConsoleExperimentalApi /** * 指令 @@ -54,7 +53,6 @@ public interface Command { /** * 指令可能的参数列表. */ - @ConsoleExperimentalApi("Property name is experimental") @ExperimentalCommandDescriptors public val overloads: List<@JvmWildcard CommandSignature> @@ -86,7 +84,6 @@ public interface Command { * 由于指令解析允许被扩展, 此属性可能不适用所有解析器, 因此还未决定是否保留. */ @ExperimentalCommandDescriptors - @ConsoleExperimentalApi public val prefixOptional: Boolean /** diff --git a/mirai-console/backend/mirai-console/src/command/CommandExecuteResult.kt b/mirai-console/backend/mirai-console/src/command/CommandExecuteResult.kt index 188bb8bb0..acb70caf5 100644 --- a/mirai-console/backend/mirai-console/src/command/CommandExecuteResult.kt +++ b/mirai-console/backend/mirai-console/src/command/CommandExecuteResult.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -16,7 +16,6 @@ import net.mamoe.mirai.console.command.parse.CommandCall import net.mamoe.mirai.console.command.parse.CommandValueArgument import net.mamoe.mirai.console.command.resolve.InterceptedReason import net.mamoe.mirai.console.command.resolve.ResolvedCommandCall -import net.mamoe.mirai.console.util.ConsoleExperimentalApi import kotlin.contracts.contract /** @@ -129,7 +128,6 @@ public sealed class CommandExecuteResult { public override val call: CommandCall, /** 尝试执行的指令 */ @ExperimentalCommandDescriptors - @ConsoleExperimentalApi public val failureReasons: List, ) : Failure() { /** 指令执行时发生的错误, 总是 `null` */ @@ -141,14 +139,12 @@ public sealed class CommandExecuteResult { } @ExperimentalCommandDescriptors -@ConsoleExperimentalApi public class UnmatchedCommandSignature( public val signature: CommandSignature, public val failureReason: FailureReason, ) @ExperimentalCommandDescriptors -@ConsoleExperimentalApi public sealed class FailureReason { public class InapplicableReceiverArgument( public override val parameter: CommandReceiverParameter<*>, diff --git a/mirai-console/backend/mirai-console/src/command/CommandManager.kt b/mirai-console/backend/mirai-console/src/command/CommandManager.kt index ea57ba55a..07b04b906 100644 --- a/mirai-console/backend/mirai-console/src/command/CommandManager.kt +++ b/mirai-console/backend/mirai-console/src/command/CommandManager.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -17,6 +17,7 @@ package net.mamoe.mirai.console.command import me.him188.kotlin.dynamic.delegation.dynamicDelegation import me.him188.kotlin.jvm.blocking.bridge.JvmBlockingBridge +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.command.CommandManager.INSTANCE.executeCommand import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors @@ -173,8 +174,12 @@ public interface CommandManager { /** * [CommandManager] 实例. 转发所有调用到 [MiraiConsoleImplementation.commandManager]. */ + public companion object INSTANCE : - CommandManager by (dynamicDelegation { MiraiConsoleImplementation.getInstance().commandManager }) { + CommandManager by (dynamicDelegation { + @OptIn(ConsoleFrontEndImplementation::class) + MiraiConsoleImplementation.getInstance().commandManager + }) { /** * @see CommandManager.getRegisteredCommands @@ -247,7 +252,9 @@ public suspend inline fun Command.execute( sender: CommandSender, vararg arguments: Message = emptyArray(), checkPermission: Boolean = true, -): CommandExecuteResult = CommandManager.executeCommand(sender, this, arguments.toMessageChain(), checkPermission) +): CommandExecuteResult = + @OptIn(ConsoleExperimentalApi::class) + CommandManager.executeCommand(sender, this, arguments.toMessageChain(), checkPermission) /** * 执行一个确切的指令 diff --git a/mirai-console/backend/mirai-console/src/command/CommandOwner.kt b/mirai-console/backend/mirai-console/src/command/CommandOwner.kt index 580ac42ad..fd251f5f9 100644 --- a/mirai-console/backend/mirai-console/src/command/CommandOwner.kt +++ b/mirai-console/backend/mirai-console/src/command/CommandOwner.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -15,6 +15,7 @@ import net.mamoe.mirai.console.permission.Permission import net.mamoe.mirai.console.permission.PermissionId import net.mamoe.mirai.console.permission.PermissionIdNamespace import net.mamoe.mirai.console.plugin.jvm.JvmPlugin +import net.mamoe.mirai.console.util.ConsoleExperimentalApi /** * 指令的所有者. [JvmPlugin] 是一个 [CommandOwner]. @@ -35,6 +36,7 @@ public interface CommandOwner : PermissionIdNamespace { * 插件注册指令时不应该使用 [ConsoleCommandOwner]. */ public object ConsoleCommandOwner : CommandOwner { + @OptIn(ConsoleExperimentalApi::class) public override val parentPermission: Permission get() = BuiltInCommands.parentPermission public override fun permissionId( diff --git a/mirai-console/backend/mirai-console/src/command/CommandSender.kt b/mirai-console/backend/mirai-console/src/command/CommandSender.kt index 5096e9e75..b059acc11 100644 --- a/mirai-console/backend/mirai-console/src/command/CommandSender.kt +++ b/mirai-console/backend/mirai-console/src/command/CommandSender.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -17,6 +17,7 @@ package net.mamoe.mirai.console.command import kotlinx.coroutines.CoroutineScope import me.him188.kotlin.jvm.blocking.bridge.JvmBlockingBridge import net.mamoe.mirai.Bot +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsole import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.command.CommandSender.Companion.asCommandSender @@ -390,15 +391,18 @@ public object ConsoleCommandSender : AbstractCommandSender(), SystemCommandSende public override val coroutineContext: CoroutineContext by lazy { MiraiConsole.childScopeContext(NAME) } + @OptIn(ConsoleFrontEndImplementation::class) override val isAnsiSupported: Boolean get() = MiraiConsoleImplementation.getInstance().isAnsiSupported + @OptIn(ConsoleFrontEndImplementation::class) @JvmBlockingBridge public override suspend fun sendMessage(message: Message): Nothing? { MiraiConsoleImplementation.getInstance().consoleCommandSender.sendMessage(message) return null } + @OptIn(ConsoleFrontEndImplementation::class) @JvmBlockingBridge public override suspend fun sendMessage(message: String): Nothing? { MiraiConsoleImplementation.getInstance().consoleCommandSender.sendMessage(message) diff --git a/mirai-console/backend/mirai-console/src/command/SimpleCommand.kt b/mirai-console/backend/mirai-console/src/command/SimpleCommand.kt index 7647143e7..f6a30b7ea 100644 --- a/mirai-console/backend/mirai-console/src/command/SimpleCommand.kt +++ b/mirai-console/backend/mirai-console/src/command/SimpleCommand.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -60,6 +60,7 @@ public abstract class SimpleCommand( private val reflector by lazy { CommandReflector(this, SimpleCommandSubCommandAnnotationResolver) } + @OptIn(ConsoleExperimentalApi::class) @ExperimentalCommandDescriptors public final override val overloads: List<@JvmWildcard CommandSignatureFromKFunction> by lazy { reflector.findSubCommands().also { diff --git a/mirai-console/backend/mirai-console/src/command/descriptor/CommandArgumentContext.kt b/mirai-console/backend/mirai-console/src/command/descriptor/CommandArgumentContext.kt index e441776c6..7b79e6ce4 100644 --- a/mirai-console/backend/mirai-console/src/command/descriptor/CommandArgumentContext.kt +++ b/mirai-console/backend/mirai-console/src/command/descriptor/CommandArgumentContext.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -23,6 +23,7 @@ import net.mamoe.mirai.contact.* import net.mamoe.mirai.message.data.Image import net.mamoe.mirai.message.data.MessageContent import net.mamoe.mirai.message.data.PlainText +import net.mamoe.mirai.utils.MiraiExperimentalApi import java.time.* import java.time.temporal.TemporalAccessor import java.util.* @@ -98,6 +99,7 @@ public interface CommandArgumentContext { private object TemporalCommandArgumentContext : CommandArgumentContext { private val cache = HashMap, CommandValueArgumentParser<*>>() + @OptIn(MiraiExperimentalApi::class) private fun put(kClass: KClass, now: () -> T, parse: (CharSequence) -> T) { cache[kClass] = TemporalArgumentParser(kClass.java, now, parse) } diff --git a/mirai-console/backend/mirai-console/src/command/descriptor/CommandParameter.kt b/mirai-console/backend/mirai-console/src/command/descriptor/CommandParameter.kt index be6c5dc83..9ee35729b 100644 --- a/mirai-console/backend/mirai-console/src/command/descriptor/CommandParameter.kt +++ b/mirai-console/backend/mirai-console/src/command/descriptor/CommandParameter.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -112,10 +112,12 @@ public sealed class ArgumentAcceptance( public object Impossible : ArgumentAcceptance(-1) public companion object { + @OptIn(ConsoleExperimentalApi::class) @JvmStatic public val ArgumentAcceptance.isAcceptable: Boolean get() = acceptanceLevel > 0 + @OptIn(ConsoleExperimentalApi::class) @JvmStatic public val ArgumentAcceptance.isNotAcceptable: Boolean get() = acceptanceLevel <= 0 @@ -123,8 +125,7 @@ public sealed class ArgumentAcceptance( } @ExperimentalCommandDescriptors -public sealed class CommandReceiverParameter( -) : CommandParameter, AbstractCommandParameter() { +public sealed class CommandReceiverParameter : CommandParameter, AbstractCommandParameter() { /** * @since 2.12 diff --git a/mirai-console/backend/mirai-console/src/command/descriptor/CommandSignature.kt b/mirai-console/backend/mirai-console/src/command/descriptor/CommandSignature.kt index 0a08ec62d..6b1e33b88 100644 --- a/mirai-console/backend/mirai-console/src/command/descriptor/CommandSignature.kt +++ b/mirai-console/backend/mirai-console/src/command/descriptor/CommandSignature.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -11,7 +11,6 @@ package net.mamoe.mirai.console.command.descriptor import net.mamoe.mirai.console.command.CommandSender import net.mamoe.mirai.console.command.resolve.ResolvedCommandCall -import net.mamoe.mirai.console.util.ConsoleExperimentalApi import kotlin.reflect.KFunction /** @@ -24,7 +23,6 @@ public interface CommandSignature { /** * 接收者参数, 为 [CommandSender] 子类 */ - @ConsoleExperimentalApi public val receiverParameter: CommandReceiverParameter<*>? /** @@ -43,7 +41,6 @@ public interface CommandSignature { * * @see CommandSignatureFromKFunctionImpl */ -@ConsoleExperimentalApi @ExperimentalCommandDescriptors public interface CommandSignatureFromKFunction : CommandSignature { public val originFunction: KFunction<*> @@ -76,7 +73,6 @@ public open class CommandSignatureImpl( } } -@ConsoleExperimentalApi @ExperimentalCommandDescriptors public open class CommandSignatureFromKFunctionImpl( override val receiverParameter: CommandReceiverParameter<*>?, diff --git a/mirai-console/backend/mirai-console/src/command/descriptor/ExperimentalCommandDescriptors.kt b/mirai-console/backend/mirai-console/src/command/descriptor/ExperimentalCommandDescriptors.kt index 1fe7ee2c6..c94a6ff49 100644 --- a/mirai-console/backend/mirai-console/src/command/descriptor/ExperimentalCommandDescriptors.kt +++ b/mirai-console/backend/mirai-console/src/command/descriptor/ExperimentalCommandDescriptors.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -9,7 +9,6 @@ package net.mamoe.mirai.console.command.descriptor -import net.mamoe.mirai.console.util.ConsoleExperimentalApi import kotlin.annotation.AnnotationTarget.* /** @@ -24,7 +23,6 @@ import kotlin.annotation.AnnotationTarget.* @RequiresOptIn(level = RequiresOptIn.Level.WARNING) @Target(CLASS, TYPEALIAS, FUNCTION, PROPERTY, FIELD, CONSTRUCTOR) @MustBeDocumented -@ConsoleExperimentalApi @ExperimentalCommandDescriptors public annotation class ExperimentalCommandDescriptors( val message: String = "Command descriptors are an experimental API.", diff --git a/mirai-console/backend/mirai-console/src/command/parse/CommandCallParser.kt b/mirai-console/backend/mirai-console/src/command/parse/CommandCallParser.kt index b7862a233..5389d677f 100644 --- a/mirai-console/backend/mirai-console/src/command/parse/CommandCallParser.kt +++ b/mirai-console/backend/mirai-console/src/command/parse/CommandCallParser.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -15,7 +15,6 @@ import net.mamoe.mirai.console.command.resolve.CommandCallResolver import net.mamoe.mirai.console.command.resolve.ResolvedCommandCall import net.mamoe.mirai.console.extensions.CommandCallParserProvider import net.mamoe.mirai.console.internal.extension.GlobalComponentStorage -import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.message.data.MessageChain /** @@ -26,7 +25,6 @@ import net.mamoe.mirai.message.data.MessageChain * * @see SpaceSeparatedCommandCallParser */ -@ConsoleExperimentalApi @ExperimentalCommandDescriptors public interface CommandCallParser { diff --git a/mirai-console/backend/mirai-console/src/command/resolve/ResolvedCommandCall.kt b/mirai-console/backend/mirai-console/src/command/resolve/ResolvedCommandCall.kt index 641094d06..b494c817b 100644 --- a/mirai-console/backend/mirai-console/src/command/resolve/ResolvedCommandCall.kt +++ b/mirai-console/backend/mirai-console/src/command/resolve/ResolvedCommandCall.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -102,6 +102,7 @@ public class ResolvedCommandCallImpl( private val context: CommandArgumentContext, override val originalMessage: MessageChain, ) : ResolvedCommandCall { + @ConsoleExperimentalApi override val resolvedValueArguments: List> by lazy { calleeSignature.valueParameters.zip(rawValueArguments).map { (parameter, argument) -> val value = argument.mapToTypeOrNull(parameter.type) { type, message -> diff --git a/mirai-console/backend/mirai-console/src/data/AbstractPluginData.kt b/mirai-console/backend/mirai-console/src/data/AbstractPluginData.kt index efbdafd71..7e3d23bc3 100644 --- a/mirai-console/backend/mirai-console/src/data/AbstractPluginData.kt +++ b/mirai-console/backend/mirai-console/src/data/AbstractPluginData.kt @@ -32,6 +32,7 @@ public abstract class AbstractPluginData : PluginData, PluginDataImpl() { /** * 这个 [PluginData] 保存时使用的名称. */ + @ConsoleExperimentalApi public abstract override val saveName: String /** @@ -66,6 +67,7 @@ public abstract class AbstractPluginData : PluginData, PluginDataImpl() { /** * 使用 `by value()` 时自动调用此方法, 添加对 [Value] 的值修改的跟踪, 并创建 [ValueNode] 加入 [valueNodes] */ + @OptIn(ConsoleExperimentalApi::class) public operator fun > T.provideDelegate( thisRef: Any?, property: KProperty<*>, diff --git a/mirai-console/backend/mirai-console/src/data/AutoSavePluginData.kt b/mirai-console/backend/mirai-console/src/data/AutoSavePluginData.kt index 120f3029b..81b539ee4 100644 --- a/mirai-console/backend/mirai-console/src/data/AutoSavePluginData.kt +++ b/mirai-console/backend/mirai-console/src/data/AutoSavePluginData.kt @@ -1,10 +1,10 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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", "PropertyName", "PrivatePropertyName") @@ -16,6 +16,7 @@ import net.mamoe.mirai.console.MiraiConsole import net.mamoe.mirai.console.internal.data.qualifiedNameOrTip import net.mamoe.mirai.console.internal.util.runIgnoreException import net.mamoe.mirai.console.util.ConsoleExperimentalApi +import net.mamoe.mirai.console.util.ConsoleInternalApi import net.mamoe.mirai.console.util.TimedTask import net.mamoe.mirai.console.util.launchTimedTask import net.mamoe.mirai.utils.MiraiLogger @@ -35,20 +36,27 @@ public open class AutoSavePluginData private constructor( // KEEP THIS PRIMARY CONSTRUCTOR FOR FUTURE USE: WE'LL SUPPORT SERIALIZERS_MODULE FOR POLYMORPHISM @Suppress("UNUSED_PARAMETER") primaryConstructorMark: Any?, ) : AbstractPluginData() { + @OptIn(ConsoleExperimentalApi::class) private lateinit var owner_: AutoSavePluginDataHolder + + @OptIn(ConsoleExperimentalApi::class) private val autoSaveIntervalMillis_: LongRange get() = owner_.autoSaveIntervalMillis + + @OptIn(ConsoleExperimentalApi::class) private lateinit var storage_: PluginDataStorage + @ConsoleExperimentalApi public final override val saveName: String get() = _saveName - @Suppress("JoinDeclarationAndAssignment") // bug + // bug private lateinit var _saveName: String public constructor(saveName: String) : this(null) { _saveName = saveName } + @OptIn(ConsoleInternalApi::class, ConsoleExperimentalApi::class) private fun logException(e: Throwable) { owner_.coroutineContext[CoroutineExceptionHandler]?.handleException(owner_.coroutineContext, e) ?.let { return } @@ -112,6 +120,7 @@ public open class AutoSavePluginData private constructor( } } + @OptIn(ConsoleExperimentalApi::class) private fun doSave() { debuggingLogger1.error { "doSave: ${this::class.qualifiedName}" } storage_.store(owner_, this) diff --git a/mirai-console/backend/mirai-console/src/data/PluginData.kt b/mirai-console/backend/mirai-console/src/data/PluginData.kt index 06d09ff63..84c8c0001 100644 --- a/mirai-console/backend/mirai-console/src/data/PluginData.kt +++ b/mirai-console/backend/mirai-console/src/data/PluginData.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -277,7 +277,7 @@ public fun PluginData.value(default: String): SerializerAwareValue = val * - [MessageSerializers] 支持的所有类型, 如 [MessageChain]. * - 在 [PluginData.serializersModule] 自定义支持的类型 */ -@Suppress("UNCHECKED_CAST") +@OptIn(ConsoleExperimentalApi::class) @LowPriorityInOverloadResolution public inline fun PluginData.value( default: T, @@ -324,6 +324,7 @@ public inline fun <@ResolveContext(RESTRICTED_NO_ARG_CONSTRUCTOR) reified T> PluginData.value(apply: T.() -> Unit = {}): SerializerAwareValue<@kotlin.internal.Exact T> = valueImpl(typeOf(), T::class).also { it.value.apply() } +@OptIn(ConsoleExperimentalApi::class) @Suppress("UNCHECKED_CAST") @PublishedApi internal fun PluginData.valueImpl(type: KType, classifier: KClass<*>): SerializerAwareValue = diff --git a/mirai-console/backend/mirai-console/src/data/PluginDataExtensions.kt b/mirai-console/backend/mirai-console/src/data/PluginDataExtensions.kt index 7d52d4bac..08063fb1c 100644 --- a/mirai-console/backend/mirai-console/src/data/PluginDataExtensions.kt +++ b/mirai-console/backend/mirai-console/src/data/PluginDataExtensions.kt @@ -1,10 +1,10 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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", "INAPPLICABLE_JVM_NAME", "INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") @@ -14,7 +14,6 @@ package net.mamoe.mirai.console.data import net.mamoe.mirai.console.data.PluginDataExtensions.withDefault import net.mamoe.mirai.console.internal.data.ShadowMap import net.mamoe.mirai.console.util.ConsoleExperimentalApi -import net.mamoe.mirai.utils.DeprecatedSinceMirai import kotlin.internal.LowPriorityInOverloadResolution /** @@ -39,6 +38,7 @@ public object PluginDataExtensions { } } + @OptIn(ConsoleExperimentalApi::class) @Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE") // as designed public class NotNullMutableMap internal constructor( private val delegate: MutableMap @@ -130,6 +130,7 @@ public object PluginDataExtensions { /** * 创建一个代理对象, 当 [Map.get] 返回 `null` 时先调用 [defaultValueComputer] 并放入 [Map], 再返回调用的返回值 */ + @OptIn(ConsoleExperimentalApi::class) @JvmStatic @JvmName("withDefaultMapImmutableNotNull") public fun SerializerAwareValue>.withDefault(defaultValueComputer: (K) -> V): SerializerAwareValue> { @@ -148,6 +149,7 @@ public object PluginDataExtensions { return (this as SerializerAwareValue>).withDefault(defaultValueComputer) as SerializerAwareValue> } + @OptIn(ConsoleExperimentalApi::class) @JvmStatic @JvmName("withDefaultMapNotNull") public fun SerializerAwareValue>.withDefault(defaultValueComputer: (K) -> V): SerializerAwareValue> { @@ -171,6 +173,7 @@ public object PluginDataExtensions { /** * 创建一个代理对象, 当 [Map.get] 返回 `null` 时先调用 [defaultValueComputer] 并放入 [Map], 再返回调用的返回值 */ + @OptIn(ConsoleExperimentalApi::class) @LowPriorityInOverloadResolution @JvmStatic @JvmName("withDefaultMap") @@ -218,6 +221,7 @@ public object PluginDataExtensions { /** * 替换 [MutableMap] 的 key */ + @OptIn(ConsoleExperimentalApi::class) @JvmName("mapKeysNotNull") @JvmStatic public fun SerializerAwareValue>.mapKeys( @@ -246,6 +250,7 @@ public object PluginDataExtensions { /** * 替换 [MutableMap] 的 key */ + @OptIn(ConsoleExperimentalApi::class) @JvmName("mapKeys") @JvmStatic public fun SerializerAwareValue>.mapKeys( @@ -272,6 +277,7 @@ public object PluginDataExtensions { /** * 替换 [Map] 的 key */ + @OptIn(ConsoleExperimentalApi::class) @JvmName("mapKeysImmutable") @JvmStatic public fun SerializerAwareValue>.mapKeys( @@ -300,6 +306,7 @@ public object PluginDataExtensions { /** * 替换 [Map] 的 key */ + @OptIn(ConsoleExperimentalApi::class) @JvmName("mapKeysImmutableNotNull") @JvmStatic public fun SerializerAwareValue>.mapKeys( diff --git a/mirai-console/backend/mirai-console/src/data/ReadOnlyPluginData.kt b/mirai-console/backend/mirai-console/src/data/ReadOnlyPluginData.kt index 28c6396af..82b521e3a 100644 --- a/mirai-console/backend/mirai-console/src/data/ReadOnlyPluginData.kt +++ b/mirai-console/backend/mirai-console/src/data/ReadOnlyPluginData.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -25,6 +25,7 @@ public open class ReadOnlyPluginData private constructor( // KEEP THIS PRIMARY CONSTRUCTOR FOR FUTURE USE: WE'LL SUPPORT SERIALIZERS_MODULE FOR POLYMORPHISM @Suppress("UNUSED_PARAMETER") primaryConstructorMark: Any?, ) : AbstractPluginData() { + @ConsoleExperimentalApi public final override val saveName: String get() = _saveName diff --git a/mirai-console/backend/mirai-console/src/data/Value.kt b/mirai-console/backend/mirai-console/src/data/Value.kt index 5a16de378..4a28cd2a5 100644 --- a/mirai-console/backend/mirai-console/src/data/Value.kt +++ b/mirai-console/backend/mirai-console/src/data/Value.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -230,6 +230,7 @@ public interface CompositeValue : Value * @see [CompositeListValue] * @see [PrimitiveListValue] */ +@OptIn(ConsoleExperimentalApi::class) public interface ListValue : CompositeValue> /** diff --git a/mirai-console/backend/mirai-console/src/data/java/JavaAutoSavePluginData.kt b/mirai-console/backend/mirai-console/src/data/java/JavaAutoSavePluginData.kt index 8b9cd0e7e..9d44dd183 100644 --- a/mirai-console/backend/mirai-console/src/data/java/JavaAutoSavePluginData.kt +++ b/mirai-console/backend/mirai-console/src/data/java/JavaAutoSavePluginData.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -8,6 +8,7 @@ */ @file:Suppress("unused", "EXPOSED_SUPER_CLASS") +@file:OptIn(ConsoleExperimentalApi::class) package net.mamoe.mirai.console.data.java @@ -16,6 +17,7 @@ import net.mamoe.mirai.console.internal.data.cast import net.mamoe.mirai.console.internal.data.setValueBySerializer import net.mamoe.mirai.console.internal.data.valueImpl import net.mamoe.mirai.console.plugin.jvm.JvmPlugin +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.console.util.JavaFriendlyApi import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentMap diff --git a/mirai-console/backend/mirai-console/src/extensions/CommandCallInterceptorProvider.kt b/mirai-console/backend/mirai-console/src/extensions/CommandCallInterceptorProvider.kt index abccc5458..5329d90a7 100644 --- a/mirai-console/backend/mirai-console/src/extensions/CommandCallInterceptorProvider.kt +++ b/mirai-console/backend/mirai-console/src/extensions/CommandCallInterceptorProvider.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -13,9 +13,11 @@ import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors import net.mamoe.mirai.console.command.resolve.CommandCallInterceptor import net.mamoe.mirai.console.extension.AbstractInstanceExtensionPoint import net.mamoe.mirai.console.extension.InstanceExtension +import net.mamoe.mirai.console.util.ConsoleExperimentalApi @ExperimentalCommandDescriptors public interface CommandCallInterceptorProvider : InstanceExtension { + @OptIn(ConsoleExperimentalApi::class) @ExperimentalCommandDescriptors public companion object ExtensionPoint : AbstractInstanceExtensionPoint( diff --git a/mirai-console/backend/mirai-console/src/extensions/CommandCallParserProvider.kt b/mirai-console/backend/mirai-console/src/extensions/CommandCallParserProvider.kt index 19512c151..defe9a7c0 100644 --- a/mirai-console/backend/mirai-console/src/extensions/CommandCallParserProvider.kt +++ b/mirai-console/backend/mirai-console/src/extensions/CommandCallParserProvider.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -13,12 +13,14 @@ import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors import net.mamoe.mirai.console.command.parse.CommandCallParser import net.mamoe.mirai.console.extension.AbstractInstanceExtensionPoint import net.mamoe.mirai.console.extension.InstanceExtension +import net.mamoe.mirai.console.util.ConsoleExperimentalApi /** * The provider of [CommandCallParser] */ @ExperimentalCommandDescriptors public interface CommandCallParserProvider : InstanceExtension { + @OptIn(ConsoleExperimentalApi::class) @ExperimentalCommandDescriptors public companion object ExtensionPoint : AbstractInstanceExtensionPoint(CommandCallParserProvider::class) diff --git a/mirai-console/backend/mirai-console/src/extensions/CommandCallResolverProvider.kt b/mirai-console/backend/mirai-console/src/extensions/CommandCallResolverProvider.kt index 8cf92ed7b..1420d2a0e 100644 --- a/mirai-console/backend/mirai-console/src/extensions/CommandCallResolverProvider.kt +++ b/mirai-console/backend/mirai-console/src/extensions/CommandCallResolverProvider.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -13,10 +13,12 @@ import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors import net.mamoe.mirai.console.command.resolve.CommandCallResolver import net.mamoe.mirai.console.extension.AbstractInstanceExtensionPoint import net.mamoe.mirai.console.extension.InstanceExtension +import net.mamoe.mirai.console.util.ConsoleExperimentalApi @ExperimentalCommandDescriptors public interface CommandCallResolverProvider : InstanceExtension { + @OptIn(ConsoleExperimentalApi::class) @ExperimentalCommandDescriptors public companion object ExtensionPoint : AbstractInstanceExtensionPoint(CommandCallResolverProvider::class) diff --git a/mirai-console/backend/mirai-console/src/extensions/PermissionServiceProvider.kt b/mirai-console/backend/mirai-console/src/extensions/PermissionServiceProvider.kt index dc9d77140..72e96d169 100644 --- a/mirai-console/backend/mirai-console/src/extensions/PermissionServiceProvider.kt +++ b/mirai-console/backend/mirai-console/src/extensions/PermissionServiceProvider.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -12,6 +12,7 @@ package net.mamoe.mirai.console.extensions import net.mamoe.mirai.console.extension.AbstractInstanceExtensionPoint import net.mamoe.mirai.console.extension.InstanceExtension import net.mamoe.mirai.console.permission.PermissionService +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.utils.DeprecatedSinceMirai /** @@ -21,6 +22,7 @@ import net.mamoe.mirai.utils.DeprecatedSinceMirai */ public interface PermissionServiceProvider : InstanceExtension> { + @OptIn(ConsoleExperimentalApi::class) public companion object ExtensionPoint : AbstractInstanceExtensionPoint>(PermissionServiceProvider::class) // ! BREAKING CHANGE MADE IN 2.11: supertype changed from AbstractSingletonExtensionPoint to AbstractInstanceExtensionPoint diff --git a/mirai-console/backend/mirai-console/src/extensions/SingletonExtensionSelector.kt b/mirai-console/backend/mirai-console/src/extensions/SingletonExtensionSelector.kt index a4d854316..c5bc43586 100644 --- a/mirai-console/backend/mirai-console/src/extensions/SingletonExtensionSelector.kt +++ b/mirai-console/backend/mirai-console/src/extensions/SingletonExtensionSelector.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -17,6 +17,7 @@ import net.mamoe.mirai.console.internal.extension.GlobalComponentStorage import net.mamoe.mirai.console.internal.extension.SingletonExtensionSelectorImpl import net.mamoe.mirai.console.plugin.Plugin import net.mamoe.mirai.console.plugin.name +import net.mamoe.mirai.console.util.ConsoleInternalApi import net.mamoe.mirai.utils.DeprecatedSinceMirai import net.mamoe.mirai.utils.info import kotlin.reflect.KClass @@ -66,6 +67,7 @@ public interface SingletonExtensionSelector : FunctionExtension { internal val instance: SingletonExtensionSelector get() = instanceField ?: error("") + @OptIn(ConsoleInternalApi::class) internal fun init() { check(instanceField == null) { "Internal error: reinitialize SingletonExtensionSelector" } val instances = GlobalComponentStorage.getExtensions(ExtensionPoint).toList() diff --git a/mirai-console/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt b/mirai-console/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt index c43df6cb7..bd9596ad7 100644 --- a/mirai-console/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt +++ b/mirai-console/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,7 +7,10 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ -@file:OptIn(ConsoleExperimentalApi::class) +@file:OptIn( + ConsoleExperimentalApi::class, ConsoleFrontEndImplementation::class, ConsoleInternalApi::class, + MiraiInternalApi::class, MiraiExperimentalApi::class +) package net.mamoe.mirai.console.internal @@ -17,6 +20,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import me.him188.kotlin.dynamic.delegation.dynamicDelegation import net.mamoe.mirai.Bot +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MalformedMiraiConsoleImplementationError import net.mamoe.mirai.console.MiraiConsole import net.mamoe.mirai.console.MiraiConsoleImplementation @@ -57,10 +61,7 @@ import net.mamoe.mirai.console.permission.PermissionService.Companion.permit import net.mamoe.mirai.console.permission.RootPermission import net.mamoe.mirai.console.plugin.PluginManager import net.mamoe.mirai.console.plugin.name -import net.mamoe.mirai.console.util.AnsiMessageBuilder -import net.mamoe.mirai.console.util.ConsoleExperimentalApi -import net.mamoe.mirai.console.util.ConsoleInput -import net.mamoe.mirai.console.util.SemVersion +import net.mamoe.mirai.console.util.* import net.mamoe.mirai.console.util.cast import net.mamoe.mirai.event.broadcast import net.mamoe.mirai.utils.* @@ -174,7 +175,6 @@ internal class MiraiConsoleImplementationBridge( return MiraiLogger.Factory.create(MiraiConsole::class, identity) } - @Suppress("RemoveRedundantBackticks") internal fun doStart() { externalImplementation.preStart() diff --git a/mirai-console/backend/mirai-console/src/internal/auth/ConsoleBotAuthorization.kt b/mirai-console/backend/mirai-console/src/internal/auth/ConsoleBotAuthorization.kt index b07a357f3..391b8c3e9 100644 --- a/mirai-console/backend/mirai-console/src/internal/auth/ConsoleBotAuthorization.kt +++ b/mirai-console/backend/mirai-console/src/internal/auth/ConsoleBotAuthorization.kt @@ -13,6 +13,7 @@ import net.mamoe.mirai.auth.BotAuthInfo import net.mamoe.mirai.auth.BotAuthResult import net.mamoe.mirai.auth.BotAuthSession import net.mamoe.mirai.auth.BotAuthorization +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsoleImplementation import java.io.ByteArrayOutputStream @@ -24,6 +25,7 @@ internal class ConsoleBotAuthorization( return delegate.invoke(session, info) } + @OptIn(ConsoleFrontEndImplementation::class) override fun calculateSecretsKey(bot: BotAuthInfo): ByteArray { val calc = MiraiConsoleImplementation.getBridge().consoleSecretsCalculator diff --git a/mirai-console/backend/mirai-console/src/internal/command/CommandManagerImpl.kt b/mirai-console/backend/mirai-console/src/internal/command/CommandManagerImpl.kt index 19bf132cc..ce595ab0c 100644 --- a/mirai-console/backend/mirai-console/src/internal/command/CommandManagerImpl.kt +++ b/mirai-console/backend/mirai-console/src/internal/command/CommandManagerImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,10 +7,13 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleFrontEndImplementation::class, ConsoleExperimentalApi::class) + package net.mamoe.mirai.console.internal.command import kotlinx.atomicfu.locks.withLock import kotlinx.coroutines.CoroutineScope +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsoleImplementation.ConsoleDataScope.Companion.get import net.mamoe.mirai.console.command.* import net.mamoe.mirai.console.command.Command.Companion.allNames @@ -24,9 +27,9 @@ import net.mamoe.mirai.console.command.resolve.getOrElse import net.mamoe.mirai.console.internal.data.builtins.DataScope import net.mamoe.mirai.console.internal.util.ifNull import net.mamoe.mirai.console.permission.PermissionService.Companion.testPermission +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.message.data.Message import net.mamoe.mirai.message.data.toMessageChain -import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.childScope import java.lang.reflect.InvocationTargetException import java.util.concurrent.locks.ReentrantLock @@ -36,11 +39,8 @@ import kotlin.coroutines.CoroutineContext internal class CommandManagerImpl( parentCoroutineContext: CoroutineContext ) : CommandManager, CoroutineScope by parentCoroutineContext.childScope("CommandManagerImpl") { - private val logger: MiraiLogger by lazy { - MiraiLogger.Factory.create(CommandManager::class, "command") - } - @Suppress("ObjectPropertyName") + @Suppress("PropertyName") @JvmField internal val _registeredCommands: MutableList = mutableListOf() diff --git a/mirai-console/backend/mirai-console/src/internal/command/CommandReflector.kt b/mirai-console/backend/mirai-console/src/internal/command/CommandReflector.kt index ba01d7ccf..c13a70c32 100644 --- a/mirai-console/backend/mirai-console/src/internal/command/CommandReflector.kt +++ b/mirai-console/backend/mirai-console/src/internal/command/CommandReflector.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,6 +7,8 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleExperimentalApi::class) + package net.mamoe.mirai.console.internal.command import net.mamoe.mirai.console.command.* diff --git a/mirai-console/backend/mirai-console/src/internal/command/builtin/LoginCommandImpl.kt b/mirai-console/backend/mirai-console/src/internal/command/builtin/LoginCommandImpl.kt index 24d2ca685..3f25fda1f 100644 --- a/mirai-console/backend/mirai-console/src/internal/command/builtin/LoginCommandImpl.kt +++ b/mirai-console/backend/mirai-console/src/internal/command/builtin/LoginCommandImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,16 +7,20 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleFrontEndImplementation::class, ConsoleExperimentalApi::class) + package net.mamoe.mirai.console.internal.command.builtin import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.launch import net.mamoe.mirai.Bot +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsole import net.mamoe.mirai.console.MiraiConsoleImplementation.ConsoleDataScope.Companion.get import net.mamoe.mirai.console.command.* import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig import net.mamoe.mirai.console.internal.data.builtins.DataScope +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.console.util.scopeWith import net.mamoe.mirai.message.nextMessageOrNull import net.mamoe.mirai.utils.BotConfiguration @@ -36,7 +40,7 @@ internal open class LoginCommandImpl : SimpleCommand( bot.login() this }.onFailure { bot.close() }.getOrThrow() - } // workaround since LoginCommand is object + } // workaround since LoginCommand is an object @Handler suspend fun CommandSender.handle( diff --git a/mirai-console/backend/mirai-console/src/internal/data/CompositeValueImpl.kt b/mirai-console/backend/mirai-console/src/internal/data/CompositeValueImpl.kt index 3c10aa259..0a008dd91 100644 --- a/mirai-console/backend/mirai-console/src/internal/data/CompositeValueImpl.kt +++ b/mirai-console/backend/mirai-console/src/internal/data/CompositeValueImpl.kt @@ -1,17 +1,19 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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") +@file:OptIn(ConsoleExperimentalApi::class) package net.mamoe.mirai.console.internal.data import net.mamoe.mirai.console.data.* +import net.mamoe.mirai.console.util.ConsoleExperimentalApi // type inference bug diff --git a/mirai-console/backend/mirai-console/src/internal/data/MemoryPluginDataStorageImpl.kt b/mirai-console/backend/mirai-console/src/internal/data/MemoryPluginDataStorageImpl.kt index a8f9f144e..d8fdc03e3 100644 --- a/mirai-console/backend/mirai-console/src/internal/data/MemoryPluginDataStorageImpl.kt +++ b/mirai-console/backend/mirai-console/src/internal/data/MemoryPluginDataStorageImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,12 +7,15 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleExperimentalApi::class) + package net.mamoe.mirai.console.internal.data import net.mamoe.mirai.console.data.MemoryPluginDataStorage import net.mamoe.mirai.console.data.PluginData import net.mamoe.mirai.console.data.PluginDataHolder import net.mamoe.mirai.console.data.PluginDataStorage +import net.mamoe.mirai.console.util.ConsoleExperimentalApi internal class MemoryPluginDataStorageImpl : PluginDataStorage, MemoryPluginDataStorage, MutableMap, PluginData> by mutableMapOf() { diff --git a/mirai-console/backend/mirai-console/src/internal/data/MultiFilePluginDataStorageImpl.kt b/mirai-console/backend/mirai-console/src/internal/data/MultiFilePluginDataStorageImpl.kt index b5a17eea3..4048c2439 100644 --- a/mirai-console/backend/mirai-console/src/internal/data/MultiFilePluginDataStorageImpl.kt +++ b/mirai-console/backend/mirai-console/src/internal/data/MultiFilePluginDataStorageImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,6 +7,8 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleExperimentalApi::class) + package net.mamoe.mirai.console.internal.data import kotlinx.serialization.json.Json diff --git a/mirai-console/backend/mirai-console/src/internal/data/PluginDataImpl.kt b/mirai-console/backend/mirai-console/src/internal/data/PluginDataImpl.kt index 7a8fa2e60..2d5ab2624 100644 --- a/mirai-console/backend/mirai-console/src/internal/data/PluginDataImpl.kt +++ b/mirai-console/backend/mirai-console/src/internal/data/PluginDataImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -8,9 +8,11 @@ */ @file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "EXPOSED_SUPER_CLASS") +@file:OptIn(ConsoleExperimentalApi::class) package net.mamoe.mirai.console.internal.data +import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialName import kotlinx.serialization.builtins.serializer @@ -23,6 +25,7 @@ import net.mamoe.mirai.console.data.AbstractPluginData.ValueNode import net.mamoe.mirai.console.data.PluginData import net.mamoe.mirai.console.data.ValueDescription import net.mamoe.mirai.console.data.ValueName +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.yamlkt.Comment import net.mamoe.yamlkt.YamlNullableDynamicSerializer import java.lang.reflect.Constructor @@ -44,6 +47,7 @@ internal abstract class PluginDataImpl { return valueNodes.firstOrNull { it.valueName == name } } + @OptIn(ExperimentalSerializationApi::class) internal open val updaterSerializer: KSerializer = object : KSerializer { override val descriptor: SerialDescriptor by lazy { check(this@PluginDataImpl is AbstractPluginData) @@ -54,11 +58,10 @@ internal abstract class PluginDataImpl { } } - @Suppress("UNCHECKED_CAST") override fun deserialize(decoder: Decoder) { val descriptor = descriptor with(decoder.beginStructure(descriptor)) { - if (decodeSequentially()) { + if (runCatching { decodeSequentially() }.getOrElse { false }) { var index = 0 repeat(decodeCollectionSize(descriptor)) { val valueName = decodeSerializableElement(descriptor, index++, String.serializer()) @@ -95,7 +98,6 @@ internal abstract class PluginDataImpl { } } - @Suppress("UNCHECKED_CAST") override fun serialize(encoder: Encoder, value: Unit) { check(this@PluginDataImpl is AbstractPluginData) diff --git a/mirai-console/backend/mirai-console/src/internal/data/_PluginData.value.kt b/mirai-console/backend/mirai-console/src/internal/data/_PluginData.value.kt index 8505382a9..2826d09bd 100644 --- a/mirai-console/backend/mirai-console/src/internal/data/_PluginData.value.kt +++ b/mirai-console/backend/mirai-console/src/internal/data/_PluginData.value.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,12 +7,15 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleExperimentalApi::class) + package net.mamoe.mirai.console.internal.data import kotlinx.serialization.builtins.serializer import net.mamoe.mirai.console.data.PluginData import net.mamoe.mirai.console.data.ReferenceValue import net.mamoe.mirai.console.data.SerializerAwareValue +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import kotlin.reflect.KClass diff --git a/mirai-console/backend/mirai-console/src/internal/data/_PrimitiveValueDeclarations.kt b/mirai-console/backend/mirai-console/src/internal/data/_PrimitiveValueDeclarations.kt index beb4a58c2..dd8c90413 100644 --- a/mirai-console/backend/mirai-console/src/internal/data/_PrimitiveValueDeclarations.kt +++ b/mirai-console/backend/mirai-console/src/internal/data/_PrimitiveValueDeclarations.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,6 +7,8 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleExperimentalApi::class) + package net.mamoe.mirai.console.internal.data import kotlinx.serialization.KSerializer @@ -15,6 +17,7 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import net.mamoe.mirai.console.data.* +import net.mamoe.mirai.console.util.ConsoleExperimentalApi /** * The super class to all ValueImpl diff --git a/mirai-console/backend/mirai-console/src/internal/data/builtins/ConsoleDataScopeImpl.kt b/mirai-console/backend/mirai-console/src/internal/data/builtins/ConsoleDataScopeImpl.kt index 173031966..39340e632 100644 --- a/mirai-console/backend/mirai-console/src/internal/data/builtins/ConsoleDataScopeImpl.kt +++ b/mirai-console/backend/mirai-console/src/internal/data/builtins/ConsoleDataScopeImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,14 +7,18 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleFrontEndImplementation::class, ConsoleExperimentalApi::class) + package net.mamoe.mirai.console.internal.data.builtins import kotlinx.coroutines.CoroutineScope +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.data.AutoSavePluginDataHolder import net.mamoe.mirai.console.data.PluginConfig import net.mamoe.mirai.console.data.PluginData import net.mamoe.mirai.console.data.PluginDataStorage +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.utils.TestOnly import net.mamoe.mirai.utils.childScope import net.mamoe.mirai.utils.minutesToMillis diff --git a/mirai-console/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt b/mirai-console/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt index 991a1c2c9..991ba6bbd 100644 --- a/mirai-console/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt +++ b/mirai-console/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -15,11 +15,13 @@ import net.mamoe.mirai.console.data.ReadOnlyPluginConfig import net.mamoe.mirai.console.data.ValueDescription import net.mamoe.mirai.console.data.value import net.mamoe.mirai.console.logging.AbstractLoggerController +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.utils.MiraiExperimentalApi @ConsoleFrontEndImplementation @MiraiExperimentalApi public class LoggerConfig : ReadOnlyPluginConfig("Logger") { + @ConsoleExperimentalApi @ValueDescription( """ 默认日志输出等级 @@ -28,6 +30,7 @@ public class LoggerConfig : ReadOnlyPluginConfig("Logger") { ) public val defaultPriority: AbstractLoggerController.LogPriority by value(AbstractLoggerController.LogPriority.INFO) + @ConsoleExperimentalApi @ValueDescription( """ 特定日志记录器输出等级 diff --git a/mirai-console/backend/mirai-console/src/internal/data/serializerHelper.kt b/mirai-console/backend/mirai-console/src/internal/data/serializerHelper.kt index 33283397c..35164a347 100644 --- a/mirai-console/backend/mirai-console/src/internal/data/serializerHelper.kt +++ b/mirai-console/backend/mirai-console/src/internal/data/serializerHelper.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -11,6 +11,7 @@ package net.mamoe.mirai.console.internal.data +import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.* import kotlinx.serialization.descriptors.SerialDescriptor @@ -27,6 +28,7 @@ import kotlin.reflect.KClass import kotlin.reflect.KType +@OptIn(ExperimentalSerializationApi::class) @Suppress("UNCHECKED_CAST") internal fun SerializersModule.serializerMirai(type: KType): KSerializer { fun serializerByKTypeImpl(type: KType): KSerializer<*> { @@ -69,6 +71,7 @@ internal fun SerializersModule.serializerMirai(type: KType): KSerializer { serializers[0], serializers[1] ) + Map.Entry::class -> MapEntrySerializer(serializers[0], serializers[1]) Pair::class -> PairSerializer(serializers[0], serializers[1]) Triple::class -> TripleSerializer(serializers[0], serializers[1], serializers[2]) @@ -102,11 +105,9 @@ internal fun SerializersModule.serializerMirai(type: KType): KSerializer { */ @Suppress( "UNCHECKED_CAST", - "NO_REFLECTION_IN_CLASS_PATH", "UNSUPPORTED", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", - "IMPLICIT_CAST_TO_ANY" ) private fun KClass.constructSerializerForGivenTypeArgs(vararg args: KSerializer): KSerializer? { val jClass = this.java diff --git a/mirai-console/backend/mirai-console/src/internal/data/valueFromKTypeImpl.kt b/mirai-console/backend/mirai-console/src/internal/data/valueFromKTypeImpl.kt index 5a5c7ec75..883ebc96c 100644 --- a/mirai-console/backend/mirai-console/src/internal/data/valueFromKTypeImpl.kt +++ b/mirai-console/backend/mirai-console/src/internal/data/valueFromKTypeImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -8,6 +8,7 @@ */ @file:Suppress("NOTHING_TO_INLINE", "INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") +@file:OptIn(ConsoleExperimentalApi::class) package net.mamoe.mirai.console.internal.data @@ -16,6 +17,7 @@ import net.mamoe.mirai.console.data.PluginData import net.mamoe.mirai.console.data.SerializableValue.Companion.serializableValueWith import net.mamoe.mirai.console.data.SerializerAwareValue import net.mamoe.mirai.console.data.valueFromKType +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.utils.createInstanceOrNull import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentMap diff --git a/mirai-console/backend/mirai-console/src/internal/extension/ComponentStorageInternal.kt b/mirai-console/backend/mirai-console/src/internal/extension/ComponentStorageInternal.kt index 5577966cd..a3dcdb277 100644 --- a/mirai-console/backend/mirai-console/src/internal/extension/ComponentStorageInternal.kt +++ b/mirai-console/backend/mirai-console/src/internal/extension/ComponentStorageInternal.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,13 +7,17 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleFrontEndImplementation::class, ConsoleExperimentalApi::class) + package net.mamoe.mirai.console.internal.extension +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.extension.* import net.mamoe.mirai.console.internal.data.kClassQualifiedNameOrTip import net.mamoe.mirai.console.plugin.Plugin import net.mamoe.mirai.console.plugin.name +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import java.util.* import java.util.concurrent.ConcurrentHashMap import java.util.stream.Stream diff --git a/mirai-console/backend/mirai-console/src/internal/extension/SingletonExtensionSelectorImpl.kt b/mirai-console/backend/mirai-console/src/internal/extension/SingletonExtensionSelectorImpl.kt index f0ec4c956..4fff1f002 100644 --- a/mirai-console/backend/mirai-console/src/internal/extension/SingletonExtensionSelectorImpl.kt +++ b/mirai-console/backend/mirai-console/src/internal/extension/SingletonExtensionSelectorImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -8,6 +8,7 @@ */ @file:Suppress("DEPRECATION_ERROR") +@file:OptIn(ConsoleInternalApi::class) package net.mamoe.mirai.console.internal.extension @@ -20,6 +21,7 @@ import net.mamoe.mirai.console.extensions.SingletonExtensionSelector import net.mamoe.mirai.console.internal.data.kClassQualifiedName import net.mamoe.mirai.console.plugin.name import net.mamoe.mirai.console.util.ConsoleInput +import net.mamoe.mirai.console.util.ConsoleInternalApi import net.mamoe.mirai.utils.DeprecatedSinceMirai import net.mamoe.mirai.utils.info import kotlin.reflect.KClass diff --git a/mirai-console/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt b/mirai-console/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt index f9935e7f6..0df2af539 100644 --- a/mirai-console/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt +++ b/mirai-console/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,10 +7,15 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleFrontEndImplementation::class, MiraiExperimentalApi::class, ConsoleExperimentalApi::class) + package net.mamoe.mirai.console.internal.logging +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.internal.data.builtins.LoggerConfig import net.mamoe.mirai.console.logging.AbstractLoggerController +import net.mamoe.mirai.console.util.ConsoleExperimentalApi +import net.mamoe.mirai.utils.MiraiExperimentalApi internal class LoggerControllerImpl : AbstractLoggerController.PathBased() { // 防止 stack overflow (使用 logger 要加载 LoggerController, LoggerConfig 可能会使用 logger) diff --git a/mirai-console/backend/mirai-console/src/internal/logging/MiraiConsoleLogger.kt b/mirai-console/backend/mirai-console/src/internal/logging/MiraiConsoleLogger.kt index f8967bc4c..a3da5d5c5 100644 --- a/mirai-console/backend/mirai-console/src/internal/logging/MiraiConsoleLogger.kt +++ b/mirai-console/backend/mirai-console/src/internal/logging/MiraiConsoleLogger.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,9 +7,12 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleExperimentalApi::class) + package net.mamoe.mirai.console.internal.logging import net.mamoe.mirai.console.logging.LoggerController +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.MiraiLoggerPlatformBase import net.mamoe.mirai.utils.SimpleLogger diff --git a/mirai-console/backend/mirai-console/src/internal/logging/externalbind/slf4j/MiraiConsoleSLF4JService.kt b/mirai-console/backend/mirai-console/src/internal/logging/externalbind/slf4j/MiraiConsoleSLF4JService.kt index 340b12a47..32c15f099 100644 --- a/mirai-console/backend/mirai-console/src/internal/logging/externalbind/slf4j/MiraiConsoleSLF4JService.kt +++ b/mirai-console/backend/mirai-console/src/internal/logging/externalbind/slf4j/MiraiConsoleSLF4JService.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,11 +7,15 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleFrontEndImplementation::class, MiraiExperimentalApi::class) + package net.mamoe.mirai.console.internal.logging.externalbind.slf4j +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsoleImplementation.ConsoleDataScope.Companion.get import net.mamoe.mirai.console.internal.data.builtins.DataScope import net.mamoe.mirai.console.internal.data.builtins.LoggerConfig +import net.mamoe.mirai.utils.MiraiExperimentalApi import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.safeCast import org.slf4j.ILoggerFactory diff --git a/mirai-console/backend/mirai-console/src/internal/permission/BuiltInPermissionServices.kt b/mirai-console/backend/mirai-console/src/internal/permission/BuiltInPermissionServices.kt index 5cedab49f..c8c7374d4 100644 --- a/mirai-console/backend/mirai-console/src/internal/permission/BuiltInPermissionServices.kt +++ b/mirai-console/backend/mirai-console/src/internal/permission/BuiltInPermissionServices.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,6 +7,8 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleExperimentalApi::class) + package net.mamoe.mirai.console.internal.permission import kotlinx.serialization.Serializable @@ -16,6 +18,7 @@ import net.mamoe.mirai.console.data.PluginDataExtensions.withDefault import net.mamoe.mirai.console.data.value import net.mamoe.mirai.console.extensions.PermissionServiceProvider import net.mamoe.mirai.console.permission.* +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.CopyOnWriteArraySet import kotlin.reflect.KClass diff --git a/mirai-console/backend/mirai-console/src/internal/plugin/BuiltInJvmPluginLoaderImpl.kt b/mirai-console/backend/mirai-console/src/internal/plugin/BuiltInJvmPluginLoaderImpl.kt index 0ca7583bc..e6112f478 100644 --- a/mirai-console/backend/mirai-console/src/internal/plugin/BuiltInJvmPluginLoaderImpl.kt +++ b/mirai-console/backend/mirai-console/src/internal/plugin/BuiltInJvmPluginLoaderImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,11 +7,14 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleFrontEndImplementation::class, ConsoleExperimentalApi::class, MiraiInternalApi::class) + package net.mamoe.mirai.console.internal.plugin import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ensureActive +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsole import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.data.PluginDataStorage @@ -24,6 +27,7 @@ import net.mamoe.mirai.console.plugin.jvm.* import net.mamoe.mirai.console.plugin.loader.AbstractFilePluginLoader import net.mamoe.mirai.console.plugin.loader.PluginLoadException import net.mamoe.mirai.console.plugin.name +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.utils.* import java.io.File import java.nio.file.Path @@ -45,7 +49,7 @@ internal class BuiltInJvmPluginLoaderImpl( MiraiLogger.Factory.create(JvmPluginLoader::class) } - fun pluginsFilesSequence( + private fun pluginsFilesSequence( files: Sequence = PluginManager.pluginsFolder.listFiles().orEmpty().asSequence() ): Sequence { val raw = files @@ -74,7 +78,7 @@ internal class BuiltInJvmPluginLoaderImpl( get() = MiraiConsoleImplementation.getInstance().dataStorageForJvmPluginLoader - internal val jvmPluginLoadingCtx: JvmPluginsLoadingCtx by lazy { + private val jvmPluginLoadingCtx: JvmPluginsLoadingCtx by lazy { val legacyCompatibilityLayerClassLoader = LegacyCompatibilityLayerClassLoader.newInstance( BuiltInJvmPluginLoaderImpl::class.java.classLoader, ) @@ -166,7 +170,6 @@ internal class BuiltInJvmPluginLoaderImpl( } - @Suppress("EXTENSION_SHADOWED_BY_MEMBER") // doesn't matter override fun getPluginDescription(plugin: JvmPlugin): JvmPluginDescription = plugin.description private val pluginFileToInstanceMap: MutableMap = ConcurrentHashMap() diff --git a/mirai-console/backend/mirai-console/src/internal/plugin/ExportManagerImpl.kt b/mirai-console/backend/mirai-console/src/internal/plugin/ExportManagerImpl.kt index 291ebf5fb..8d6241b5b 100644 --- a/mirai-console/backend/mirai-console/src/internal/plugin/ExportManagerImpl.kt +++ b/mirai-console/backend/mirai-console/src/internal/plugin/ExportManagerImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,9 +7,12 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleExperimentalApi::class) + package net.mamoe.mirai.console.internal.plugin import net.mamoe.mirai.console.plugin.jvm.ExportManager +import net.mamoe.mirai.console.util.ConsoleExperimentalApi internal class ExportManagerImpl( private val rules: List<(String) -> Boolean?> diff --git a/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginClassLoader.kt b/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginClassLoader.kt index f03f5d8e2..51b07662e 100644 --- a/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginClassLoader.kt +++ b/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginClassLoader.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,11 +7,13 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ @file:Suppress("MemberVisibilityCanBePrivate") +@file:OptIn(ConsoleExperimentalApi::class) package net.mamoe.mirai.console.internal.plugin import net.mamoe.mirai.console.plugin.jvm.ExportManager import net.mamoe.mirai.console.plugin.jvm.JvmPluginClasspath +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.utils.* import org.eclipse.aether.artifact.Artifact import org.eclipse.aether.graph.DependencyFilter @@ -22,7 +24,6 @@ import java.net.URLClassLoader import java.util.* import java.util.concurrent.atomic.AtomicBoolean import java.util.zip.ZipFile -import kotlin.collections.LinkedHashSet /* Class resolving: diff --git a/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginDependencyDownload.kt b/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginDependencyDownload.kt index f1c574b66..3fec6c34b 100644 --- a/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginDependencyDownload.kt +++ b/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginDependencyDownload.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,8 +7,11 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleFrontEndImplementation::class) + package net.mamoe.mirai.console.internal.plugin +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.MiraiConsoleImplementation.ConsoleDataScope.Companion.get import net.mamoe.mirai.console.fontend.ProcessProgress diff --git a/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginInternal.kt b/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginInternal.kt index 019c169f4..0f10b14fc 100644 --- a/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginInternal.kt +++ b/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginInternal.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,12 +7,15 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(MiraiInternalApi::class, ConsoleFrontEndImplementation::class, ConsoleExperimentalApi::class) + package net.mamoe.mirai.console.internal.plugin import kotlinx.atomicfu.AtomicLong import kotlinx.atomicfu.atomic import kotlinx.atomicfu.locks.withLock import kotlinx.coroutines.* +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsole import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.data.runCatchingLog @@ -31,6 +34,8 @@ import net.mamoe.mirai.console.plugin.jvm.AbstractJvmPlugin import net.mamoe.mirai.console.plugin.jvm.JvmPlugin import net.mamoe.mirai.console.plugin.jvm.JvmPlugin.Companion.onLoad import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader +import net.mamoe.mirai.console.util.ConsoleExperimentalApi +import net.mamoe.mirai.utils.MiraiInternalApi import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.safeCast import java.io.File diff --git a/mirai-console/backend/mirai-console/src/internal/shutdown/ShutdownDaemon.kt b/mirai-console/backend/mirai-console/src/internal/shutdown/ShutdownDaemon.kt index 326fd2295..24d9ec7c7 100644 --- a/mirai-console/backend/mirai-console/src/internal/shutdown/ShutdownDaemon.kt +++ b/mirai-console/backend/mirai-console/src/internal/shutdown/ShutdownDaemon.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,6 +7,8 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleInternalApi::class) + package net.mamoe.mirai.console.internal.shutdown import kotlinx.coroutines.* @@ -14,6 +16,7 @@ import net.mamoe.mirai.console.MiraiConsole import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge import net.mamoe.mirai.console.internal.pluginManagerImpl import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.description +import net.mamoe.mirai.console.util.ConsoleInternalApi import net.mamoe.mirai.utils.debug import java.io.File import java.io.FileDescriptor diff --git a/mirai-console/backend/mirai-console/src/internal/util/ConsoleInputImpl.kt b/mirai-console/backend/mirai-console/src/internal/util/ConsoleInputImpl.kt index ded6336ad..25bb5afab 100644 --- a/mirai-console/backend/mirai-console/src/internal/util/ConsoleInputImpl.kt +++ b/mirai-console/backend/mirai-console/src/internal/util/ConsoleInputImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,10 +7,13 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleFrontEndImplementation::class) + package net.mamoe.mirai.console.internal.util import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.util.ConsoleInput diff --git a/mirai-console/backend/mirai-console/src/internal/util/PluginServiceHelper.kt b/mirai-console/backend/mirai-console/src/internal/util/PluginServiceHelper.kt index a9c150109..0e6d599d5 100644 --- a/mirai-console/backend/mirai-console/src/internal/util/PluginServiceHelper.kt +++ b/mirai-console/backend/mirai-console/src/internal/util/PluginServiceHelper.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -8,11 +8,13 @@ */ @file:Suppress("unused") +@file:OptIn(MiraiInternalApi::class) package net.mamoe.mirai.console.internal.util import net.mamoe.mirai.console.internal.data.cast import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader +import net.mamoe.mirai.utils.MiraiInternalApi import net.mamoe.mirai.utils.createInstanceOrNull import java.lang.reflect.Modifier import java.util.* diff --git a/mirai-console/backend/mirai-console/src/permission/PermissionService.kt b/mirai-console/backend/mirai-console/src/permission/PermissionService.kt index 3fd66bce1..1dbcc1f15 100644 --- a/mirai-console/backend/mirai-console/src/permission/PermissionService.kt +++ b/mirai-console/backend/mirai-console/src/permission/PermissionService.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,10 +7,11 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ -@file:Suppress("NOTHING_TO_INLINE", "unused", "MemberVisibilityCanBePrivate") +@file:Suppress("unused", "MemberVisibilityCanBePrivate") package net.mamoe.mirai.console.permission +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.compiler.common.ResolveContext import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.COMMAND_NAME @@ -22,6 +23,7 @@ import net.mamoe.mirai.console.permission.Permission.Companion.parentsWithSelf import net.mamoe.mirai.console.plugin.Plugin import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.description import net.mamoe.mirai.console.util.ConsoleExperimentalApi +import net.mamoe.mirai.utils.MiraiExperimentalApi import kotlin.reflect.KClass /** @@ -147,6 +149,7 @@ public interface PermissionService

{ */ @get:JvmName("getInstance") @JvmStatic + @OptIn(ConsoleFrontEndImplementation::class, MiraiExperimentalApi::class) public val INSTANCE: PermissionService get() { if (!MiraiConsoleImplementation.getBridge().permissionSeviceLoaded) { diff --git a/mirai-console/backend/mirai-console/src/permission/PermitteeId.kt b/mirai-console/backend/mirai-console/src/permission/PermitteeId.kt index 780e1383a..f514fe4ae 100644 --- a/mirai-console/backend/mirai-console/src/permission/PermitteeId.kt +++ b/mirai-console/backend/mirai-console/src/permission/PermitteeId.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -166,6 +166,7 @@ public interface PermitteeId { * ExactTemp * ``` */ +@OptIn(ConsoleExperimentalApi::class) @Serializable(with = AsStringSerializer::class) public sealed class AbstractPermitteeId( public final override vararg val directParents: PermitteeId, diff --git a/mirai-console/backend/mirai-console/src/plugin/jvm/AbstractJvmPlugin.kt b/mirai-console/backend/mirai-console/src/plugin/jvm/AbstractJvmPlugin.kt index 57a3ad0fd..69e3c9ab0 100644 --- a/mirai-console/backend/mirai-console/src/plugin/jvm/AbstractJvmPlugin.kt +++ b/mirai-console/backend/mirai-console/src/plugin/jvm/AbstractJvmPlugin.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -32,6 +32,7 @@ import kotlin.reflect.KClass * @see JavaPlugin * @see KotlinPlugin */ +@OptIn(ConsoleExperimentalApi::class) public abstract class AbstractJvmPlugin @JvmOverloads constructor( parentCoroutineContext: CoroutineContext = EmptyCoroutineContext, ) : JvmPlugin, JvmPluginInternal(parentCoroutineContext), AutoSavePluginDataHolder { diff --git a/mirai-console/backend/mirai-console/src/plugin/jvm/JvmPluginLoader.kt b/mirai-console/backend/mirai-console/src/plugin/jvm/JvmPluginLoader.kt index 4882ed6a0..63e20d042 100644 --- a/mirai-console/backend/mirai-console/src/plugin/jvm/JvmPluginLoader.kt +++ b/mirai-console/backend/mirai-console/src/plugin/jvm/JvmPluginLoader.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -11,10 +11,12 @@ package net.mamoe.mirai.console.plugin.jvm import kotlinx.coroutines.CoroutineScope import me.him188.kotlin.dynamic.delegation.dynamicDelegation +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.data.PluginDataStorage import net.mamoe.mirai.console.internal.plugin.BuiltInJvmPluginLoaderImpl import net.mamoe.mirai.console.plugin.loader.FilePluginLoader +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.utils.MiraiInternalApi import net.mamoe.mirai.utils.NotStableForInheritance @@ -31,11 +33,13 @@ public interface JvmPluginLoader : CoroutineScope, FilePluginLoader? public companion object BuiltIn : - JvmPluginLoader by (dynamicDelegation { MiraiConsoleImplementation.getInstance().jvmPluginLoader }) { + JvmPluginLoader by (dynamicDelegation { + @OptIn(ConsoleFrontEndImplementation::class) + MiraiConsoleImplementation.getInstance().jvmPluginLoader + }) { - @Suppress("EXTENSION_SHADOWED_BY_MEMBER") override fun getPluginDescription(plugin: JvmPlugin): JvmPluginDescription = BuiltInJvmPluginLoaderImpl.run { plugin.description } } diff --git a/mirai-console/backend/mirai-console/src/util/AnsiMessageBuilder.kt b/mirai-console/backend/mirai-console/src/util/AnsiMessageBuilder.kt index a427fa3de..7ba4a86e0 100644 --- a/mirai-console/backend/mirai-console/src/util/AnsiMessageBuilder.kt +++ b/mirai-console/backend/mirai-console/src/util/AnsiMessageBuilder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -97,7 +97,6 @@ public open class AnsiMessageBuilder public constructor( /** * 判断 [sender] 是否支持带 ansi 控制符的正确显示 */ - @ConsoleExperimentalApi @JvmStatic public fun isAnsiSupported(sender: CommandSender): Boolean = if (sender is SystemCommandSender) { @@ -117,8 +116,7 @@ public open class AnsiMessageBuilder public constructor( if (other == null) return false if (other::class.java != this::class.java) return false other as AnsiMessageBuilder - if (other.delegate != this.delegate) return false - return true + return other.delegate == this.delegate } ///////////////////////////////////////////////////////////////////////////////// diff --git a/mirai-console/backend/mirai-console/src/util/MessageScope.kt b/mirai-console/backend/mirai-console/src/util/MessageScope.kt index 0957299d7..7feedd329 100644 --- a/mirai-console/backend/mirai-console/src/util/MessageScope.kt +++ b/mirai-console/backend/mirai-console/src/util/MessageScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -579,6 +579,7 @@ internal fun MessageScope.asSequence(): Sequence { } else sequenceOf(this) } +@OptIn(ConsoleExperimentalApi::class) private class CombinedScope( val first: MessageScope, val second: MessageScope, @@ -602,6 +603,7 @@ private class CombinedScope( } } +@OptIn(ConsoleExperimentalApi::class) private class CommandSenderAsMessageScope( private val sender: CommandSender, ) : MessageScope { @@ -621,6 +623,7 @@ private class CommandSenderAsMessageScope( } } +@OptIn(ConsoleExperimentalApi::class) private class ContactAsMessageScope( private val sender: Contact, ) : MessageScope { @@ -636,6 +639,7 @@ private class ContactAsMessageScope( } } +@OptIn(ConsoleExperimentalApi::class) private object NoopMessageScope : MessageScope { override val realTarget: Any? get() = null diff --git a/mirai-console/frontend/mirai-console-frontend-base/src/AbstractMiraiConsoleFrontendImplementation.kt b/mirai-console/frontend/mirai-console-frontend-base/src/AbstractMiraiConsoleFrontendImplementation.kt index ceb0b3037..e2df965c8 100644 --- a/mirai-console/frontend/mirai-console-frontend-base/src/AbstractMiraiConsoleFrontendImplementation.kt +++ b/mirai-console/frontend/mirai-console-frontend-base/src/AbstractMiraiConsoleFrontendImplementation.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -10,6 +10,7 @@ package net.mamoe.mirai.console.frontendbase import kotlinx.coroutines.* +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsole import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.command.CommandManager @@ -17,6 +18,9 @@ import net.mamoe.mirai.console.data.MultiFilePluginDataStorage import net.mamoe.mirai.console.data.PluginDataStorage import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader import net.mamoe.mirai.console.plugin.loader.PluginLoader +import net.mamoe.mirai.console.util.ConsoleExperimentalApi +import net.mamoe.mirai.console.util.ConsoleInternalApi +import net.mamoe.mirai.utils.MiraiInternalApi import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.PlatformLogger import kotlin.coroutines.CoroutineContext @@ -27,11 +31,13 @@ import kotlin.coroutines.CoroutineContext * @param frontendCoroutineName 该前端的名字, 如 `"MiraiConsoleImplementationTerminal"` * @see FrontendBase */ +@OptIn(ConsoleFrontEndImplementation::class) public abstract class AbstractMiraiConsoleFrontendImplementation( frontendCoroutineName: String, ) : MiraiConsoleImplementation, CoroutineScope { // region 此 region 的 字段 / 方法 为 console 默认/内部 实现, 如无必要不建议修改 + @OptIn(ConsoleInternalApi::class) private val delegateCoroutineScope by lazy { CoroutineScope( SupervisorJob() + @@ -51,19 +57,28 @@ public abstract class AbstractMiraiConsoleFrontendImplementation( override val jvmPluginLoader: JvmPluginLoader by lazy { backendAccess.createDefaultJvmPluginLoader(coroutineContext) } override val commandManager: CommandManager by lazy { backendAccess.createDefaultCommandManager(coroutineContext) } override val consoleDataScope: MiraiConsoleImplementation.ConsoleDataScope by lazy { + @OptIn(ConsoleExperimentalApi::class) MiraiConsoleImplementation.ConsoleDataScope.createDefault( coroutineContext, dataStorageForBuiltIns, configStorageForBuiltIns ) } + + @ConsoleExperimentalApi override val dataStorageForJvmPluginLoader: PluginDataStorage by lazy { MultiFilePluginDataStorage(rootPath.resolve("data")) } + + @ConsoleExperimentalApi override val dataStorageForBuiltIns: PluginDataStorage by lazy { MultiFilePluginDataStorage(rootPath.resolve("data")) } + + @ConsoleExperimentalApi override val configStorageForJvmPluginLoader: PluginDataStorage by lazy { MultiFilePluginDataStorage(rootPath.resolve("config")) } + + @ConsoleExperimentalApi override val configStorageForBuiltIns: PluginDataStorage by lazy { MultiFilePluginDataStorage(rootPath.resolve("config")) } @@ -75,6 +90,7 @@ public abstract class AbstractMiraiConsoleFrontendImplementation( // region Logging + @OptIn(MiraiInternalApi::class) override fun createLoggerFactory(context: MiraiConsoleImplementation.FrontendLoggingInitContext): MiraiLogger.Factory { @Suppress("INVISIBLE_MEMBER") frontendBase.initScreen_forwardStdToScreen() diff --git a/mirai-console/frontend/mirai-console-terminal/build.gradle.kts b/mirai-console/frontend/mirai-console-terminal/build.gradle.kts index 53653dd5a..a16776d1f 100644 --- a/mirai-console/frontend/mirai-console-terminal/build.gradle.kts +++ b/mirai-console/frontend/mirai-console-terminal/build.gradle.kts @@ -19,6 +19,11 @@ plugins { val shadow: Configuration = project.configurations.create("shadow") +kotlin { + optInForTestSourceSets("net.mamoe.mirai.console.util.ConsoleExperimentalApi") + optInForTestSourceSets("net.mamoe.mirai.console.ConsoleFrontEndImplementation") +} + dependencies { api(project(":mirai-core-api")) api(project(":mirai-console")) diff --git a/mirai-console/frontend/mirai-console-terminal/src/ConsoleTerminalSettings.kt b/mirai-console/frontend/mirai-console-terminal/src/ConsoleTerminalSettings.kt index cb3c16169..6c697d7ed 100644 --- a/mirai-console/frontend/mirai-console-terminal/src/ConsoleTerminalSettings.kt +++ b/mirai-console/frontend/mirai-console-terminal/src/ConsoleTerminalSettings.kt @@ -1,10 +1,10 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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 */ /* * @author Karlatemp @@ -12,6 +12,7 @@ package net.mamoe.mirai.console.terminal +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsoleImplementation @Retention(AnnotationRetention.BINARY) @@ -29,8 +30,11 @@ annotation class ConsoleTerminalExperimentalApi @ConsoleTerminalExperimentalApi object ConsoleTerminalSettings { + + @ConsoleFrontEndImplementation @JvmField - var launchOptions: MiraiConsoleImplementation.ConsoleLaunchOptions = MiraiConsoleImplementation.ConsoleLaunchOptions() + var launchOptions: MiraiConsoleImplementation.ConsoleLaunchOptions = + MiraiConsoleImplementation.ConsoleLaunchOptions() @JvmField var setupAnsi: Boolean = System.getProperty("os.name") diff --git a/mirai-console/frontend/mirai-console-terminal/src/ConsoleThread.kt b/mirai-console/frontend/mirai-console-terminal/src/ConsoleThread.kt index 27199930b..a4f716c49 100644 --- a/mirai-console/frontend/mirai-console-terminal/src/ConsoleThread.kt +++ b/mirai-console/frontend/mirai-console-terminal/src/ConsoleThread.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,7 +7,7 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ -@file:OptIn(ExperimentalCommandDescriptors::class) +@file:OptIn(ExperimentalCommandDescriptors::class, ConsoleExperimentalApi::class) package net.mamoe.mirai.console.terminal @@ -22,7 +22,7 @@ import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors import net.mamoe.mirai.console.command.parse.CommandCall import net.mamoe.mirai.console.command.parse.CommandValueArgument import net.mamoe.mirai.console.terminal.noconsole.NoConsole -import net.mamoe.mirai.console.util.ConsoleInternalApi +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.console.util.cast import net.mamoe.mirai.console.util.safeCast import net.mamoe.mirai.utils.MiraiLogger @@ -34,7 +34,7 @@ import kotlin.reflect.full.isSubclassOf val consoleLogger by lazy { MiraiLogger.Factory.create(MiraiConsole::class, "console") } -@OptIn(ConsoleInternalApi::class, ConsoleTerminalExperimentalApi::class, ExperimentalCommandDescriptors::class) +@OptIn(ExperimentalCommandDescriptors::class) internal fun startupConsoleThread() { if (terminal is NoConsole) return @@ -43,7 +43,7 @@ internal fun startupConsoleThread() { delay(2000) } }.invokeOnCompletion { - runCatching { + runCatching { // 应该仅关闭用户输入 terminal.reader().shutdown() }.exceptionOrNull()?.printStackTrace() diff --git a/mirai-console/frontend/mirai-console-terminal/src/JLineInputDaemon.kt b/mirai-console/frontend/mirai-console-terminal/src/JLineInputDaemon.kt index 2e62754ac..365007139 100644 --- a/mirai-console/frontend/mirai-console-terminal/src/JLineInputDaemon.kt +++ b/mirai-console/frontend/mirai-console-terminal/src/JLineInputDaemon.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,6 +7,8 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ConsoleExperimentalApi::class) + package net.mamoe.mirai.console.terminal import kotlinx.coroutines.CancellableContinuation @@ -14,6 +16,7 @@ import kotlinx.coroutines.Runnable import kotlinx.coroutines.isActive import kotlinx.coroutines.suspendCancellableCoroutine import net.mamoe.mirai.console.terminal.noconsole.NoConsole +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.utils.ConcurrentLinkedDeque import net.mamoe.mirai.utils.cast import org.jline.reader.MaskingCallback diff --git a/mirai-console/frontend/mirai-console-terminal/src/MiraiConsoleTerminalLoader.kt b/mirai-console/frontend/mirai-console-terminal/src/MiraiConsoleTerminalLoader.kt index 8cf15e300..2c10759c8 100644 --- a/mirai-console/frontend/mirai-console-terminal/src/MiraiConsoleTerminalLoader.kt +++ b/mirai-console/frontend/mirai-console-terminal/src/MiraiConsoleTerminalLoader.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -15,11 +15,12 @@ "INVISIBLE_GETTER", "INVISIBLE_ABSTRACT_MEMBER_FROM_SUPER", ) -@file:OptIn(ConsoleInternalApi::class, ConsoleTerminalExperimentalApi::class) +@file:OptIn(ConsoleInternalApi::class, ConsoleTerminalExperimentalApi::class, ConsoleFrontEndImplementation::class) package net.mamoe.mirai.console.terminal import kotlinx.coroutines.* +import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsole import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.MiraiConsoleImplementation.Companion.start @@ -28,7 +29,10 @@ import net.mamoe.mirai.console.terminal.noconsole.SystemOutputPrintStream import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.console.util.ConsoleInternalApi import net.mamoe.mirai.message.data.Message -import net.mamoe.mirai.utils.* +import net.mamoe.mirai.utils.childScope +import net.mamoe.mirai.utils.debug +import net.mamoe.mirai.utils.info +import net.mamoe.mirai.utils.verbose import org.jline.utils.Signals import java.io.FileDescriptor import java.io.FileOutputStream @@ -48,6 +52,7 @@ object MiraiConsoleTerminalLoader { // Note: Do not run this in IDEA, as you will get invalid classpath and `java.lang.NoClassDefFoundError`. // Run `RunTerminal.kt` under `test` source set instead. + @OptIn(ConsoleExperimentalApi::class) @JvmStatic fun main(args: Array) { parse(args, exitProcess = true) @@ -179,6 +184,7 @@ object MiraiConsoleTerminalLoader { } } +@OptIn(ConsoleExperimentalApi::class) internal object ConsoleDataHolder : AutoSavePluginDataHolder, CoroutineScope by MiraiConsole.childScope("ConsoleDataHolder") { @ConsoleExperimentalApi @@ -194,6 +200,8 @@ private val shutdownSignals = arrayOf( ) internal val signalHandler: (String) -> Unit = initSignalHandler() + +@OptIn(ConsoleExperimentalApi::class) private fun initSignalHandler(): (String) -> Unit { val shutdownMonitorLock = AtomicBoolean(false) val lastSignalTimestamp = AtomicLong(0) @@ -223,7 +231,7 @@ private fun initSignalHandler(): (String) -> Unit { if (signalName !in shutdownSignals) return@handler MiraiConsole.mainLogger.debug { "Handled signal $signalName" } - kotlin.run multiSignalHandler@{ + run multiSignalHandler@{ val crtTime = System.currentTimeMillis() val last = lastSignalTimestamp.getAndSet(crtTime) if (crtTime - last < 1000L) { diff --git a/mirai-core-api/compatibility-validation/android/api/android.api b/mirai-core-api/compatibility-validation/android/api/android.api index 59e2dd499..44fed993d 100644 --- a/mirai-core-api/compatibility-validation/android/api/android.api +++ b/mirai-core-api/compatibility-validation/android/api/android.api @@ -131,6 +131,9 @@ public abstract interface class net/mamoe/mirai/IMirai : net/mamoe/mirai/LowLeve public abstract fun setFileCacheStrategy (Lnet/mamoe/mirai/utils/FileCacheStrategy;)V } +public abstract interface annotation class net/mamoe/mirai/LowLevelApi : java/lang/annotation/Annotation { +} + public abstract interface class net/mamoe/mirai/LowLevelApiAccessor { public fun getGroupVoiceDownloadUrl (Lnet/mamoe/mirai/Bot;[BJJ)Ljava/lang/String; public abstract fun getGroupVoiceDownloadUrl (Lnet/mamoe/mirai/Bot;[BJJLkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -3919,7 +3922,6 @@ public final class net/mamoe/mirai/message/data/Face$Companion { public abstract interface class net/mamoe/mirai/message/data/FileMessage : net/mamoe/mirai/message/code/CodableMessage, net/mamoe/mirai/message/data/ConstrainSingle, net/mamoe/mirai/message/data/MessageContent { public static final field Key Lnet/mamoe/mirai/message/data/FileMessage$Key; public static final field SERIAL_NAME Ljava/lang/String; - public fun appendMiraiCodeTo (Ljava/lang/StringBuilder;)V public fun contentToString ()Ljava/lang/String; public static fun create (Ljava/lang/String;ILjava/lang/String;J)Lnet/mamoe/mirai/message/data/FileMessage; public abstract fun getId ()Ljava/lang/String; @@ -4719,7 +4721,6 @@ public final class net/mamoe/mirai/message/data/MusicShare : net/mamoe/mirai/mes public synthetic fun (ILnet/mamoe/mirai/message/data/MusicKind;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V public fun (Lnet/mamoe/mirai/message/data/MusicKind;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V public fun (Lnet/mamoe/mirai/message/data/MusicKind;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V - public fun appendMiraiCodeTo (Ljava/lang/StringBuilder;)V public final fun component1 ()Lnet/mamoe/mirai/message/data/MusicKind; public final fun component2 ()Ljava/lang/String; public final fun component3 ()Ljava/lang/String; @@ -5323,14 +5324,12 @@ public class net/mamoe/mirai/message/data/Voice : net/mamoe/mirai/message/data/P public synthetic fun (ILjava/lang/String;[BJILjava/lang/String;Ljava/lang/String;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V public synthetic fun (Ljava/lang/String;[BJILjava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun contentToString ()Ljava/lang/String; - public fun equals (Ljava/lang/Object;)Z public static final fun fromAudio (Lnet/mamoe/mirai/message/data/Audio;)Lnet/mamoe/mirai/message/data/Voice; public fun getFileName ()Ljava/lang/String; public fun getFileSize ()J public fun getMd5 ()[B public fun getUrl ()Ljava/lang/String; public final fun get_codec ()I - public fun hashCode ()I public final fun toAudio ()Lnet/mamoe/mirai/message/data/Audio; public fun toString ()Ljava/lang/String; public static final fun write$Self (Lnet/mamoe/mirai/message/data/Voice;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V diff --git a/mirai-core-api/compatibility-validation/jvm/api/jvm.api b/mirai-core-api/compatibility-validation/jvm/api/jvm.api index 3ff7aaa04..19f1110e2 100644 --- a/mirai-core-api/compatibility-validation/jvm/api/jvm.api +++ b/mirai-core-api/compatibility-validation/jvm/api/jvm.api @@ -131,6 +131,9 @@ public abstract interface class net/mamoe/mirai/IMirai : net/mamoe/mirai/LowLeve public abstract fun setFileCacheStrategy (Lnet/mamoe/mirai/utils/FileCacheStrategy;)V } +public abstract interface annotation class net/mamoe/mirai/LowLevelApi : java/lang/annotation/Annotation { +} + public abstract interface class net/mamoe/mirai/LowLevelApiAccessor { public fun getGroupVoiceDownloadUrl (Lnet/mamoe/mirai/Bot;[BJJ)Ljava/lang/String; public abstract fun getGroupVoiceDownloadUrl (Lnet/mamoe/mirai/Bot;[BJJLkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -3919,7 +3922,6 @@ public final class net/mamoe/mirai/message/data/Face$Companion { public abstract interface class net/mamoe/mirai/message/data/FileMessage : net/mamoe/mirai/message/code/CodableMessage, net/mamoe/mirai/message/data/ConstrainSingle, net/mamoe/mirai/message/data/MessageContent { public static final field Key Lnet/mamoe/mirai/message/data/FileMessage$Key; public static final field SERIAL_NAME Ljava/lang/String; - public fun appendMiraiCodeTo (Ljava/lang/StringBuilder;)V public fun contentToString ()Ljava/lang/String; public static fun create (Ljava/lang/String;ILjava/lang/String;J)Lnet/mamoe/mirai/message/data/FileMessage; public abstract fun getId ()Ljava/lang/String; @@ -4719,7 +4721,6 @@ public final class net/mamoe/mirai/message/data/MusicShare : net/mamoe/mirai/mes public synthetic fun (ILnet/mamoe/mirai/message/data/MusicKind;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V public fun (Lnet/mamoe/mirai/message/data/MusicKind;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V public fun (Lnet/mamoe/mirai/message/data/MusicKind;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V - public fun appendMiraiCodeTo (Ljava/lang/StringBuilder;)V public final fun component1 ()Lnet/mamoe/mirai/message/data/MusicKind; public final fun component2 ()Ljava/lang/String; public final fun component3 ()Ljava/lang/String; @@ -5323,14 +5324,12 @@ public class net/mamoe/mirai/message/data/Voice : net/mamoe/mirai/message/data/P public synthetic fun (ILjava/lang/String;[BJILjava/lang/String;Ljava/lang/String;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V public synthetic fun (Ljava/lang/String;[BJILjava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun contentToString ()Ljava/lang/String; - public fun equals (Ljava/lang/Object;)Z public static final fun fromAudio (Lnet/mamoe/mirai/message/data/Audio;)Lnet/mamoe/mirai/message/data/Voice; public fun getFileName ()Ljava/lang/String; public fun getFileSize ()J public fun getMd5 ()[B public fun getUrl ()Ljava/lang/String; public final fun get_codec ()I - public fun hashCode ()I public final fun toAudio ()Lnet/mamoe/mirai/message/data/Audio; public fun toString ()Ljava/lang/String; public static final fun write$Self (Lnet/mamoe/mirai/message/data/Voice;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V diff --git a/mirai-core-api/src/commonMain/kotlin/IMirai.kt b/mirai-core-api/src/commonMain/kotlin/IMirai.kt index 9dec7319e..0b8147ec8 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-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -72,6 +72,7 @@ public val Mirai: IMirai * * @see Mirai 获取实例 */ +@OptIn(LowLevelApi::class, MiraiExperimentalApi::class) @NotStableForInheritance public interface IMirai : LowLevelApiAccessor { /** diff --git a/mirai-core-api/src/commonMain/kotlin/LowLevelApiAccessor.kt b/mirai-core-api/src/commonMain/kotlin/LowLevelApiAccessor.kt index 960c685c5..a51f08d27 100644 --- a/mirai-core-api/src/commonMain/kotlin/LowLevelApiAccessor.kt +++ b/mirai-core-api/src/commonMain/kotlin/LowLevelApiAccessor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -14,7 +14,9 @@ package net.mamoe.mirai import kotlinx.coroutines.Job import me.him188.kotlin.jvm.blocking.bridge.JvmBlockingBridge import net.mamoe.mirai.contact.* -import net.mamoe.mirai.data.* +import net.mamoe.mirai.data.FriendInfo +import net.mamoe.mirai.data.MemberInfo +import net.mamoe.mirai.data.StrangerInfo import net.mamoe.mirai.utils.MiraiExperimentalApi import net.mamoe.mirai.utils.NotStableForInheritance import kotlin.annotation.AnnotationTarget.* @@ -26,7 +28,7 @@ import kotlin.annotation.AnnotationTarget.* * 使用低级的 API 无法带来任何安全和便捷保障. * 仅在某些使用结构化 API 可能影响性能的情况下使用这些低级 API. */ -@MiraiExperimentalApi +@LowLevelApi @RequiresOptIn @Retention(AnnotationRetention.BINARY) @Target(CLASS, FUNCTION, PROPERTY, CONSTRUCTOR) diff --git a/mirai-core-api/src/commonMain/kotlin/auth/BotAuthorization.kt b/mirai-core-api/src/commonMain/kotlin/auth/BotAuthorization.kt index 03d2db9a3..e6cd54cbe 100644 --- a/mirai-core-api/src/commonMain/kotlin/auth/BotAuthorization.kt +++ b/mirai-core-api/src/commonMain/kotlin/auth/BotAuthorization.kt @@ -59,6 +59,7 @@ public interface BotAuthorization { /** * 计算 `cache/account.secrets` 的加密秘钥 */ + @OptIn(MiraiInternalApi::class) public fun calculateSecretsKey( bot: BotAuthInfo, ): ByteArray = bot.deviceInfo.guid + bot.id.toByteArray() diff --git a/mirai-core-api/src/commonMain/kotlin/contact/ContactList.kt b/mirai-core-api/src/commonMain/kotlin/contact/ContactList.kt index 7fe3915fd..3dae32e89 100644 --- a/mirai-core-api/src/commonMain/kotlin/contact/ContactList.kt +++ b/mirai-core-api/src/commonMain/kotlin/contact/ContactList.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -32,7 +32,10 @@ public class ContactList /** * 获取一个 [Contact.id] 为 [id] 的元素. 在不存在时返回 `null`. */ - public operator fun get(id: Long): C? = delegate.firstOrNull { it.id == id } + public operator fun get(id: Long): C? { + @OptIn(MiraiInternalApi::class) + return delegate.firstOrNull { it.id == id } + } /** * 获取一个 [Contact.id] 为 [id] 的元素. 在不存在时抛出 [NoSuchElementException]. @@ -42,14 +45,28 @@ public class ContactList /** * 删除 [Contact.id] 为 [id] 的元素. */ - public fun remove(id: Long): Boolean = delegate.removeAll { it.id == id } + public fun remove(id: Long): Boolean { + @OptIn(MiraiInternalApi::class) + return delegate.removeAll { it.id == id } + } /** * 当存在 [Contact.id] 为 [id] 的元素时返回 `true`. */ public operator fun contains(id: Long): Boolean = get(id) != null - override fun toString(): String = delegate.joinToString(separator = ", ", prefix = "ContactList(", postfix = ")") - override fun equals(other: Any?): Boolean = other is ContactList<*> && delegate == other.delegate - override fun hashCode(): Int = delegate.hashCode() + override fun toString(): String { + @OptIn(MiraiInternalApi::class) + return delegate.joinToString(separator = ", ", prefix = "ContactList(", postfix = ")") + } + + override fun equals(other: Any?): Boolean { + @OptIn(MiraiInternalApi::class) + return other is ContactList<*> && delegate == other.delegate + } + + override fun hashCode(): Int { + @OptIn(MiraiInternalApi::class) + return delegate.hashCode() + } } \ No newline at end of file diff --git a/mirai-core-api/src/commonMain/kotlin/contact/ContactOrBot.kt b/mirai-core-api/src/commonMain/kotlin/contact/ContactOrBot.kt index 01ba36b13..8c4da8770 100644 --- a/mirai-core-api/src/commonMain/kotlin/contact/ContactOrBot.kt +++ b/mirai-core-api/src/commonMain/kotlin/contact/ContactOrBot.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -11,6 +11,7 @@ package net.mamoe.mirai.contact import kotlinx.coroutines.CoroutineScope import net.mamoe.mirai.Bot +import net.mamoe.mirai.utils.MiraiInternalApi import net.mamoe.mirai.utils.NotStableForInheritance import kotlin.jvm.JvmName @@ -49,5 +50,8 @@ public interface ContactOrBot : CoroutineScope { */ @Suppress("INAPPLICABLE_JVM_NAME") @JvmName("getAvatarUrl") - public fun avatarUrl(spec: AvatarSpec): String = "http://q.qlogo.cn/g?b=qq&nk=${id}&s=${spec.size}" + public fun avatarUrl(spec: AvatarSpec): String { + @OptIn(MiraiInternalApi::class) + return "http://q.qlogo.cn/g?b=qq&nk=${id}&s=${spec.size}" + } } \ No newline at end of file diff --git a/mirai-core-api/src/commonMain/kotlin/contact/Exceptions.kt b/mirai-core-api/src/commonMain/kotlin/contact/Exceptions.kt index 218b73c70..972d9d7e8 100644 --- a/mirai-core-api/src/commonMain/kotlin/contact/Exceptions.kt +++ b/mirai-core-api/src/commonMain/kotlin/contact/Exceptions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -23,7 +23,8 @@ import net.mamoe.mirai.utils.millisToHumanReadableString * * @see Contact.sendMessage */ -public class MessageTooLargeException constructor( +@OptIn(MiraiInternalApi::class) +public class MessageTooLargeException( public override val target: Contact, /** * 原发送消息 @@ -43,6 +44,7 @@ public class MessageTooLargeException constructor( * * @see Group.sendMessage */ +@OptIn(MiraiInternalApi::class) public class BotIsBeingMutedException @MiraiInternalApi constructor( // this constructor is since 2.9.0-RC public override val target: Group, diff --git a/mirai-core-api/src/commonMain/kotlin/contact/Group.kt b/mirai-core-api/src/commonMain/kotlin/contact/Group.kt index ea7e314c6..fb7826d8e 100644 --- a/mirai-core-api/src/commonMain/kotlin/contact/Group.kt +++ b/mirai-core-api/src/commonMain/kotlin/contact/Group.kt @@ -7,7 +7,7 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ -@file:Suppress("EXPERIMENTAL_API_USAGE", "unused", "UnusedImport", "NOTHING_TO_INLINE") +@file:Suppress("EXPERIMENTAL_API_USAGE", "unused", "UnusedImport") @file:JvmBlockingBridge package net.mamoe.mirai.contact @@ -23,10 +23,7 @@ import net.mamoe.mirai.contact.roaming.RoamingSupported import net.mamoe.mirai.event.events.* import net.mamoe.mirai.message.MessageReceipt import net.mamoe.mirai.message.data.* -import net.mamoe.mirai.utils.DeprecatedSinceMirai -import net.mamoe.mirai.utils.ExternalResource -import net.mamoe.mirai.utils.MiraiExperimentalApi -import net.mamoe.mirai.utils.NotStableForInheritance +import net.mamoe.mirai.utils.* import kotlin.jvm.JvmStatic import kotlin.jvm.JvmSynthetic @@ -125,7 +122,10 @@ public interface Group : Contact, CoroutineScope, FileSupported, AudioSupported, * @param spec 头像的规格. * @since 2.11 */ - public override fun avatarUrl(spec: AvatarSpec): String = "http://p.qlogo.cn/gh/${id}/${id}/${spec.size}" + public override fun avatarUrl(spec: AvatarSpec): String { + @OptIn(MiraiInternalApi::class) + return "http://p.qlogo.cn/gh/${id}/${id}/${spec.size}" + } /** * 群成员列表, 不含机器人自己, 含群主. @@ -211,7 +211,7 @@ public interface Group : Contact, CoroutineScope, FileSupported, AudioSupported, /** * 上传一个语音消息以备发送. 该方法已弃用且将在未来版本删除, 请使用 [uploadAudio]. */ - @Suppress("DEPRECATION", "DEPRECATION_ERROR") + @Suppress("DEPRECATION_ERROR") @Deprecated( "use uploadAudio", replaceWith = ReplaceWith("uploadAudio(resource)"), @@ -312,13 +312,13 @@ public interface GroupSettings { * 同 [get]. 在一些不适合使用 [get] 的情境下使用 [getMember]. */ @JvmSynthetic -public inline fun Group.getMember(id: Long): NormalMember? = get(id) +public fun Group.getMember(id: Long): NormalMember? = get(id) /** * 同 [getMemberOrFail]. 在一些不适合使用 [getOrFail] 的情境下使用 [getMemberOrFail]. */ @JvmSynthetic -public inline fun Group.getMemberOrFail(id: Long): NormalMember = getOrFail(id) +public fun Group.getMemberOrFail(id: Long): NormalMember = getOrFail(id) /** @@ -326,5 +326,5 @@ public inline fun Group.getMemberOrFail(id: Long): NormalMember = getOrFail(id) * * @see Group.botMuteRemaining 剩余禁言时间 */ -public inline val Group.isBotMuted: Boolean get() = this.botMuteRemaining != 0 +public val Group.isBotMuted: Boolean get() = this.botMuteRemaining != 0 diff --git a/mirai-core-api/src/commonMain/kotlin/contact/OtherClient.kt b/mirai-core-api/src/commonMain/kotlin/contact/OtherClient.kt index 20fde162c..b6e5007dd 100644 --- a/mirai-core-api/src/commonMain/kotlin/contact/OtherClient.kt +++ b/mirai-core-api/src/commonMain/kotlin/contact/OtherClient.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -40,7 +40,11 @@ public interface OtherClient : Contact { * * 此 id 由其他客户端控制, 重启可能会变化. */ - public override val id: Long get() = info.appId.toLongUnsigned() + public override val id: Long + get() { + @OptIn(MiraiInternalApi::class) + return info.appId.toLongUnsigned() + } override suspend fun sendMessage(message: Message): MessageReceipt { throw UnsupportedOperationException("OtherClientImpl.sendMessage is not yet supported.") diff --git a/mirai-core-api/src/commonMain/kotlin/data/RequestEventData.kt b/mirai-core-api/src/commonMain/kotlin/data/RequestEventData.kt index 2763f7eec..13923825e 100644 --- a/mirai-core-api/src/commonMain/kotlin/data/RequestEventData.kt +++ b/mirai-core-api/src/commonMain/kotlin/data/RequestEventData.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -15,6 +15,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import me.him188.kotlin.jvm.blocking.bridge.JvmBlockingBridge import net.mamoe.mirai.Bot +import net.mamoe.mirai.LowLevelApi import net.mamoe.mirai.Mirai import net.mamoe.mirai.event.events.BotInvitedJoinGroupRequestEvent import net.mamoe.mirai.event.events.MemberJoinRequestEvent @@ -48,6 +49,7 @@ public sealed class RequestEventData { public val message: String, ) : RequestEventData() { + @OptIn(LowLevelApi::class) override suspend fun accept(bot: Bot) { Mirai.solveNewFriendRequestEvent( bot, @@ -64,6 +66,7 @@ public sealed class RequestEventData { } @JvmBlockingBridge + @OptIn(LowLevelApi::class) public suspend fun reject(bot: Bot, blackList: Boolean) { Mirai.solveNewFriendRequestEvent( bot, @@ -93,6 +96,7 @@ public sealed class RequestEventData { public val groupName: String, ) : RequestEventData() { override suspend fun accept(bot: Bot) { + @OptIn(LowLevelApi::class) Mirai.solveBotInvitedJoinGroupRequestEvent( bot, eventId = eventId, @@ -103,6 +107,7 @@ public sealed class RequestEventData { } override suspend fun reject(bot: Bot) { + @OptIn(LowLevelApi::class) Mirai.solveBotInvitedJoinGroupRequestEvent( bot, eventId = eventId, @@ -134,6 +139,7 @@ public sealed class RequestEventData { public val message: String, ) : RequestEventData() { override suspend fun accept(bot: Bot) { + @OptIn(LowLevelApi::class) Mirai.solveMemberJoinRequestEvent( bot, eventId = eventId, @@ -158,6 +164,7 @@ public sealed class RequestEventData { @JvmBlockingBridge @JvmOverloads public suspend fun reject(bot: Bot, blackList: Boolean, message: String = "") { + @OptIn(LowLevelApi::class) Mirai.solveMemberJoinRequestEvent( bot, eventId = eventId, @@ -181,6 +188,7 @@ public sealed class RequestEventData { @JvmStatic @JvmName("from") public fun NewFriendRequestEvent.toRequestEventData(): NewFriendRequest { + @OptIn(MiraiExperimentalApi::class) return NewFriendRequest( eventId = eventId, message = message, @@ -193,6 +201,7 @@ public sealed class RequestEventData { @JvmStatic @JvmName("from") public fun BotInvitedJoinGroupRequestEvent.toRequestEventData(): BotInvitedJoinGroupRequest { + @OptIn(MiraiExperimentalApi::class) return BotInvitedJoinGroupRequest( eventId = eventId, invitor = invitorId, @@ -205,6 +214,7 @@ public sealed class RequestEventData { @JvmStatic @JvmName("from") public fun MemberJoinRequestEvent.toRequestEventData(): MemberJoinRequest { + @OptIn(MiraiExperimentalApi::class) return MemberJoinRequest( eventId = eventId, requester = fromId, diff --git a/mirai-core-api/src/commonMain/kotlin/data/StrangerInfo.kt b/mirai-core-api/src/commonMain/kotlin/data/StrangerInfo.kt index d68337841..7437bcc15 100644 --- a/mirai-core-api/src/commonMain/kotlin/data/StrangerInfo.kt +++ b/mirai-core-api/src/commonMain/kotlin/data/StrangerInfo.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -10,7 +10,9 @@ package net.mamoe.mirai.data import net.mamoe.mirai.LowLevelApi +import net.mamoe.mirai.utils.MiraiExperimentalApi +@OptIn(MiraiExperimentalApi::class) @LowLevelApi public interface StrangerInfo : UserInfo { /** diff --git a/mirai-core-api/src/commonMain/kotlin/data/UserInfo.kt b/mirai-core-api/src/commonMain/kotlin/data/UserInfo.kt index edf537543..e0402dc2f 100644 --- a/mirai-core-api/src/commonMain/kotlin/data/UserInfo.kt +++ b/mirai-core-api/src/commonMain/kotlin/data/UserInfo.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. diff --git a/mirai-core-api/src/commonMain/kotlin/event/Event.kt b/mirai-core-api/src/commonMain/kotlin/event/Event.kt index eced4cee7..18f702fde 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/Event.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/Event.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -93,12 +93,16 @@ public abstract class AbstractEvent : Event { * @see Event.isIntercepted */ public override val isIntercepted: Boolean - get() = _intercepted + get() { + @OptIn(MiraiInternalApi::class) + return _intercepted + } /** * @see Event.intercept */ public override fun intercept() { + @OptIn(MiraiInternalApi::class) _intercepted = true } diff --git a/mirai-core-api/src/commonMain/kotlin/event/EventChannel.kt b/mirai-core-api/src/commonMain/kotlin/event/EventChannel.kt index 531abe776..0a3575d5f 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/EventChannel.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/EventChannel.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -508,6 +508,7 @@ public expect abstract class EventChannel @MiraiInternalA // used by mirai-core +@OptIn(MiraiInternalApi::class) internal open class FilterEventChannel( private val delegate: EventChannel, private val filter: suspend (event: BaseEvent) -> Boolean, diff --git a/mirai-core-api/src/commonMain/kotlin/event/GlobalEventChannel.kt b/mirai-core-api/src/commonMain/kotlin/event/GlobalEventChannel.kt index 417a00b5d..c5778c1fc 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/GlobalEventChannel.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/GlobalEventChannel.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -29,6 +29,7 @@ import kotlin.reflect.KClass * * @see EventChannel */ +@OptIn(MiraiInternalApi::class) public object GlobalEventChannel : EventChannel(Event::class, EmptyCoroutineContext) { private val instance by lazy { loadService(InternalGlobalEventChannelProvider::class).getInstance() diff --git a/mirai-core-api/src/commonMain/kotlin/event/MessageSelectBuilderUnit.kt b/mirai-core-api/src/commonMain/kotlin/event/MessageSelectBuilderUnit.kt index 1b8711839..571fa5a87 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/MessageSelectBuilderUnit.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/MessageSelectBuilderUnit.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -23,6 +23,7 @@ import net.mamoe.mirai.utils.MiraiInternalApi * * @see MessageSubscribersBuilder 查看上层 API */ +@OptIn(MiraiInternalApi::class) public expect abstract class MessageSelectBuilderUnit @PublishedApi internal constructor( ownerMessagePacket: M, stub: Any?, @@ -50,7 +51,6 @@ public abstract class CommonMessageSelectBuilderUnit protec /** * 限制本次 select 的最长等待时间, 当超时后抛出 [TimeoutCancellationException] */ - @Suppress("NOTHING_TO_INLINE") @MessageDsl public fun timeoutException( timeoutMillis: Long, diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/ImageUploadEvent.kt b/mirai-core-api/src/commonMain/kotlin/event/events/ImageUploadEvent.kt index 3a9cae991..5af71580d 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/ImageUploadEvent.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/ImageUploadEvent.kt @@ -35,6 +35,7 @@ import kotlin.jvm.JvmName * * @see Contact.uploadImage 上传图片. 为广播这个事件的唯一途径 */ +@OptIn(MiraiInternalApi::class) public data class BeforeImageUploadEvent @MiraiInternalApi constructor( public val target: Contact, public val source: ExternalResource @@ -54,6 +55,7 @@ public data class BeforeImageUploadEvent @MiraiInternalApi constructor( * @see Succeed * @see Failed */ +@OptIn(MiraiInternalApi::class) public sealed class ImageUploadEvent : BotEvent, BotActiveEvent, AbstractEvent(), VerboseEvent { public abstract val target: Contact public abstract val source: ExternalResource diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/MessageEvent.kt b/mirai-core-api/src/commonMain/kotlin/event/events/MessageEvent.kt index f1aeddb5a..f2915f41e 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/MessageEvent.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/MessageEvent.kt @@ -45,6 +45,7 @@ import kotlin.jvm.JvmName * * 使用 [MessageEvent.isContextIdenticalWith] 可判断两个 [MessageEvent] 的语境是否相同. 有关"语境"的定义可查看 [MessageEvent.isContextIdenticalWith]. */ +@OptIn(MiraiInternalApi::class) public sealed interface MessageEvent : Event, Packet, BotPassiveEvent { /** * 与这个消息事件相关的 [Bot] @@ -109,7 +110,8 @@ public sealed interface UserMessageEvent : MessageEvent { * * @see MessageEvent */ -public class FriendMessageEvent constructor( +@OptIn(MiraiInternalApi::class) +public class FriendMessageEvent( public override val sender: Friend, public override val message: MessageChain, public override val time: Int @@ -134,7 +136,8 @@ public class FriendMessageEvent constructor( * * @see MessageEvent */ -public class OtherClientMessageEvent constructor( +@OptIn(MiraiInternalApi::class) +public class OtherClientMessageEvent( public override val client: OtherClient, public override val message: MessageChain, public override val time: Int @@ -173,6 +176,7 @@ public sealed interface GroupAwareMessageEvent : MessageEvent { * * @see MessageEvent */ +@OptIn(MiraiInternalApi::class) public class GroupMessageEvent( public override val senderName: String, /** @@ -205,13 +209,14 @@ public class GroupMessageEvent( * * @see MessageEvent */ +@OptIn(MiraiInternalApi::class) @Deprecated( "mirai 正计划支持其他渠道发起的临时会话, 届时此事件会变动. 原 TempMessageEvent 已更改为 GroupTempMessageEvent", replaceWith = ReplaceWith("GroupTempMessageEvent", "net.mamoe.mirai.event.events.GroupTempMessageEvent"), DeprecationLevel.HIDDEN ) @DeprecatedSinceMirai(hiddenSince = "2.0") // maybe 2.0 -public sealed class TempMessageEvent constructor( +public sealed class TempMessageEvent( public override val sender: NormalMember, public override val message: MessageChain, public override val time: Int @@ -254,7 +259,8 @@ public class GroupTempMessageEvent( * * @see MessageEvent */ -public class StrangerMessageEvent constructor( +@OptIn(MiraiInternalApi::class) +public class StrangerMessageEvent( public override val sender: Stranger, public override val message: MessageChain, public override val time: Int diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/MessagePostSendEvent.kt b/mirai-core-api/src/commonMain/kotlin/event/events/MessagePostSendEvent.kt index 78fd091a8..1b7f73c14 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/MessagePostSendEvent.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/MessagePostSendEvent.kt @@ -37,6 +37,7 @@ import kotlin.jvm.JvmSynthetic * @see Contact.sendMessage 发送消息. 为广播这个事件的唯一途径 * @see MessagePreSendEvent */ +@OptIn(MiraiInternalApi::class) public sealed class MessagePostSendEvent : BotEvent, BotActiveEvent, AbstractEvent(), VerboseEvent { /** 发信目标. */ public abstract val target: C @@ -184,6 +185,7 @@ public sealed class TempMessagePostSendEvent @MiraiInternalApi constructor( * 在群临时会话消息发送后广播的事件. * @see MessagePostSendEvent */ +@OptIn(MiraiInternalApi::class) public data class GroupTempMessagePostSendEvent @MiraiInternalApi constructor( /** 发信目标. */ public override val target: NormalMember, diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/MessagePreSendEvent.kt b/mirai-core-api/src/commonMain/kotlin/event/events/MessagePreSendEvent.kt index 535a47ce8..0a05b1094 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/MessagePreSendEvent.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/MessagePreSendEvent.kt @@ -36,6 +36,7 @@ import kotlin.jvm.JvmName * * @see Contact.sendMessage 发送消息. 为广播这个事件的唯一途径 */ +@OptIn(MiraiInternalApi::class) public sealed class MessagePreSendEvent : BotEvent, BotActiveEvent, AbstractEvent(), CancellableEvent, VerboseEvent { /** 发信目标. */ public abstract val target: Contact @@ -102,6 +103,7 @@ public sealed class TempMessagePreSendEvent @MiraiInternalApi constructor( * 在发送群临时会话消息前广播的事件. * @see MessagePreSendEvent */ +@OptIn(MiraiInternalApi::class) public data class GroupTempMessagePreSendEvent @MiraiInternalApi constructor( /** 发信目标. */ public override val target: NormalMember, diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/MessageRecallEvent.kt b/mirai-core-api/src/commonMain/kotlin/event/events/MessageRecallEvent.kt index 0cf005c99..32adf8e2c 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/MessageRecallEvent.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/MessageRecallEvent.kt @@ -59,6 +59,7 @@ public sealed class MessageRecallEvent : BotEvent, AbstractEvent() { /** * 好友消息撤回事件 */ + @OptIn(MiraiInternalApi::class) public data class FriendRecall @MiraiInternalApi public constructor( public override val bot: Bot, public override val messageIds: IntArray, @@ -88,9 +89,7 @@ public sealed class MessageRecallEvent : BotEvent, AbstractEvent() { if (!messageInternalIds.contentEquals(other.messageInternalIds)) return false if (messageTime != other.messageTime) return false if (operatorId != other.operatorId) return false - if (operator != other.operator) return false - - return true + return operator == other.operator } override fun hashCode(): Int { @@ -107,6 +106,7 @@ public sealed class MessageRecallEvent : BotEvent, AbstractEvent() { /** * 群消息撤回事件. */ + @OptIn(MiraiInternalApi::class) public data class GroupRecall @MiraiInternalApi constructor( public override val bot: Bot, public override val authorId: Long, @@ -133,9 +133,7 @@ public sealed class MessageRecallEvent : BotEvent, AbstractEvent() { if (messageTime != other.messageTime) return false if (operator != other.operator) return false if (group != other.group) return false - if (author != other.author) return false - - return true + return author == other.author } override fun hashCode(): Int { diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/MessageSyncEvent.kt b/mirai-core-api/src/commonMain/kotlin/event/events/MessageSyncEvent.kt index d0707e965..03af316e4 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/MessageSyncEvent.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/MessageSyncEvent.kt @@ -19,6 +19,7 @@ import net.mamoe.mirai.message.data.MessageSource import net.mamoe.mirai.message.data.OnlineMessageSource import net.mamoe.mirai.message.data.source import net.mamoe.mirai.utils.DeprecatedSinceMirai +import net.mamoe.mirai.utils.MiraiInternalApi import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName @@ -40,12 +41,13 @@ public interface MessageSyncEvent : MessageEvent, OtherClientEvent { * * @see MessageSyncEvent */ +@OptIn(MiraiInternalApi::class) public class GroupTempMessageSyncEvent private constructor( private val _client: OtherClient?, public override val sender: NormalMember, public override val message: MessageChain, public override val time: Int, - @Suppress("UNUSED_PARAMETER") _primaryConstructorMark: Any? + @Suppress("UNUSED_PARAMETER", "LocalVariableName") _primaryConstructorMark: Any? ) : AbstractMessageEvent(), GroupAwareMessageEvent, MessageSyncEvent { /** * @since 2.13 @@ -93,12 +95,13 @@ public class GroupTempMessageSyncEvent private constructor( * * @see MessageSyncEvent */ +@OptIn(MiraiInternalApi::class) public class FriendMessageSyncEvent private constructor( private val _client: OtherClient?, public override val sender: Friend, public override val message: MessageChain, public override val time: Int, - @Suppress("UNUSED_PARAMETER") _primaryConstructorMark: Any? + @Suppress("UNUSED_PARAMETER", "LocalVariableName") _primaryConstructorMark: Any? ) : AbstractMessageEvent(), FriendEvent, MessageSyncEvent { /** * @since 2.13 @@ -147,12 +150,13 @@ public class FriendMessageSyncEvent private constructor( * * @see MessageSyncEvent */ +@OptIn(MiraiInternalApi::class) public class StrangerMessageSyncEvent private constructor( private val _client: OtherClient?, public override val sender: Stranger, public override val message: MessageChain, public override val time: Int, - @Suppress("UNUSED_PARAMETER") _primaryConstructorMark: Any?, + @Suppress("UNUSED_PARAMETER", "LocalVariableName") _primaryConstructorMark: Any?, ) : AbstractMessageEvent(), StrangerEvent, MessageSyncEvent { /** * @since 2.13 @@ -201,6 +205,7 @@ public class StrangerMessageSyncEvent private constructor( * * @see MessageSyncEvent */ +@OptIn(MiraiInternalApi::class) public class GroupMessageSyncEvent private constructor( private val _client: OtherClient?, public override val group: Group, @@ -208,7 +213,7 @@ public class GroupMessageSyncEvent private constructor( public override val sender: Member, public override val senderName: String, public override val time: Int, - @Suppress("UNUSED_PARAMETER") _primaryConstructorMark: Any?, + @Suppress("UNUSED_PARAMETER", "LocalVariableName") _primaryConstructorMark: Any?, ) : AbstractMessageEvent(), GroupAwareMessageEvent, MessageSyncEvent { /** * @since 2.13 diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/NudgeEvent.kt b/mirai-core-api/src/commonMain/kotlin/event/events/NudgeEvent.kt index da119a170..3a8ddfb99 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/NudgeEvent.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/NudgeEvent.kt @@ -9,6 +9,7 @@ @file:JvmMultifileClass @file:JvmName("BotEventsKt") +@file:OptIn(MiraiInternalApi::class) package net.mamoe.mirai.event.events diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/SignEvent.kt b/mirai-core-api/src/commonMain/kotlin/event/events/SignEvent.kt index b2acd4229..bf98228e1 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/SignEvent.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/SignEvent.kt @@ -9,11 +9,14 @@ @file:JvmMultifileClass @file:JvmName("BotEventsKt") +@file:OptIn(MiraiInternalApi::class) package net.mamoe.mirai.event.events import net.mamoe.mirai.Bot -import net.mamoe.mirai.contact.* +import net.mamoe.mirai.contact.Friend +import net.mamoe.mirai.contact.Member +import net.mamoe.mirai.contact.UserOrBot import net.mamoe.mirai.event.AbstractEvent import net.mamoe.mirai.internal.network.Packet import net.mamoe.mirai.utils.MiraiInternalApi diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/bot.kt b/mirai-core-api/src/commonMain/kotlin/event/events/bot.kt index c81a4baa3..a295048d1 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/bot.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/bot.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -10,6 +10,7 @@ @file:Suppress("unused", "FunctionName") @file:JvmMultifileClass @file:JvmName("BotEventsKt") +@file:OptIn(MiraiInternalApi::class) package net.mamoe.mirai.event.events @@ -47,6 +48,7 @@ public sealed class BotOfflineEvent : BotEvent, AbstractEvent() { * * 主动广播这个事件也可以让 [Bot] 离线, 但不建议这么做. 建议调用 [Bot.close]. */ + @OptIn(MiraiExperimentalApi::class) public data class Active( public override val bot: Bot, public override val cause: Throwable? @@ -76,6 +78,7 @@ public sealed class BotOfflineEvent : BotEvent, AbstractEvent() { /** * 被服务器断开 */ + @OptIn(MiraiExperimentalApi::class) @MiraiInternalApi("This is very experimental and might be changed") public data class MsfOffline @MiraiInternalApi public constructor( public override val bot: Bot, @@ -91,7 +94,9 @@ public sealed class BotOfflineEvent : BotEvent, AbstractEvent() { /** * 因网络问题而掉线 */ - public data class Dropped @MiraiInternalApi public constructor( + @OptIn(MiraiExperimentalApi::class) + public data class Dropped + @MiraiInternalApi public constructor( public override val bot: Bot, public override val cause: Throwable? ) : BotOfflineEvent(), Packet, BotPassiveEvent, CauseAware { @@ -105,6 +110,7 @@ public sealed class BotOfflineEvent : BotEvent, AbstractEvent() { /** * 服务器主动要求更换另一个服务器 */ + @OptIn(MiraiExperimentalApi::class) @MiraiInternalApi public data class RequireReconnect @MiraiInternalApi public constructor( public override val bot: Bot, override val cause: Throwable?, diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/friend.kt b/mirai-core-api/src/commonMain/kotlin/event/events/friend.kt index 8c2a314d2..25198ffb1 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/friend.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/friend.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -10,11 +10,10 @@ @file:JvmMultifileClass @file:JvmName("BotEventsKt") @file:Suppress("FunctionName", "unused", "DEPRECATION_ERROR") +@file:OptIn(MiraiInternalApi::class) package net.mamoe.mirai.event.events -import kotlinx.atomicfu.AtomicBoolean -import kotlinx.atomicfu.atomic import me.him188.kotlin.jvm.blocking.bridge.JvmBlockingBridge import net.mamoe.mirai.Bot import net.mamoe.mirai.Mirai @@ -62,7 +61,6 @@ public data class FriendDeleteEvent @MiraiInternalApi public constructor( /** * 一个账号请求添加机器人为好友的事件 */ -@Suppress("DEPRECATION") public data class NewFriendRequestEvent @MiraiInternalApi public constructor( public override val bot: Bot, /** diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/group.kt b/mirai-core-api/src/commonMain/kotlin/event/events/group.kt index e29442f39..0d642caef 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/group.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/group.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -13,6 +13,7 @@ "FunctionName", "INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "DEPRECATION_ERROR", "MemberVisibilityCanBePrivate" ) +@file:OptIn(MiraiInternalApi::class) package net.mamoe.mirai.event.events @@ -337,7 +338,6 @@ public sealed class MemberLeaveEvent : GroupMemberEvent, AbstractEvent(), GroupM /** * [Bot] 被邀请加入一个群. */ -@Suppress("DEPRECATION") public data class BotInvitedJoinGroupRequestEvent @MiraiInternalApi constructor( public override val bot: Bot, /** diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/stranger.kt b/mirai-core-api/src/commonMain/kotlin/event/events/stranger.kt index d7e24b36d..6f6b88b0a 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/stranger.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/stranger.kt @@ -1,12 +1,14 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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:OptIn(MiraiInternalApi::class) + package net.mamoe.mirai.event.events import net.mamoe.mirai.Bot diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/types.kt b/mirai-core-api/src/commonMain/kotlin/event/events/types.kt index 87eb8fa14..a5dd059a5 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/types.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/types.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -127,6 +127,7 @@ internal interface GroupMemberInfoChangeEvent : BotEvent, GroupEvent, BaseGroupM override val groupId: Long get() = group.id } // for cache +@OptIn(MiraiInternalApi::class) public interface OtherClientEvent : BotEvent, Packet { public val client: OtherClient override val bot: Bot get() = client.bot diff --git a/mirai-core-api/src/commonMain/kotlin/internal/message/AbstractPolymorphicSerializer.kt b/mirai-core-api/src/commonMain/kotlin/internal/message/AbstractPolymorphicSerializer.kt index cc52d104a..a9d315bdc 100644 --- a/mirai-core-api/src/commonMain/kotlin/internal/message/AbstractPolymorphicSerializer.kt +++ b/mirai-core-api/src/commonMain/kotlin/internal/message/AbstractPolymorphicSerializer.kt @@ -7,12 +7,11 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(ExperimentalSerializationApi::class) + package net.mamoe.mirai.internal.message -import kotlinx.serialization.DeserializationStrategy -import kotlinx.serialization.KSerializer -import kotlinx.serialization.SerializationException -import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.* import kotlinx.serialization.encoding.* import net.mamoe.mirai.utils.cast import kotlin.jvm.JvmName diff --git a/mirai-core-api/src/commonMain/kotlin/internal/message/MessageSerializersImpl.kt b/mirai-core-api/src/commonMain/kotlin/internal/message/MessageSerializersImpl.kt index 2ac201601..a0f5eff8d 100644 --- a/mirai-core-api/src/commonMain/kotlin/internal/message/MessageSerializersImpl.kt +++ b/mirai-core-api/src/commonMain/kotlin/internal/message/MessageSerializersImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -17,11 +17,11 @@ import kotlinx.serialization.modules.SerializersModule import kotlinx.serialization.modules.overwriteWith import net.mamoe.mirai.Mirai import net.mamoe.mirai.message.MessageSerializers -import net.mamoe.mirai.message.data.* -import net.mamoe.mirai.utils.MiraiInternalApi -import net.mamoe.mirai.utils.lateinitMutableProperty -import net.mamoe.mirai.utils.map -import net.mamoe.mirai.utils.takeElementsFrom +import net.mamoe.mirai.message.data.MessageChain +import net.mamoe.mirai.message.data.MessageSource +import net.mamoe.mirai.message.data.MessageSourceKind +import net.mamoe.mirai.message.data.SingleMessage +import net.mamoe.mirai.utils.* import kotlin.jvm.Synchronized import kotlin.reflect.KClass @@ -61,6 +61,7 @@ public open class MessageSourceSerializerImpl(serialName: String) : // Tests: // net.mamoe.mirai.internal.message.data.MessageSerializationTest +@OptIn(MiraiExperimentalApi::class) internal object MessageSerializersImpl : MessageSerializers { private var serializersModuleField: SerializersModule by lateinitMutableProperty { SerializersModule { } diff --git a/mirai-core-api/src/commonMain/kotlin/internal/utils/StdoutLogger.kt b/mirai-core-api/src/commonMain/kotlin/internal/utils/StdoutLogger.kt index 13d34314c..9143b78e4 100644 --- a/mirai-core-api/src/commonMain/kotlin/internal/utils/StdoutLogger.kt +++ b/mirai-core-api/src/commonMain/kotlin/internal/utils/StdoutLogger.kt @@ -37,6 +37,7 @@ import net.mamoe.mirai.utils.* * @see SingleFileLogger 使用单一文件记录日志 * @see DirectoryLogger 在一个目录中按日期存放文件记录日志, 自动清理过期日志 */ +@OptIn(MiraiExperimentalApi::class) internal open class StdoutLogger constructor( override val identity: String? = "Mirai", /** diff --git a/mirai-core-api/src/commonMain/kotlin/message/code/CodableMessage.kt b/mirai-core-api/src/commonMain/kotlin/message/code/CodableMessage.kt index eb0625dea..b837734e8 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/code/CodableMessage.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/code/CodableMessage.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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,7 +30,10 @@ public interface CodableMessage : Message { /** * 转换为 mirai 码. */ - public fun serializeToMiraiCode(): String = buildString { appendMiraiCodeTo(this) } + public fun serializeToMiraiCode(): String = buildString { + @OptIn(MiraiExperimentalApi::class) + appendMiraiCodeTo(this) + } // Using StringBuilder faster than direct plus objects @MiraiExperimentalApi diff --git a/mirai-core-api/src/commonMain/kotlin/message/code/MiraiCode.kt b/mirai-core-api/src/commonMain/kotlin/message/code/MiraiCode.kt index 0749f89fc..93e6b2c0d 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/code/MiraiCode.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/code/MiraiCode.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,7 +7,7 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ -@file:Suppress("unused", "NOTHING_TO_INLINE") +@file:Suppress("unused") package net.mamoe.mirai.message.code @@ -16,6 +16,7 @@ import net.mamoe.mirai.message.code.internal.parseMiraiCodeImpl import net.mamoe.mirai.message.data.Message import net.mamoe.mirai.message.data.MessageChain import net.mamoe.mirai.message.data.MessageChain.Companion.deserializeFromMiraiCode +import net.mamoe.mirai.utils.MiraiExperimentalApi import net.mamoe.mirai.utils.safeCast import kotlin.jvm.JvmName import kotlin.jvm.JvmOverloads @@ -34,7 +35,7 @@ public object MiraiCode { */ @JvmName("parseMiraiCode1") @JvmSynthetic - public inline fun String.deserializeMiraiCode(contact: Contact? = null): MessageChain = + public fun String.deserializeMiraiCode(contact: Contact? = null): MessageChain = deserializeMiraiCode(this, contact) /** @@ -69,6 +70,7 @@ public object MiraiCode { */ @JvmStatic public fun Iterator.serializeToMiraiCode(): String = buildString { + @OptIn(MiraiExperimentalApi::class) this@serializeToMiraiCode.forEach { it.safeCast()?.appendMiraiCodeTo(this) } diff --git a/mirai-core-api/src/commonMain/kotlin/message/code/internal/impl.kt b/mirai-core-api/src/commonMain/kotlin/message/code/internal/impl.kt index b8834f062..862d5348b 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/code/internal/impl.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/code/internal/impl.kt @@ -1,10 +1,10 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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("INVISIBLE_MEMBER") @@ -13,6 +13,8 @@ package net.mamoe.mirai.message.code.internal import net.mamoe.mirai.contact.Contact import net.mamoe.mirai.message.data.* +import net.mamoe.mirai.utils.MiraiExperimentalApi +import net.mamoe.mirai.utils.MiraiInternalApi internal fun String.parseMiraiCodeImpl(contact: Contact?): MessageChain = buildMessageChain { @@ -91,6 +93,7 @@ private fun String.forEachMiraiCode(block: (origin: String, name: String?, args: } } +@OptIn(MiraiInternalApi::class, MiraiExperimentalApi::class) @Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE") private object MiraiCodeParsers : AbstractMap(), Map by mapOf( "at" to MiraiCodeParser(Regex("""(\d*)""")) { (target) -> diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/CustomMessage.kt b/mirai-core-api/src/commonMain/kotlin/message/data/CustomMessage.kt index 3b245ecdd..54449b637 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/CustomMessage.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/CustomMessage.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -10,6 +10,7 @@ package net.mamoe.mirai.message.data import io.ktor.utils.io.core.* +import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json @@ -92,7 +93,10 @@ public sealed class CustomMessage : SingleMessage { */ public abstract fun serializer(): KSerializer + @OptIn(ExperimentalSerializationApi::class) public override fun dump(message: M): ByteArray = ProtoBuf.encodeToByteArray(serializer(), message) + + @OptIn(ExperimentalSerializationApi::class) public override fun load(input: ByteArray): M = ProtoBuf.decodeFromByteArray(serializer(), input) } @@ -127,7 +131,7 @@ public sealed class CustomMessage : SingleMessage { } @Serializable - private class CustomMessageFullData( + private class CustomMessageFullData @OptIn(ExperimentalSerializationApi::class) constructor( @ProtoNumber(1) val miraiVersionFlag: Int, @ProtoNumber(2) val typeName: String, @ProtoNumber(3) val data: ByteArray @@ -137,6 +141,7 @@ public sealed class CustomMessage : SingleMessage { public class CustomMessageFullDataDeserializeUserException(public val body: ByteArray, cause: Throwable?) : RuntimeException(cause) + @OptIn(ExperimentalSerializationApi::class) @MiraiInternalApi public fun load(fullData: ByteReadPacket): CustomMessage? { val msg = kotlin.runCatching { @@ -158,6 +163,7 @@ public sealed class CustomMessage : SingleMessage { } } + @OptIn(ExperimentalSerializationApi::class) @MiraiInternalApi public fun dump(factory: Factory, message: M): ByteArray = buildPacket { ProtoBuf.encodeToByteArray( @@ -213,8 +219,8 @@ public abstract class CustomMessageMetadata : CustomMessage(), MessageMetadata { } -@Suppress("NOTHING_TO_INLINE") -internal inline fun T.customToStringImpl(factory: CustomMessage.Factory<*>): ByteArray { +@OptIn(MiraiExperimentalApi::class) +internal fun T.customToStringImpl(factory: CustomMessage.Factory<*>): ByteArray { @Suppress("UNCHECKED_CAST") return (factory as CustomMessage.Factory).dump(this) } diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/FileMessage.kt b/mirai-core-api/src/commonMain/kotlin/message/data/FileMessage.kt index 62cd5bea4..5ee48b71b 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/FileMessage.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/FileMessage.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,7 +7,6 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ -@file:Suppress("NOTHING_TO_INLINE") @file:JvmMultifileClass @file:JvmName("MessageUtils") @@ -23,6 +22,7 @@ import net.mamoe.mirai.contact.file.AbsoluteFile import net.mamoe.mirai.event.events.MessageEvent import net.mamoe.mirai.message.code.CodableMessage import net.mamoe.mirai.message.data.visitor.MessageVisitor +import net.mamoe.mirai.utils.MiraiExperimentalApi import net.mamoe.mirai.utils.MiraiInternalApi import net.mamoe.mirai.utils.NotStableForInheritance import net.mamoe.mirai.utils.map @@ -75,6 +75,7 @@ public expect interface FileMessage : MessageContent, ConstrainSingle, CodableMe open override fun contentToString(): String + @MiraiExperimentalApi open override fun appendMiraiCodeTo(builder: StringBuilder) /** @@ -119,7 +120,7 @@ internal open class FallbackFileMessageSerializer : @Suppress("ANNOTATION_ARGUMENT_MUST_BE_CONST") @SerialName(FileMessage.SERIAL_NAME) @Serializable - data class Delegate constructor( + data class Delegate( val id: String, val internalId: Int, val name: String, @@ -133,5 +134,5 @@ internal open class FallbackFileMessageSerializer : */ @JvmSynthetic @CName("", "FileMessage_new") -public inline fun FileMessage(id: String, internalId: Int, name: String, size: Long): FileMessage = +public fun FileMessage(id: String, internalId: Int, name: String, size: Long): FileMessage = FileMessage.create(id, internalId, name, size) \ No newline at end of file diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/FlashImage.kt b/mirai-core-api/src/commonMain/kotlin/message/data/FlashImage.kt index 750468bf3..d2d8a8bd8 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/FlashImage.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/FlashImage.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -42,6 +42,7 @@ import kotlin.native.CName * * @see Image 查看图片相关信息 */ +@OptIn(MiraiExperimentalApi::class) @Serializable @SerialName(FlashImage.SERIAL_NAME) public data class FlashImage( diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/ForwardMessage.kt b/mirai-core-api/src/commonMain/kotlin/message/data/ForwardMessage.kt index 6595e738c..8916a2122 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/ForwardMessage.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/ForwardMessage.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -165,6 +165,7 @@ public data class ForwardMessage( /** * 消息节点 */ + @OptIn(MiraiExperimentalApi::class) @Serializable public data class Node( /** @@ -394,6 +395,7 @@ public annotation class ForwardMessageDsl * * `S named "name1" named "name2" says M` 最终的发送人名称为 `"name2"` */ +@OptIn(MiraiExperimentalApi::class) public class ForwardMessageBuilder private constructor( /** * 消息语境. 可为 [Group] 或 [User]. 用来确定某 ID 的用户的昵称. @@ -769,6 +771,7 @@ public class ForwardMessageBuilder private constructor( } } +@OptIn(MiraiExperimentalApi::class) private fun ForwardMessage.INode.toNode(): ForwardMessage.Node { return ForwardMessage.Node(senderId, time, senderName, messageChain) } diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/Image.kt b/mirai-core-api/src/commonMain/kotlin/message/data/Image.kt index d67e32ce0..01ad46299 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/Image.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/Image.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -14,11 +14,12 @@ "EXPERIMENTAL_API_USAGE", "unused", "UnusedImport", - "DEPRECATION_ERROR", "NOTHING_TO_INLINE", "MemberVisibilityCanBePrivate" + "DEPRECATION_ERROR", "MemberVisibilityCanBePrivate" ) package net.mamoe.mirai.message.data +import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -189,6 +190,7 @@ public interface Image : Message, MessageContent, CodableMessage { deserialize = { Image(it) }, ) + @OptIn(MiraiInternalApi::class) @Deprecated( message = "For internal use only. Deprecated for removal. Please retrieve serializer from MessageSerializers.serializersModule.", level = DeprecationLevel.WARNING @@ -212,7 +214,8 @@ public interface Image : Message, MessageContent, CodableMessage { // Without this implementation you will need `ignoreUnknownKeys` on deserialization. override fun deserialize(decoder: Decoder): Image { return decoder.decodeStructure(descriptor) { - if (this.decodeSequentially()) { + @OptIn(ExperimentalSerializationApi::class) + if (runCatching { this.decodeSequentially() }.getOrElse { false }) { val imageId = this.decodeStringElement(descriptor, 0) val size = this.decodeLongElement(descriptor, 1) val type = this.decodeSerializableElement(descriptor, 2, ImageType.serializer()) @@ -237,6 +240,7 @@ public interface Image : Message, MessageContent, CodableMessage { index, ImageType.serializer() ) + 3 -> width = this@decodeStructure.decodeIntElement(descriptor, index) 4 -> height = this@decodeStructure.decodeIntElement(descriptor, index) 5 -> isEmoji = this@decodeStructure.decodeBooleanElement(descriptor, index) @@ -250,14 +254,16 @@ public interface Image : Message, MessageContent, CodableMessage { } override fun serialize(encoder: Encoder, value: Image) { - Delegate.serializer().serialize(encoder, Delegate( - value.imageId, - value.size, - value.imageType, - value.width, - value.height, - value.isEmoji - )) + Delegate.serializer().serialize( + encoder, Delegate( + value.imageId, + value.size, + value.imageType, + value.width, + value.height, + value.isEmoji + ) + ) } @SerialName(SERIAL_NAME) @@ -321,17 +327,18 @@ public interface Image : Message, MessageContent, CodableMessage { */ public var isEmoji: Boolean = false - /** - * 使用当前参数构造 [Image]. - */ - public fun build(): Image = InternalImageProtocol.instance.createImage( - imageId = imageId, - size = size, - type = type, - width = width, - height = height, - isEmoji = isEmoji, - ) + + public fun build(): Image { + @OptIn(MiraiInternalApi::class) + return InternalImageProtocol.instance.createImage( + imageId = imageId, + size = size, + type = type, + width = width, + height = height, + isEmoji = isEmoji, + ) + } public companion object { /** @@ -389,8 +396,10 @@ public interface Image : Message, MessageContent, CodableMessage { * @since 2.9.0 */ @JvmStatic - public suspend fun Image.isUploaded(bot: Bot): Boolean = - InternalImageProtocol.instance.isUploaded(bot, md5, size, null, imageType, width, height) + public suspend fun Image.isUploaded(bot: Bot): Boolean { + @OptIn(MiraiInternalApi::class) + return InternalImageProtocol.instance.isUploaded(bot, md5, size, null, imageType, width, height) + } /** * 当图片在服务器上存在时返回 `true`, 这意味着图片可以直接发送给 [contact]. @@ -407,7 +416,10 @@ public interface Image : Message, MessageContent, CodableMessage { bot: Bot, md5: ByteArray, size: Long, - ): Boolean = InternalImageProtocol.instance.isUploaded(bot, md5, size, null) + ): Boolean { + @OptIn(MiraiInternalApi::class) + return InternalImageProtocol.instance.isUploaded(bot, md5, size, null) + } /** * 由 [Image.imageId] 计算 [Image.md5]. @@ -415,7 +427,7 @@ public interface Image : Message, MessageContent, CodableMessage { * @since 2.9.0 */ public fun calculateImageMd5ByImageId(imageId: String): ByteArray { - @Suppress("DEPRECATION") + @OptIn(MiraiInternalApi::class) return when { imageId matches IMAGE_ID_REGEX -> imageId.imageIdToMd5(1) imageId matches IMAGE_RESOURCE_ID_REGEX_2 -> imageId.imageIdToMd5(imageId.skipToSecondHyphen() + 1) @@ -476,7 +488,7 @@ public interface Image : Message, MessageContent, CodableMessage { */ @JvmSynthetic @CName("", "Image_new") -public inline fun Image(imageId: String): Image = Builder.newBuilder(imageId).build() +public fun Image(imageId: String): Image = Builder.newBuilder(imageId).build() /** * 使用 [Image.Builder] 构建一个 [Image]. diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/MarketFace.kt b/mirai-core-api/src/commonMain/kotlin/message/data/MarketFace.kt index b4796ed6b..de3b05d0a 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/MarketFace.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/MarketFace.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -22,6 +22,7 @@ import net.mamoe.mirai.utils.safeCast * * @see Dice */ +@OptIn(MiraiExperimentalApi::class) @NotStableForInheritance public interface MarketFace : HummerMessage { /** @@ -44,6 +45,7 @@ public interface MarketFace : HummerMessage { return visitor.visitMarketFace(this, data) } + @OptIn(MiraiExperimentalApi::class) public companion object Key : AbstractPolymorphicMessageKey(HummerMessage, { it.safeCast() }) { // Notice that for MarketFaceImpl, its serial name is 'MarketFace'; diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/Message.kt b/mirai-core-api/src/commonMain/kotlin/message/data/Message.kt index cd2a2b4d2..c1452191f 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/Message.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/Message.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -9,7 +9,6 @@ @file:JvmMultifileClass @file:JvmName("MessageUtils") -@file:Suppress("NOTHING_TO_INLINE") package net.mamoe.mirai.message.data @@ -255,7 +254,7 @@ public interface Message { // Future optimize: // When constrainSingleCount == 1, see if we can connect by CombinedMessage, // this need some kind of replacement of `hasConstrainSingle` with more information about MessageKeys. - @OptIn(MessageChainConstructor::class) + @OptIn(MessageChainConstructor::class, MiraiInternalApi::class) CombinedMessage(this, tail, false) } else { LinearMessageChainImpl.combineCreate(this, tail) @@ -352,7 +351,7 @@ public interface Message { /** 将 [another] 按顺序连接到这个消息的尾部. */ @JvmSynthetic -public suspend inline operator fun Message.plus(another: Flow): MessageChain = +public suspend operator fun Message.plus(another: Flow): MessageChain = another.fold(this) { acc, it -> acc + it }.toMessageChain() @@ -360,7 +359,7 @@ public suspend inline operator fun Message.plus(another: Flow): Message * [Message.contentToString] 的捷径 */ @get:JvmSynthetic -public inline val Message.content: String +public val Message.content: String get() = contentToString() /** @@ -397,8 +396,7 @@ public fun Message.isContentBlank(): Boolean { /** * 将此消息元素按顺序重复 [count] 次. */ -// inline: for future removal -public inline fun Message.repeat(count: Int): MessageChain { +public fun Message.repeat(count: Int): MessageChain { if (this is ConstrainSingle) { // fast-path return this.toMessageChain() @@ -414,4 +412,4 @@ public inline fun Message.repeat(count: Int): MessageChain { * 将此消息元素按顺序重复 [count] 次. */ @JvmSynthetic -public inline operator fun Message.times(count: Int): MessageChain = this.repeat(count) +public operator fun Message.times(count: Int): MessageChain = this.repeat(count) diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/MessageSource.kt b/mirai-core-api/src/commonMain/kotlin/message/data/MessageSource.kt index 1f1659440..c4c8fdf34 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/MessageSource.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/MessageSource.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -22,7 +22,10 @@ import me.him188.kotlin.jvm.blocking.bridge.JvmBlockingBridge import net.mamoe.mirai.Bot import net.mamoe.mirai.IMirai import net.mamoe.mirai.Mirai -import net.mamoe.mirai.contact.* +import net.mamoe.mirai.contact.Contact +import net.mamoe.mirai.contact.Group +import net.mamoe.mirai.contact.PermissionDeniedException +import net.mamoe.mirai.contact.User import net.mamoe.mirai.event.events.MessageEvent import net.mamoe.mirai.internal.message.MessageSourceSerializerImpl import net.mamoe.mirai.message.MessageReceipt @@ -221,6 +224,7 @@ public sealed class MessageSource : Message, MessageMetadata, ConstrainSingle { return visitor.visitMessageSource(this, data) } + @OptIn(MiraiInternalApi::class) @Deprecated("Do not use this serializer. Retrieve from `MessageSerializers.serializersModule`.") @DeprecatedSinceMirai(warningSince = "2.13") public object Serializer : KSerializer by MessageSourceSerializerImpl("MessageSource") diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/MusicShare.kt b/mirai-core-api/src/commonMain/kotlin/message/data/MusicShare.kt index 80478ddd3..9fc14059e 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/MusicShare.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/MusicShare.kt @@ -16,6 +16,7 @@ import kotlinx.serialization.Serializable import net.mamoe.mirai.message.code.CodableMessage import net.mamoe.mirai.message.code.internal.appendStringAsMiraiCode import net.mamoe.mirai.message.data.visitor.MessageVisitor +import net.mamoe.mirai.utils.MiraiExperimentalApi import net.mamoe.mirai.utils.MiraiInternalApi import net.mamoe.mirai.utils.safeCast @@ -118,6 +119,7 @@ public data class MusicShare( override fun contentToString(): String = brief.takeIf { it.isNotBlank() } ?: "[分享]$title" // empty content is not accepted by `sendMessage` + @MiraiExperimentalApi override fun appendMiraiCodeTo(builder: StringBuilder) { builder.append("[mirai:musicshare:") .append(kind.name) diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/PokeMessage.kt b/mirai-core-api/src/commonMain/kotlin/message/data/PokeMessage.kt index 28bf5805f..1986bf706 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/PokeMessage.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/PokeMessage.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -32,6 +32,7 @@ import kotlin.jvm.JvmField * * @see PokeMessage.Companion 使用伴生对象中的常量 */ +@OptIn(MiraiExperimentalApi::class) @SerialName(PokeMessage.SERIAL_NAME) @Serializable public data class PokeMessage @MiraiInternalApi constructor( @@ -64,6 +65,7 @@ public data class PokeMessage @MiraiInternalApi constructor( return visitor.visitPokeMessage(this, data) } + @OptIn(MiraiExperimentalApi::class, MiraiInternalApi::class) public companion object Key : AbstractPolymorphicMessageKey(HummerMessage, { it.castOrNull() }) { diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/RichMessage.kt b/mirai-core-api/src/commonMain/kotlin/message/data/RichMessage.kt index f9dedbb3a..60f21b809 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/RichMessage.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/RichMessage.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -39,6 +39,7 @@ import kotlin.jvm.* // using polymorphic serializer from Message.Serializer @NotStableForInheritance public interface RichMessage : MessageContent, ConstrainSingle { + @OptIn(MiraiExperimentalApi::class) override val key: MessageKey get() = Key /** @@ -185,6 +186,7 @@ public class SimpleServiceMessage( */ @NotStableForInheritance public interface ServiceMessage : RichMessage, CodableMessage { + @OptIn(MiraiExperimentalApi::class) public companion object Key : AbstractPolymorphicMessageKey(RichMessage, { it.safeCast() }) diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/VipFace.kt b/mirai-core-api/src/commonMain/kotlin/message/data/VipFace.kt index 2d3c774bb..2a6ed1bef 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/VipFace.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/VipFace.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,8 +7,6 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ -@file:Suppress("NOTHING_TO_INLINE") - package net.mamoe.mirai.message.data import kotlinx.serialization.SerialName @@ -31,6 +29,7 @@ import kotlin.jvm.JvmField * * @see VipFace.Key 使用伴生对象中的常量 */ +@OptIn(MiraiExperimentalApi::class) @Serializable @SerialName(VipFace.SERIAL_NAME) public data class VipFace @MiraiInternalApi constructor( @@ -112,6 +111,6 @@ public data class VipFace @MiraiInternalApi constructor( BianBian, ZhaDan, AiXin, HaHa, DianZan, QinQin, YaoWan ) - private inline infix fun Int.to(name: String): Kind = Kind(this, name) + private infix fun Int.to(name: String): Kind = Kind(this, name) } } \ No newline at end of file diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/Voice.kt b/mirai-core-api/src/commonMain/kotlin/message/data/Voice.kt index f3db81a6a..f15a18f5b 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/Voice.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/Voice.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -9,7 +9,6 @@ @file:JvmMultifileClass @file:JvmName("MessageUtils") -@file:Suppress("NOTHING_TO_INLINE") package net.mamoe.mirai.message.data @@ -68,7 +67,8 @@ public abstract class PttMessage : MessageContent { * - 将 [Group.uploadVoice] 替换为 [Group.uploadAudio] * - 如果有必须使用旧 [Voice] 类型的情况, 请使用 [Audio.toVoice] */ -@Suppress("DuplicatedCode", "DEPRECATION", "DEPRECATION_ERROR") +@OptIn(MiraiExperimentalApi::class) +@Suppress("DuplicatedCode", "DEPRECATION_ERROR", "PropertyName", "HttpUrlsUsage") @Serializable @SerialName(Voice.SERIAL_NAME) @Deprecated( @@ -101,7 +101,7 @@ public open class Voice @MiraiInternalApi constructor( * @see Audio.toVoice * @since 2.7 */ - @Suppress("DeprecatedCallableAddReplaceWith") + @OptIn(MiraiInternalApi::class) @Deprecated( "Please consider migrating to Audio", level = DeprecationLevel.ERROR @@ -149,6 +149,7 @@ public open class Voice @MiraiInternalApi constructor( * * @since 2.7 */ + @OptIn(MiraiExperimentalApi::class, MiraiInternalApi::class) public fun toAudio(): Audio { val voice = this return OfflineAudio( @@ -160,6 +161,8 @@ public open class Voice @MiraiInternalApi constructor( ) } + @OptIn(MiraiInternalApi::class) + @MiraiExperimentalApi override fun equals(other: Any?): Boolean { if (this === other) return true if (other !is Voice) return false @@ -168,11 +171,11 @@ public open class Voice @MiraiInternalApi constructor( if (!md5.contentEquals(other.md5)) return false if (fileSize != other.fileSize) return false if (_codec != other._codec) return false - if (_url != other._url) return false - - return true + return _url == other._url } + @OptIn(MiraiInternalApi::class) + @MiraiExperimentalApi override fun hashCode(): Int { var result = fileName.hashCode() result = 12 * result + md5.contentHashCode() @@ -193,11 +196,11 @@ public open class Voice @MiraiInternalApi constructor( * * @since 2.7 */ -@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith", "DEPRECATION_ERROR") +@Suppress("DeprecatedCallableAddReplaceWith", "DEPRECATION_ERROR") @Deprecated( "Please migrate to Audio", level = DeprecationLevel.ERROR ) // deprecated since 2.7 @JvmSynthetic @DeprecatedSinceMirai(warningSince = "2.7", errorSince = "2.10", hiddenSince = "2.11") -public inline fun Audio.toVoice(): Voice = Voice.fromAudio(this) \ No newline at end of file +public fun Audio.toVoice(): Voice = Voice.fromAudio(this) \ No newline at end of file diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/impl.kt b/mirai-core-api/src/commonMain/kotlin/message/data/impl.kt index 5feb27619..33217ebae 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/impl.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/impl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -10,6 +10,7 @@ @file:Suppress("EXPERIMENTAL_API_USAGE") @file:JvmMultifileClass @file:JvmName("MessageUtils") +@file:OptIn(MiraiInternalApi::class) package net.mamoe.mirai.message.data @@ -70,6 +71,7 @@ internal sealed class AbstractMessageChain : MessageChain { @MiraiInternalApi abstract val hasConstrainSingle: Boolean + @OptIn(MiraiInternalApi::class) override fun hashCode(): Int { var result = 1 acceptChildren(object : RecursiveMessageVisitor() { @@ -110,6 +112,7 @@ internal sealed class AbstractMessageChain : MessageChain { } } +@OptIn(MiraiInternalApi::class) internal val Message.hasConstrainSingle: Boolean get() { if (this is SingleMessage) return this is ConstrainSingle diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/visitor/MessageVisitor.kt b/mirai-core-api/src/commonMain/kotlin/message/data/visitor/MessageVisitor.kt index 9c072fc2a..3c2b63391 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/visitor/MessageVisitor.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/visitor/MessageVisitor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -10,6 +10,7 @@ package net.mamoe.mirai.message.data.visitor import net.mamoe.mirai.message.data.* +import net.mamoe.mirai.utils.MiraiExperimentalApi import net.mamoe.mirai.utils.MiraiInternalApi import net.mamoe.mirai.utils.NotStableForInheritance @@ -20,6 +21,7 @@ import net.mamoe.mirai.utils.NotStableForInheritance * @suppress 这是内部 API, 请不要调用 * @since 2.12 */ +@OptIn(MiraiExperimentalApi::class) @MiraiInternalApi @NotStableForInheritance public interface MessageVisitor { @@ -95,6 +97,7 @@ public interface MessageVisitor { * @suppress 这是内部 API, 请不要调用 * @since 2.12 */ +@OptIn(MiraiExperimentalApi::class) @MiraiInternalApi public abstract class AbstractMessageVisitor : MessageVisitor { public override fun visitSingleMessage(message: SingleMessage, data: D): R { diff --git a/mirai-core-api/src/commonMain/kotlin/spi/SPIServiceLoader.kt b/mirai-core-api/src/commonMain/kotlin/spi/SPIServiceLoader.kt index edcb7a466..e3ded3868 100644 --- a/mirai-core-api/src/commonMain/kotlin/spi/SPIServiceLoader.kt +++ b/mirai-core-api/src/commonMain/kotlin/spi/SPIServiceLoader.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -24,6 +24,7 @@ public interface BaseService { public val priority: Int get() = 5 } +@OptIn(MiraiExperimentalApi::class) internal expect class SPIServiceLoader( defaultService: T, serviceType: KClass, diff --git a/mirai-core-api/src/commonMain/kotlin/utils/BotConfiguration.kt b/mirai-core-api/src/commonMain/kotlin/utils/BotConfiguration.kt index d745274f6..9e9ef48bd 100644 --- a/mirai-core-api/src/commonMain/kotlin/utils/BotConfiguration.kt +++ b/mirai-core-api/src/commonMain/kotlin/utils/BotConfiguration.kt @@ -54,7 +54,7 @@ import kotlin.time.Duration.Companion.milliseconds * }}) * ``` */ -@Suppress("PropertyName") +@OptIn(MiraiInternalApi::class) public open class BotConfiguration : AbstractBotConfiguration() { // open for Java /////////////////////////////////////////////////////////////////////////// // Coroutines diff --git a/mirai-core-api/src/commonMain/kotlin/utils/DeviceInfo.kt b/mirai-core-api/src/commonMain/kotlin/utils/DeviceInfo.kt index 3a6a72987..2128a43d6 100644 --- a/mirai-core-api/src/commonMain/kotlin/utils/DeviceInfo.kt +++ b/mirai-core-api/src/commonMain/kotlin/utils/DeviceInfo.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,13 +7,12 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:Suppress("MemberVisibilityCanBePrivate") + package net.mamoe.mirai.utils import io.ktor.utils.io.core.* -import kotlinx.serialization.KSerializer -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable -import kotlinx.serialization.Transient +import kotlinx.serialization.* import kotlinx.serialization.builtins.serializer import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonElement @@ -182,6 +181,7 @@ internal object DeviceInfoCommonImpl { } + @OptIn(MiraiInternalApi::class) @Suppress("DuplicatedCode") fun equalsImpl(deviceInfo: DeviceInfo, other: Any?): Boolean = deviceInfo.run { if (deviceInfo === other) return true @@ -207,11 +207,10 @@ internal object DeviceInfoCommonImpl { if (!imsiMd5.contentEquals(other.imsiMd5)) return false if (imei != other.imei) return false if (!apn.contentEquals(other.apn)) return false - if (!guid.contentEquals(other.guid)) return false - - return true + return guid.contentEquals(other.guid) } + @OptIn(MiraiInternalApi::class) @Suppress("DuplicatedCode") fun hashCodeImpl(deviceInfo: DeviceInfo): Int = deviceInfo.run { var result = display.contentHashCode() @@ -240,7 +239,7 @@ internal object DeviceInfoCommonImpl { } @Serializable -private class DevInfo( +private class DevInfo @OptIn(ExperimentalSerializationApi::class) constructor( @ProtoNumber(1) val bootloader: ByteArray, @ProtoNumber(2) val procVersion: ByteArray, @ProtoNumber(3) val codename: ByteArray, @@ -253,6 +252,7 @@ private class DevInfo( ) public fun DeviceInfo.generateDeviceInfoData(): ByteArray { + @OptIn(ExperimentalSerializationApi::class) return ProtoBuf.encodeToByteArray( DevInfo.serializer(), DevInfo( bootloader, @@ -489,7 +489,6 @@ internal object DeviceInfoManager { /** * Defaults "%4;7t>;28 T.withAutoClose(action: () -> R): R */ public inline fun T.runAutoClose(action: T.() -> R): R { contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } + @OptIn(MiraiExperimentalApi::class) return withAutoClose { action() } } diff --git a/mirai-core-api/src/commonMain/kotlin/utils/MiraiLogger.kt b/mirai-core-api/src/commonMain/kotlin/utils/MiraiLogger.kt index 99919ccc9..dd1e3f8cb 100644 --- a/mirai-core-api/src/commonMain/kotlin/utils/MiraiLogger.kt +++ b/mirai-core-api/src/commonMain/kotlin/utils/MiraiLogger.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -255,6 +255,7 @@ public expect open class PlatformLogger @JvmOverloads constructor( /** * 不做任何事情的 logger, keep silent. */ +@OptIn(MiraiInternalApi::class) @Suppress("unused") public object SilentLogger : PlatformLogger() { public override val identity: String? = null diff --git a/mirai-core-api/src/jvmBaseMain/kotlin/event/EventChannel.kt b/mirai-core-api/src/jvmBaseMain/kotlin/event/EventChannel.kt index 893fbb95e..9aa166c31 100644 --- a/mirai-core-api/src/jvmBaseMain/kotlin/event/EventChannel.kt +++ b/mirai-core-api/src/jvmBaseMain/kotlin/event/EventChannel.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -438,7 +438,7 @@ public actual abstract class EventChannel @MiraiInternalA handler: suspend E.(E) -> ListeningStatus, ): Listener = subscribeInternal( eventClass, - createListener(coroutineContext, concurrency, priority) { it.handler(it); } + createListener0(coroutineContext, concurrency, priority) { it.handler(it); } ) /** @@ -477,7 +477,7 @@ public actual abstract class EventChannel @MiraiInternalA handler: suspend E.(E) -> Unit, ): Listener = subscribeInternal( eventClass, - createListener(coroutineContext, concurrency, priority) { it.handler(it); ListeningStatus.LISTENING } + createListener0(coroutineContext, concurrency, priority) { it.handler(it); ListeningStatus.LISTENING } ) /** @@ -508,7 +508,7 @@ public actual abstract class EventChannel @MiraiInternalA handler: suspend E.(E) -> Unit, ): Listener = subscribeInternal( eventClass, - createListener(coroutineContext, ConcurrencyKind.LOCKED, priority) { it.handler(it); ListeningStatus.STOPPED } + createListener0(coroutineContext, ConcurrencyKind.LOCKED, priority) { it.handler(it); ListeningStatus.STOPPED } ) // endregion @@ -596,7 +596,7 @@ public actual abstract class EventChannel @MiraiInternalA handler: Consumer, ): Listener = subscribeInternal( eventClass.kotlin, - createListener(coroutineContext, concurrency, priority) { event -> + createListener0(coroutineContext, concurrency, priority) { event -> runInterruptible(Dispatchers.IO) { handler.accept(event) } ListeningStatus.LISTENING } @@ -624,7 +624,7 @@ public actual abstract class EventChannel @MiraiInternalA handler: java.util.function.Function, ): Listener = subscribeInternal( eventClass.kotlin, - createListener(coroutineContext, concurrency, priority) { event -> + createListener0(coroutineContext, concurrency, priority) { event -> runInterruptible(Dispatchers.IO) { handler.apply(event) } } ) @@ -650,7 +650,7 @@ public actual abstract class EventChannel @MiraiInternalA handler: Consumer, ): Listener = subscribeInternal( eventClass.kotlin, - createListener(coroutineContext, concurrency, priority) { event -> + createListener0(coroutineContext, concurrency, priority) { event -> runInterruptible(Dispatchers.IO) { handler.accept(event) } ListeningStatus.STOPPED } @@ -700,10 +700,12 @@ public actual abstract class EventChannel @MiraiInternalA protected actual abstract fun registerListener(eventClass: KClass, listener: Listener) // to overcome visibility issue + @OptIn(MiraiInternalApi::class) internal actual fun registerListener0(eventClass: KClass, listener: Listener) { return registerListener(eventClass, listener) } + @OptIn(MiraiInternalApi::class) private fun , E : Event> subscribeInternal(eventClass: KClass, listener: L): L { registerListener(eventClass, listener) return listener @@ -722,6 +724,7 @@ public actual abstract class EventChannel @MiraiInternalA ): Listener // to overcome visibility issue + @OptIn(MiraiInternalApi::class) internal actual fun createListener0( coroutineContext: CoroutineContext, concurrencyKind: ConcurrencyKind, diff --git a/mirai-core-api/src/jvmBaseMain/kotlin/event/MessageSelectBuilderUnit.kt b/mirai-core-api/src/jvmBaseMain/kotlin/event/MessageSelectBuilderUnit.kt index d5624dd40..afc16ed83 100644 --- a/mirai-core-api/src/jvmBaseMain/kotlin/event/MessageSelectBuilderUnit.kt +++ b/mirai-core-api/src/jvmBaseMain/kotlin/event/MessageSelectBuilderUnit.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -11,6 +11,7 @@ package net.mamoe.mirai.event import net.mamoe.mirai.event.events.MessageEvent import net.mamoe.mirai.message.data.Message +import net.mamoe.mirai.utils.MiraiInternalApi /** * [selectMessagesUnit] 或 [selectMessages] 时的 DSL 构建器. @@ -19,6 +20,7 @@ import net.mamoe.mirai.message.data.Message * * @see MessageSubscribersBuilder 查看上层 API */ +@OptIn(MiraiInternalApi::class) public actual abstract class MessageSelectBuilderUnit @PublishedApi internal actual constructor( ownerMessagePacket: M, stub: Any?, diff --git a/mirai-core-api/src/jvmBaseMain/kotlin/internal/utils/ExternalResourceImpls.kt b/mirai-core-api/src/jvmBaseMain/kotlin/internal/utils/ExternalResourceImpls.kt index aa84869ce..72d67d2ae 100644 --- a/mirai-core-api/src/jvmBaseMain/kotlin/internal/utils/ExternalResourceImpls.kt +++ b/mirai-core-api/src/jvmBaseMain/kotlin/internal/utils/ExternalResourceImpls.kt @@ -18,8 +18,6 @@ import net.mamoe.mirai.utils.* import java.io.Closeable import java.io.InputStream import java.io.RandomAccessFile -import kotlin.io.buffered -import kotlin.io.inputStream import kotlin.io.use @@ -102,6 +100,7 @@ internal abstract class ExternalResourceHolder : Closeable { internal interface ExternalResourceInternal : ExternalResource { val holder: ExternalResourceHolder + @MiraiInternalApi override fun input(): Input = inputStream().asInput() } @@ -164,6 +163,8 @@ internal class ExternalResourceImplByByteArray( get() = data//.clone() override fun inputStream(): InputStream = data.inputStream() + + @MiraiInternalApi override fun input(): Input { return data.inputStream().asInput() } diff --git a/mirai-core-api/src/jvmBaseMain/kotlin/message/data/FileMessage.kt b/mirai-core-api/src/jvmBaseMain/kotlin/message/data/FileMessage.kt index d1510965e..7456b5c93 100644 --- a/mirai-core-api/src/jvmBaseMain/kotlin/message/data/FileMessage.kt +++ b/mirai-core-api/src/jvmBaseMain/kotlin/message/data/FileMessage.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -64,6 +64,7 @@ public actual interface FileMessage : MessageContent, ConstrainSingle, CodableMe actual override fun contentToString(): String = "[文件]$name" // orthodox + @MiraiExperimentalApi actual override fun appendMiraiCodeTo(builder: StringBuilder) { builder.append("[mirai:file:") builder.appendStringAsMiraiCode(id).append(",") @@ -75,7 +76,7 @@ public actual interface FileMessage : MessageContent, ConstrainSingle, CodableMe /** * 获取一个对应的 [RemoteFile]. 当目标群或好友不存在这个文件时返回 `null`. */ - @Suppress("DEPRECATION", "DEPRECATION_ERROR") + @Suppress("DEPRECATION_ERROR") @Deprecated( "Please use toAbsoluteFile", ReplaceWith("this.toAbsoluteFile(contact)"), @@ -83,7 +84,6 @@ public actual interface FileMessage : MessageContent, ConstrainSingle, CodableMe ) // deprecated since 2.8.0-RC @DeprecatedSinceMirai(warningSince = "2.8", errorSince = "2.14") public suspend fun toRemoteFile(contact: FileSupported): RemoteFile? { - @Suppress("DEPRECATION") return contact.filesRoot.resolveById(id) } @@ -119,6 +119,7 @@ public actual interface FileMessage : MessageContent, ConstrainSingle, CodableMe Mirai.createFileMessage(id, internalId, name, size) } + public actual object Serializer : - KSerializer by FallbackFileMessageSerializer() + KSerializer by @OptIn(MiraiInternalApi::class) FallbackFileMessageSerializer() } diff --git a/mirai-core-api/src/jvmBaseMain/kotlin/spi/SPIServiceLoader.kt b/mirai-core-api/src/jvmBaseMain/kotlin/spi/SPIServiceLoader.kt index 1734ff987..37571c54a 100644 --- a/mirai-core-api/src/jvmBaseMain/kotlin/spi/SPIServiceLoader.kt +++ b/mirai-core-api/src/jvmBaseMain/kotlin/spi/SPIServiceLoader.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,8 +7,11 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(MiraiExperimentalApi::class) + package net.mamoe.mirai.spi +import net.mamoe.mirai.utils.MiraiExperimentalApi import net.mamoe.mirai.utils.MiraiLogger import java.util.* import kotlin.reflect.KClass diff --git a/mirai-core-api/src/jvmBaseMain/kotlin/utils/AbstractExternalResource.kt b/mirai-core-api/src/jvmBaseMain/kotlin/utils/AbstractExternalResource.kt index 6bdabd3ba..991be5b8c 100644 --- a/mirai-core-api/src/jvmBaseMain/kotlin/utils/AbstractExternalResource.kt +++ b/mirai-core-api/src/jvmBaseMain/kotlin/utils/AbstractExternalResource.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -257,6 +257,7 @@ public constructor( holder.close() } + @OptIn(MiraiInternalApi::class) @MiraiExperimentalApi override fun input(): Input { return inputStream().asInput() diff --git a/mirai-core-api/src/jvmBaseMain/kotlin/utils/MiraiLogger.kt b/mirai-core-api/src/jvmBaseMain/kotlin/utils/MiraiLogger.kt index 4197c6fbe..21b3be660 100644 --- a/mirai-core-api/src/jvmBaseMain/kotlin/utils/MiraiLogger.kt +++ b/mirai-core-api/src/jvmBaseMain/kotlin/utils/MiraiLogger.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -252,8 +252,9 @@ public actual interface MiraiLogger { public actual fun error(message: String?, e: Throwable?) /** 根据优先级调用对应函数 */ + public actual fun call(priority: SimpleLogger.LogPriority, message: String?, e: Throwable?): Unit = - priority.correspondingFunction(this, message, e) + @OptIn(MiraiExperimentalApi::class) priority.correspondingFunction(this, message, e) @Deprecated("plus 设计不佳, 请避免使用.", level = DeprecationLevel.HIDDEN) // deprecated since 2.7 @DeprecatedSinceMirai(warningSince = "2.7", errorSince = "2.10", hiddenSince = "2.11") @@ -265,7 +266,6 @@ public actual interface MiraiLogger { * @since 2.13 */ internal object MiraiLoggerFactoryImplementationBridge : MiraiLogger.Factory { - @Suppress("ObjectPropertyName") private var _instance by lateinitMutableProperty { createPlatformInstance() } @@ -332,6 +332,7 @@ internal object MiraiLoggerFactoryImplementationBridge : MiraiLogger.Factory { } private class DefaultFactory : MiraiLogger.Factory { + @OptIn(MiraiInternalApi::class) override fun create(requester: Class<*>, identity: String?): MiraiLogger { return PlatformLogger(identity ?: requester.kotlin.simpleName ?: requester.simpleName) } diff --git a/mirai-core-api/src/jvmMain/kotlin/utils/LoginSolver.jvm.kt b/mirai-core-api/src/jvmMain/kotlin/utils/LoginSolver.jvm.kt index 5dd7afe51..5f1a8aabb 100644 --- a/mirai-core-api/src/jvmMain/kotlin/utils/LoginSolver.jvm.kt +++ b/mirai-core-api/src/jvmMain/kotlin/utils/LoginSolver.jvm.kt @@ -41,15 +41,20 @@ internal actual object PlatformLoginSolverImplementations { * * @see createBlocking */ -public class StandardCharImageLoginSolver @JvmOverloads constructor( - input: suspend () -> String = { readLine() ?: throw NoStandardInputForCaptchaException() }, +public class StandardCharImageLoginSolver +@JvmOverloads constructor( + input: suspend () -> String = { + readlnOrNull() ?: @OptIn(MiraiInternalApi::class) throw NoStandardInputForCaptchaException() + }, /** * 为 `null` 时使用 [Bot.logger] */ private val loggerSupplier: (bot: Bot) -> MiraiLogger = { it.logger } ) : LoginSolver() { public constructor( - input: suspend () -> String = { readLine() ?: throw NoStandardInputForCaptchaException() }, + input: suspend () -> String = { + readlnOrNull() ?: @OptIn(MiraiInternalApi::class) throw NoStandardInputForCaptchaException() + }, overrideLogger: MiraiLogger? ) : this(input, { overrideLogger ?: it.logger }) @@ -383,6 +388,7 @@ private fun BufferedImage.createCharImg(outputWidth: Int = 100, ignoreRate: Doub } } +@Suppress("LocalVariableName", "SpellCheckingInspection") private fun BufferedImage.renderQRCode( blackPlaceholder: String = " ", whitePlaceholder: String = " ", diff --git a/mirai-core-api/src/jvmMain/kotlin/utils/PlatformLogger.jvm.kt b/mirai-core-api/src/jvmMain/kotlin/utils/PlatformLogger.jvm.kt index 379c2d1bc..e8a34edba 100644 --- a/mirai-core-api/src/jvmMain/kotlin/utils/PlatformLogger.jvm.kt +++ b/mirai-core-api/src/jvmMain/kotlin/utils/PlatformLogger.jvm.kt @@ -1,10 +1,10 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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("MemberVisibilityCanBePrivate") @@ -61,6 +61,7 @@ public actual open class PlatformLogger constructor( // same as StdoutLogger bu * 输出一条日志. [message] 末尾可能不带换行符. */ protected open fun printLog(message: String?, priority: SimpleLogger.LogPriority) { + @OptIn(MiraiExperimentalApi::class) if (isColored) output("${priority.color}$currentTimeFormatted ${priority.simpleName}/$identity: $message${Color.RESET}") else output("$currentTimeFormatted ${priority.simpleName}/$identity: $message") } @@ -68,6 +69,7 @@ public actual open class PlatformLogger constructor( // same as StdoutLogger bu /** * 获取指定 [SimpleLogger.LogPriority] 的颜色 */ + @MiraiExperimentalApi protected open val SimpleLogger.LogPriority.color: Color get() = when (this) { SimpleLogger.LogPriority.VERBOSE -> Color.RESET @@ -111,9 +113,12 @@ public actual open class PlatformLogger constructor( // same as StdoutLogger bu @Deprecated("Use formatter instead.", level = DeprecationLevel.HIDDEN) protected open val timeFormat: DateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.SIMPLIFIED_CHINESE) + @Suppress("NewApi") protected open val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") - private val currentTimeFormatted get() = formatter.format(LocalDateTime.now()) + private val currentTimeFormatted + @Suppress("NewApi") // we are in JVM module + get() = formatter.format(LocalDateTime.now()) @MiraiExperimentalApi("This is subject to change.") protected enum class Color(private val format: String) { diff --git a/mirai-core-api/src/jvmMain/kotlin/utils/SingleFileLogger.jvm.kt b/mirai-core-api/src/jvmMain/kotlin/utils/SingleFileLogger.jvm.kt index f978f905e..45ef3e5b3 100644 --- a/mirai-core-api/src/jvmMain/kotlin/utils/SingleFileLogger.jvm.kt +++ b/mirai-core-api/src/jvmMain/kotlin/utils/SingleFileLogger.jvm.kt @@ -1,10 +1,10 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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 */ @@ -20,6 +20,7 @@ import java.io.File * * @see PlatformLogger 查看格式信息 */ +@OptIn(MiraiInternalApi::class) public actual class SingleFileLogger actual constructor( identity: String, file: File diff --git a/mirai-core-api/src/nativeMain/kotlin/event/EventChannel.kt b/mirai-core-api/src/nativeMain/kotlin/event/EventChannel.kt index 890bd10b1..10525f12b 100644 --- a/mirai-core-api/src/nativeMain/kotlin/event/EventChannel.kt +++ b/mirai-core-api/src/nativeMain/kotlin/event/EventChannel.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -415,7 +415,7 @@ public actual abstract class EventChannel @MiraiInternalA handler: suspend E.(E) -> ListeningStatus, ): Listener = subscribeInternal( eventClass, - createListener(coroutineContext, concurrency, priority) { it.handler(it); } + createListener0(coroutineContext, concurrency, priority) { it.handler(it); } ) /** @@ -452,7 +452,7 @@ public actual abstract class EventChannel @MiraiInternalA handler: suspend E.(E) -> Unit, ): Listener = subscribeInternal( eventClass, - createListener(coroutineContext, concurrency, priority) { it.handler(it); ListeningStatus.LISTENING } + createListener0(coroutineContext, concurrency, priority) { it.handler(it); ListeningStatus.LISTENING } ) /** @@ -482,7 +482,7 @@ public actual abstract class EventChannel @MiraiInternalA handler: suspend E.(E) -> Unit, ): Listener = subscribeInternal( eventClass, - createListener(coroutineContext, ConcurrencyKind.LOCKED, priority) { it.handler(it); ListeningStatus.STOPPED } + createListener0(coroutineContext, ConcurrencyKind.LOCKED, priority) { it.handler(it); ListeningStatus.STOPPED } ) // endregion @@ -495,12 +495,13 @@ public actual abstract class EventChannel @MiraiInternalA protected actual abstract fun registerListener(eventClass: KClass, listener: Listener) // to overcome visibility issue + @OptIn(MiraiInternalApi::class) internal actual fun registerListener0(eventClass: KClass, listener: Listener) { return registerListener(eventClass, listener) } private fun , E : Event> subscribeInternal(eventClass: KClass, listener: L): L { - registerListener(eventClass, listener) + registerListener0(eventClass, listener) return listener } @@ -517,6 +518,7 @@ public actual abstract class EventChannel @MiraiInternalA ): Listener // to overcome visibility issue + @OptIn(MiraiInternalApi::class) internal actual fun createListener0( coroutineContext: CoroutineContext, concurrencyKind: ConcurrencyKind, diff --git a/mirai-core-api/src/nativeMain/kotlin/event/MessageSelectBuilderUnit.kt b/mirai-core-api/src/nativeMain/kotlin/event/MessageSelectBuilderUnit.kt index 204cf1254..09e599463 100644 --- a/mirai-core-api/src/nativeMain/kotlin/event/MessageSelectBuilderUnit.kt +++ b/mirai-core-api/src/nativeMain/kotlin/event/MessageSelectBuilderUnit.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -10,6 +10,7 @@ package net.mamoe.mirai.event import net.mamoe.mirai.event.events.MessageEvent +import net.mamoe.mirai.utils.MiraiInternalApi /** * [selectMessagesUnit] 或 [selectMessages] 时的 DSL 构建器. @@ -18,6 +19,7 @@ import net.mamoe.mirai.event.events.MessageEvent * * @see MessageSubscribersBuilder 查看上层 API */ +@OptIn(MiraiInternalApi::class) public actual abstract class MessageSelectBuilderUnit @PublishedApi internal actual constructor( ownerMessagePacket: M, stub: Any?, diff --git a/mirai-core-api/src/nativeMain/kotlin/internal/utils/ExternalResourceImplByByteArray.kt b/mirai-core-api/src/nativeMain/kotlin/internal/utils/ExternalResourceImplByByteArray.kt index a06a3d874..5cdd53881 100644 --- a/mirai-core-api/src/nativeMain/kotlin/internal/utils/ExternalResourceImplByByteArray.kt +++ b/mirai-core-api/src/nativeMain/kotlin/internal/utils/ExternalResourceImplByByteArray.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -28,6 +28,7 @@ internal class ExternalResourceImplByByteArray( override val origin: Any get() = data//.clone() + @MiraiInternalApi override fun input(): Input = ByteReadPacket(data) override fun close() { diff --git a/mirai-core-api/src/nativeMain/kotlin/message/data/FileMessage.kt b/mirai-core-api/src/nativeMain/kotlin/message/data/FileMessage.kt index 74df74100..f458f4e24 100644 --- a/mirai-core-api/src/nativeMain/kotlin/message/data/FileMessage.kt +++ b/mirai-core-api/src/nativeMain/kotlin/message/data/FileMessage.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -19,6 +19,7 @@ import net.mamoe.mirai.event.events.MessageEvent import net.mamoe.mirai.message.code.CodableMessage import net.mamoe.mirai.message.code.internal.appendStringAsMiraiCode import net.mamoe.mirai.message.data.visitor.MessageVisitor +import net.mamoe.mirai.utils.MiraiExperimentalApi import net.mamoe.mirai.utils.MiraiInternalApi import net.mamoe.mirai.utils.NotStableForInheritance import net.mamoe.mirai.utils.safeCast @@ -64,6 +65,7 @@ public actual interface FileMessage : MessageContent, ConstrainSingle, CodableMe actual override fun contentToString(): String = "[文件]$name" // orthodox + @MiraiExperimentalApi actual override fun appendMiraiCodeTo(builder: StringBuilder) { builder.append("[mirai:file:") builder.appendStringAsMiraiCode(id).append(",") @@ -104,5 +106,5 @@ public actual interface FileMessage : MessageContent, ConstrainSingle, CodableMe } public actual object Serializer : - KSerializer by FallbackFileMessageSerializer() + KSerializer by @OptIn(MiraiInternalApi::class) FallbackFileMessageSerializer() } diff --git a/mirai-core-api/src/nativeMain/kotlin/spi/SPIServiceLoader.kt b/mirai-core-api/src/nativeMain/kotlin/spi/SPIServiceLoader.kt index 856713847..672cb5936 100644 --- a/mirai-core-api/src/nativeMain/kotlin/spi/SPIServiceLoader.kt +++ b/mirai-core-api/src/nativeMain/kotlin/spi/SPIServiceLoader.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -7,8 +7,11 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ +@file:OptIn(MiraiExperimentalApi::class) + package net.mamoe.mirai.spi +import net.mamoe.mirai.utils.MiraiExperimentalApi import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.loadService import kotlin.reflect.KClass diff --git a/mirai-core-api/src/nativeMain/kotlin/utils/MiraiLogger.kt b/mirai-core-api/src/nativeMain/kotlin/utils/MiraiLogger.kt index b47849252..d4af23e41 100644 --- a/mirai-core-api/src/nativeMain/kotlin/utils/MiraiLogger.kt +++ b/mirai-core-api/src/nativeMain/kotlin/utils/MiraiLogger.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -55,6 +55,7 @@ public actual interface MiraiLogger { } public actual companion object INSTANCE : Factory by loadService(Factory::class, fallbackImplementation = { + @OptIn(MiraiInternalApi::class) object : Factory { override fun create(requester: KClass<*>): MiraiLogger { return PlatformLogger(requester.simpleName ?: requester.qualifiedName) @@ -182,5 +183,6 @@ public actual interface MiraiLogger { /** 根据优先级调用对应函数 */ public actual fun call(priority: SimpleLogger.LogPriority, message: String?, e: Throwable?): Unit = + @OptIn(MiraiExperimentalApi::class) priority.correspondingFunction(this, message, e) } diff --git a/mirai-core-mock/build.gradle.kts b/mirai-core-mock/build.gradle.kts index 0bc42bc87..a1b28bb45 100644 --- a/mirai-core-mock/build.gradle.kts +++ b/mirai-core-mock/build.gradle.kts @@ -20,6 +20,9 @@ description = "Mirai core mock testing framework" kotlin { explicitApiWarning() + optInForAllSourceSets("net.mamoe.mirai.LowLevelApi") + optInForAllSourceSets("net.mamoe.mirai.utils.MiraiInternalApi") + optInForAllSourceSets("net.mamoe.mirai.utils.MiraiExperimentalApi") } dependencies { diff --git a/mirai-core-mock/src/MockActions.kt b/mirai-core-mock/src/MockActions.kt index 377cfb9f7..cb52186bf 100644 --- a/mirai-core-mock/src/MockActions.kt +++ b/mirai-core-mock/src/MockActions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -24,6 +24,7 @@ import net.mamoe.mirai.mock.database.removeMessageInfo import net.mamoe.mirai.mock.utils.NudgeDsl import net.mamoe.mirai.mock.utils.mock import net.mamoe.mirai.mock.utils.nudged0 +import net.mamoe.mirai.utils.MiraiInternalApi import net.mamoe.mirai.utils.cast @JvmBlockingBridge @@ -32,6 +33,7 @@ public object MockActions { /** * 修改 [MockUserOrBot.nick] 并广播相关事件 (如 [FriendNickChangedEvent]) */ + @OptIn(MiraiInternalApi::class) @JvmStatic public suspend fun fireNickChanged(target: MockUserOrBot, value: String) { when (target) { @@ -63,6 +65,7 @@ public object MockActions { /** * 修改 [MockNormalMember.nameCard] 并广播 [MemberCardChangeEvent] */ + @OptIn(MiraiInternalApi::class) @JvmStatic public suspend fun fireNameCardChanged(member: MockNormalMember, value: String) { val ov = member.nameCard @@ -73,6 +76,7 @@ public object MockActions { /** * 修改 [MockNormalMember.specialTitle] 并广播 [MemberSpecialTitleChangeEvent] */ + @OptIn(MiraiInternalApi::class) @JvmStatic public suspend fun fireSpecialTitleChanged(member: MockNormalMember, value: String) { val ov = member.specialTitle @@ -88,6 +92,7 @@ public object MockActions { /** * 修改一名成员的权限并广播 [MemberPermissionChangeEvent] */ + @OptIn(MiraiInternalApi::class) @JvmStatic public suspend fun firePermissionChanged(member: MockNormalMember, perm: MemberPermission) { if (perm == MemberPermission.OWNER || member == member.group.owner) { @@ -117,6 +122,7 @@ public object MockActions { * * @param operator 当 [operator] 为 null 时代表是发送者自己撤回 */ + @OptIn(MiraiInternalApi::class) @JvmStatic public suspend fun fireMessageRecalled(source: MessageSource, operator: User? = null) { fun notSupported(): Nothing = error("Unsupported message source kind: ${source.kind}: ${source.javaClass}") diff --git a/mirai-core-mock/src/internal/msgsrc/OnlineMsgSrc.kt b/mirai-core-mock/src/internal/msgsrc/OnlineMsgSrc.kt index 8dc774a54..dd773ecaa 100644 --- a/mirai-core-mock/src/internal/msgsrc/OnlineMsgSrc.kt +++ b/mirai-core-mock/src/internal/msgsrc/OnlineMsgSrc.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -8,6 +8,7 @@ */ @file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") +@file:OptIn(MiraiInternalApi::class) package net.mamoe.mirai.mock.internal.msgsrc @@ -23,6 +24,7 @@ import net.mamoe.mirai.message.MessageSerializers import net.mamoe.mirai.message.data.* import net.mamoe.mirai.mock.internal.contact.AbstractMockContact import net.mamoe.mirai.mock.internal.contact.MockImage +import net.mamoe.mirai.utils.MiraiInternalApi import net.mamoe.mirai.utils.cast import net.mamoe.mirai.utils.currentTimeSeconds diff --git a/mirai-core-mock/src/utils/NudgeDsl.kt b/mirai-core-mock/src/utils/NudgeDsl.kt index fcbdf3002..a38f3dfdf 100644 --- a/mirai-core-mock/src/utils/NudgeDsl.kt +++ b/mirai-core-mock/src/utils/NudgeDsl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -14,6 +14,7 @@ import net.mamoe.mirai.contact.* import net.mamoe.mirai.event.broadcast import net.mamoe.mirai.event.events.NudgeEvent import net.mamoe.mirai.mock.contact.MockUserOrBot +import net.mamoe.mirai.utils.MiraiInternalApi /** * 构造 Nudge 的 DSL @@ -34,6 +35,7 @@ public class NudgeDsl { public fun suffix(value: String): NudgeDsl = apply { suffix = value } } +@OptIn(MiraiInternalApi::class) @PublishedApi internal suspend fun MockUserOrBot.nudged0(target: MockUserOrBot, dsl: NudgeDsl) { diff --git a/mirai-core-utils/src/commonMain/kotlin/Bytes.kt b/mirai-core-utils/src/commonMain/kotlin/Bytes.kt index 7bdf7eec3..96a9ca486 100644 --- a/mirai-core-utils/src/commonMain/kotlin/Bytes.kt +++ b/mirai-core-utils/src/commonMain/kotlin/Bytes.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -9,7 +9,6 @@ @file:JvmMultifileClass @file:JvmName("MiraiUtils") -@file:Suppress("NOTHING_TO_INLINE") package net.mamoe.mirai.utils @@ -104,6 +103,7 @@ public fun ByteArray.checkOffsetAndLength(offset: Int, length: Int) { require(offset + length <= this.size) { "offset ($offset) + length ($length) > array.size (${this.size})" } } +@OptIn(ExperimentalUnsignedTypes::class) public fun UByteArray.toUHexString(separator: String = " ", offset: Int = 0, length: Int = this.size - offset): String { if (length == 0) { return "" @@ -121,10 +121,10 @@ public fun UByteArray.toUHexString(separator: String = " ", offset: Int = 0, len } } -public inline fun ByteArray.toReadPacket( +public fun ByteArray.toReadPacket( offset: Int = 0, length: Int = this.size - offset, - noinline release: (ByteArray) -> Unit = {} + release: (ByteArray) -> Unit = {} ): ByteReadPacket = ByteReadPacket(this, offset = offset, length = length, block = release) diff --git a/mirai-core-utils/src/commonMain/kotlin/Conversions.kt b/mirai-core-utils/src/commonMain/kotlin/Conversions.kt index 0cf837907..61df7d530 100644 --- a/mirai-core-utils/src/commonMain/kotlin/Conversions.kt +++ b/mirai-core-utils/src/commonMain/kotlin/Conversions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -189,6 +189,7 @@ public fun String.hexToBytes(): ByteArray { return array } +@OptIn(ExperimentalUnsignedTypes::class) public fun String.hexToUBytes(): UByteArray { val array = UByteArray(countHexBytes()) forEachHexChunkIndexed { index, char1, char2 -> diff --git a/mirai-core-utils/src/commonMain/kotlin/IO.kt b/mirai-core-utils/src/commonMain/kotlin/IO.kt index 886d28ff6..026889680 100644 --- a/mirai-core-utils/src/commonMain/kotlin/IO.kt +++ b/mirai-core-utils/src/commonMain/kotlin/IO.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -10,8 +10,6 @@ @file:JvmMultifileClass @file:JvmName("MiraiUtils") -@file:Suppress("NOTHING_TO_INLINE") - package net.mamoe.mirai.utils import io.ktor.utils.io.* @@ -50,6 +48,7 @@ public inline fun Input.useBytes( n != null -> { this.readBytes(n).let { block(it, it.size) } } + this is ByteReadPacket -> { val count = this.remaining.toIntOrFail() ByteArrayPool.useInstance(count) { @@ -57,6 +56,7 @@ public inline fun Input.useBytes( block(it, count) } } + else -> { this.readBytes().let { block(it, it.size) } } @@ -70,31 +70,31 @@ public fun Long.toIntOrFail(): Int { return this.toInt() } -public inline fun ByteReadPacket.readPacketExact( +public fun ByteReadPacket.readPacketExact( n: Int = remaining.toIntOrFail() ): ByteReadPacket = this.readBytes(n).toReadPacket() public fun Input.readAllText(): String = Charsets.UTF_8.newDecoder().decode(this) -public inline fun Input.readString(length: Int, charset: Charset = Charsets.UTF_8): String = +public fun Input.readString(length: Int, charset: Charset = Charsets.UTF_8): String = String(this.readBytes(length), charset = charset) // stdlib -public inline fun Input.readString(length: Long, charset: Charset = Charsets.UTF_8): String = +public fun Input.readString(length: Long, charset: Charset = Charsets.UTF_8): String = String(this.readBytes(length.toInt()), charset = charset) -public inline fun Input.readString(length: Short, charset: Charset = Charsets.UTF_8): String = +public fun Input.readString(length: Short, charset: Charset = Charsets.UTF_8): String = String(this.readBytes(length.toInt()), charset = charset) @JvmSynthetic -public inline fun Input.readString(length: UShort, charset: Charset = Charsets.UTF_8): String = +public fun Input.readString(length: UShort, charset: Charset = Charsets.UTF_8): String = String(this.readBytes(length.toInt()), charset = charset) -public inline fun Input.readString(length: Byte, charset: Charset = Charsets.UTF_8): String = +public fun Input.readString(length: Byte, charset: Charset = Charsets.UTF_8): String = String(this.readBytes(length.toInt()), charset = charset) public fun Input.readUShortLVString(): String = String(this.readUShortLVByteArray()) -public fun Input.readUShortLVByteArray(): ByteArray = this.readBytes(this.readUShort().toInt()) +public fun Input.readUShortLVByteArray(): ByteArray = this.readBytes(this.readShort().toUShort().toInt()) public suspend fun Input.copyTo(output: ByteWriteChannel): Long { val buffer = ChunkBuffer.Pool.borrow() diff --git a/mirai-core-utils/src/commonMain/kotlin/Serialization.kt b/mirai-core-utils/src/commonMain/kotlin/Serialization.kt index c7f7cd64a..72294bc25 100644 --- a/mirai-core-utils/src/commonMain/kotlin/Serialization.kt +++ b/mirai-core-utils/src/commonMain/kotlin/Serialization.kt @@ -11,10 +11,7 @@ package net.mamoe.mirai.utils -import kotlinx.serialization.BinaryFormat -import kotlinx.serialization.DeserializationStrategy -import kotlinx.serialization.KSerializer -import kotlinx.serialization.StringFormat +import kotlinx.serialization.* import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder @@ -23,6 +20,7 @@ import kotlin.jvm.JvmName public fun SerialDescriptor.copy(newName: String): SerialDescriptor = buildClassSerialDescriptor(newName) { takeElementsFrom(this@copy) } +@OptIn(ExperimentalSerializationApi::class) // bad but there is no other solution public fun ClassSerialDescriptorBuilder.takeElementsFrom(descriptor: SerialDescriptor) { with(descriptor) { repeat(descriptor.elementsCount) { index -> @@ -48,6 +46,7 @@ public inline fun KSerializer.map( } } +@OptIn(ExperimentalSerializationApi::class) public inline fun KSerializer.mapPrimitive( serialName: String, crossinline deserialize: (T) -> R, diff --git a/mirai-core-utils/src/commonMain/kotlin/TlvMap.kt b/mirai-core-utils/src/commonMain/kotlin/TlvMap.kt index b69c046d9..8bc0fc295 100644 --- a/mirai-core-utils/src/commonMain/kotlin/TlvMap.kt +++ b/mirai-core-utils/src/commonMain/kotlin/TlvMap.kt @@ -170,9 +170,9 @@ public fun Input._readTLVMap( while (kotlin.run { try { key = when (tagSize) { - 1 -> readUByte().toInt() - 2 -> readUShort().toInt() - 4 -> readUInt().toInt() + 1 -> readByte().toUByte().toInt() + 2 -> readShort().toUShort().toInt() + 4 -> readInt() else -> error("Unsupported tag size: $tagSize") } } catch (e: Exception) { // java.nio.BufferUnderflowException is not a EOFException... @@ -209,7 +209,7 @@ public fun Input._readTLVMap( } } else { try { - val len = readUShort().toInt() + val len = readShort().toUShort().toInt() val data = this.readBytes(len) // println("Writing [${key.toUHexString()}]($len) => ${data.toUHexString()}") map[key] = data diff --git a/mirai-core-utils/src/jvmBaseMain/kotlin/StructureToStringTransformerLegacy.kt b/mirai-core-utils/src/jvmBaseMain/kotlin/StructureToStringTransformerLegacy.kt index 19fc1f37c..9a5be84c2 100644 --- a/mirai-core-utils/src/jvmBaseMain/kotlin/StructureToStringTransformerLegacy.kt +++ b/mirai-core-utils/src/jvmBaseMain/kotlin/StructureToStringTransformerLegacy.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -35,14 +35,14 @@ public class StructureToStringTransformerLegacy : StructureToStringTransformer { * 将内容格式化为较可读的字符串输出. * * 各数字类型及其无符号类型: 十六进制表示 + 十进制表示. e.g. `0x1000(4096)` - * [ByteArray] 和 [UByteArray]: 十六进制表示, 通过 [ByteArray.toUHexString] + * [ByteArray]: 十六进制表示, 通过 [ByteArray.toUHexString] * [Iterable], [Iterator], [Sequence]: 调用各自的 joinToString. * [Map]: 多行输出. 每行显示一个值. 递归调用 [_miraiContentToString]. 嵌套结构将会以缩进表示 * `data class`: 调用其 [toString] * 其他类型: 反射获取它和它的所有来自 Mirai 的 super 类型的所有自有属性并递归调用 [_miraiContentToString]. 嵌套结构将会以缩进表示 */ @Suppress("FunctionName") // 这样就不容易被 IDE 提示 - internal fun Any?._miraiContentToString(prefix: String = ""): String = when (this) { + private fun Any?._miraiContentToString(prefix: String = ""): String = when (this) { is Unit -> "Unit" is UInt -> "0x" + this.toUHexString("") + "($this)" is UByte -> "0x" + this.toUHexString() + "($this)" @@ -59,10 +59,6 @@ public class StructureToStringTransformerLegacy : StructureToStringTransformer { if (this.size == 0) "" else this.toUHexString() } - is UByteArray -> { - if (this.size == 0) "" - else this.toUHexString() - } is ShortArray -> { if (this.size == 0) "" else this.iterator()._miraiContentToString() @@ -83,18 +79,6 @@ public class StructureToStringTransformerLegacy : StructureToStringTransformer { if (this.size == 0) "" else this.iterator()._miraiContentToString() } - is UShortArray -> { - if (this.size == 0) "" - else this.iterator()._miraiContentToString() - } - is UIntArray -> { - if (this.size == 0) "" - else this.iterator()._miraiContentToString() - } - is ULongArray -> { - if (this.size == 0) "" - else this.iterator()._miraiContentToString() - } is Array<*> -> { if (this.size == 0) "" else this.iterator()._miraiContentToString() @@ -130,7 +114,7 @@ public class StructureToStringTransformerLegacy : StructureToStringTransformer { } } - internal fun KProperty1<*, *>.getValueAgainstPermission(receiver: Any): Any? { + private fun KProperty1<*, *>.getValueAgainstPermission(receiver: Any): Any? { return this.javaField?.apply { isAccessible = true }?.get(receiver) } @@ -202,7 +186,7 @@ public class StructureToStringTransformerLegacy : StructureToStringTransformer { .map { it as KProperty1 } } - internal fun KProperty<*>.isTransient(): Boolean = + private fun KProperty<*>.isTransient(): Boolean = javaField?.modifiers?.and(Modifier.TRANSIENT) != 0 diff --git a/mirai-core/build.gradle.kts b/mirai-core/build.gradle.kts index 24e792eab..ff7134cac 100644 --- a/mirai-core/build.gradle.kts +++ b/mirai-core/build.gradle.kts @@ -35,6 +35,11 @@ kotlin { configureNativeTargetsHierarchical(project) configureNativeTargetBinaries(project) // register native binaries for mirai-core only + optInForAllSourceSets("net.mamoe.mirai.utils.MiraiExperimentalApi") + optInForAllSourceSets("net.mamoe.mirai.utils.MiraiInternalApi") + optInForAllSourceSets("net.mamoe.mirai.LowLevelApi") + optInForAllSourceSets("kotlinx.serialization.ExperimentalSerializationApi") + sourceSets.apply { val commonMain by getting { diff --git a/mirai-core/src/commonMain/kotlin/AbstractBot.kt b/mirai-core/src/commonMain/kotlin/AbstractBot.kt index 0bdedf54b..76ef805d2 100644 --- a/mirai-core/src/commonMain/kotlin/AbstractBot.kt +++ b/mirai-core/src/commonMain/kotlin/AbstractBot.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -8,10 +8,13 @@ */ +@file:OptIn(LowLevelApi::class) + package net.mamoe.mirai.internal import kotlinx.coroutines.* import net.mamoe.mirai.Bot +import net.mamoe.mirai.LowLevelApi import net.mamoe.mirai.Mirai import net.mamoe.mirai.contact.ContactList import net.mamoe.mirai.event.EventChannel @@ -36,7 +39,7 @@ import kotlin.jvm.Volatile /** * Protocol-irrelevant implementations */ -internal abstract class AbstractBot constructor( +internal abstract class AbstractBot( final override val configuration: BotConfiguration, final override val id: Long, ) : Bot, CoroutineScope { diff --git a/mirai-core/src/commonMain/kotlin/event/EventChannelImpl.kt b/mirai-core/src/commonMain/kotlin/event/EventChannelImpl.kt index aea77ac8a..f2d96b3fb 100644 --- a/mirai-core/src/commonMain/kotlin/event/EventChannelImpl.kt +++ b/mirai-core/src/commonMain/kotlin/event/EventChannelImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -48,7 +48,7 @@ internal annotation class InternalEventMechanism * * **Never ever** use [EventChannelToEventDispatcherAdapter.instance] directly. */ -internal sealed class EventChannelImpl constructor( +internal sealed class EventChannelImpl( baseEventClass: KClass, defaultCoroutineContext: CoroutineContext = EmptyCoroutineContext ) : EventChannel(baseEventClass, defaultCoroutineContext) { private val eventListeners = EventListeners() diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/FileMessageProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/FileMessageProtocol.kt index f2ec5aeec..e7a76d694 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/FileMessageProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/FileMessageProtocol.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -153,7 +153,7 @@ internal class FileMessageProtocol : MessageProtocol() { val var7 = readByte() if (var7 == 1.toByte()) { while (remaining > 2) { - val proto = readProtoBuf(ObjMsg.ObjMsg.serializer(), readUShort().toInt()) + val proto = readProtoBuf(ObjMsg.ObjMsg.serializer(), readShort().toUShort().toInt()) // proto.msgType=6 val file = proto.msgContentInfo.firstOrNull()?.msgFile ?: continue // officially get(0) only. diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/TextProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/TextProtocol.kt index b22b19292..d744f0936 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/TextProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/TextProtocol.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -58,7 +58,7 @@ internal class TextProtocol : MessageProtocol() { } else { val id = text.attr6Buf.read { discardExact(7) - readUInt().toLong() + readInt().toUInt().toLong() } if (id == 0L) { collect(AtAll) diff --git a/mirai-core/src/commonMain/kotlin/network/components/PacketCodec.kt b/mirai-core/src/commonMain/kotlin/network/components/PacketCodec.kt index b40cf1199..8f7ec0248 100644 --- a/mirai-core/src/commonMain/kotlin/network/components/PacketCodec.kt +++ b/mirai-core/src/commonMain/kotlin/network/components/PacketCodec.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -331,7 +331,7 @@ internal class PacketCodecImpl : PacketCodec { var decryptedData: String? = null if (remaining > 15) { discardExact(12) - val encryptionMethod = this.readUShort().toInt() + val encryptionMethod = this.readShort().toUShort().toInt() discardExact(1) decryptedData = kotlin.runCatching { decrypt(encryptionMethod).toUHexString() @@ -348,10 +348,10 @@ internal class PacketCodecImpl : PacketCodec { this.discardExact(2) this.discardExact(2) - this.readUShort() + this.readShort().toUShort() this.readShort() - this.readUInt().toLong() - val encryptionMethod = this.readUShort().toInt() + this.readInt().toUInt().toLong() + val encryptionMethod = this.readShort().toUShort().toInt() this.discardExact(1) return decrypt(encryptionMethod) diff --git a/mirai-core/src/commonMain/kotlin/network/notice/decoders/MsgInfoDecoder.kt b/mirai-core/src/commonMain/kotlin/network/notice/decoders/MsgInfoDecoder.kt index bc82b1c71..2ba3afe87 100644 --- a/mirai-core/src/commonMain/kotlin/network/notice/decoders/MsgInfoDecoder.kt +++ b/mirai-core/src/commonMain/kotlin/network/notice/decoders/MsgInfoDecoder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -51,7 +51,7 @@ internal class MsgInfoDecoder( // 732 0x2dc -> { data.vMsg.read { - val groupCode = readUInt().toLong() + val groupCode = readInt().toUInt().toLong() val group = bot.getGroup(groupCode) ?: bot.getGroupByUin(groupCode) ?: return // group has not been initialized group.checkIsGroupImpl() diff --git a/mirai-core/src/commonMain/kotlin/network/notice/group/GroupNotificationProcessor.kt b/mirai-core/src/commonMain/kotlin/network/notice/group/GroupNotificationProcessor.kt index 7b96b39e5..b59a4bb04 100644 --- a/mirai-core/src/commonMain/kotlin/network/notice/group/GroupNotificationProcessor.kt +++ b/mirai-core/src/commonMain/kotlin/network/notice/group/GroupNotificationProcessor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -218,14 +218,14 @@ internal class GroupNotificationProcessor( markAsConsumed() buf.read { - val operatorUin = readUInt().toLong() + val operatorUin = readInt().toUInt().toLong() if (operatorUin == bot.id) return val operator = group[operatorUin] ?: return - readUInt().toLong() // time - val length = readUShort().toInt() + readInt().toUInt().toLong() // time + val length = readShort().toUShort().toInt() repeat(length) { - val target = readUInt().toLong() - val timeSeconds = readUInt() + val target = readInt().toUInt().toLong() + val timeSeconds = readInt().toUInt() collected += handleMuteMemberPacket(bot, group, operator, target, timeSeconds.toInt()) } } @@ -239,7 +239,7 @@ internal class GroupNotificationProcessor( ) = data.context { markAsConsumed() buf.read { - val operator = group[readUInt().toLong()] ?: return + val operator = group[readInt().toUInt().toLong()] ?: return val new = readInt() == 0 if (group.settings.isAnonymousChatEnabledField == new) return diff --git a/mirai-core/src/commonMain/kotlin/network/notice/group/GroupOrMemberListNoticeProcessor.kt b/mirai-core/src/commonMain/kotlin/network/notice/group/GroupOrMemberListNoticeProcessor.kt index fcfa95422..15f1c5e04 100644 --- a/mirai-core/src/commonMain/kotlin/network/notice/group/GroupOrMemberListNoticeProcessor.kt +++ b/mirai-core/src/commonMain/kotlin/network/notice/group/GroupOrMemberListNoticeProcessor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -135,16 +135,16 @@ internal class GroupOrMemberListNoticeProcessor( // 33 private suspend fun NoticePipelineContext.processGroupJoin33(data: MsgComm.Msg) = data.context { msgBody.msgContent.read { - val groupCode = readUInt().toLong() + val groupCode = readInt().toUInt().toLong() if (remaining < 5) return discardExact(1) - val joinedMemberUin = readUInt().toLong() + val joinedMemberUin = readInt().toUInt().toLong() if (joinedMemberUin == bot.id && bot.getGroupByCodeOrUin(groupCode) != null) return // duplicate val group = bot.getGroupByCodeOrUin(groupCode) ?: bot.addNewGroupByCode(groupCode) ?: return val joinType = readByte().toInt() - val invitorUin = readUInt().toLong() + val invitorUin = readInt().toUInt().toLong() when (joinType) { // 邀请加入 -125, 3 -> { @@ -312,15 +312,15 @@ internal class GroupOrMemberListNoticeProcessor( // 3D C4 33 DD 01 00/01 ..... // 3D C4 33 DD 01 01 C3 7E 2E 34 01 discardExact(5) - val kind = readUByte().toInt() + val kind = readByte().toUByte().toInt() if (kind == 0xFF) { - val from = readUInt().toLong() - val to = readUInt().toLong() + val from = readInt().toUInt().toLong() + val to = readInt().toUInt().toLong() handleGroupOwnershipTransfer(data, from, to) } else { - val var5 = if (kind == 0 || kind == 1) 0 else readUInt().toInt() - val target = readUInt().toLong() + val var5 = if (kind == 0 || kind == 1) 0 else readInt().toUInt().toInt() + val target = readInt().toUInt().toLong() if (var5 == 0) { val newPermission = if (remaining == 1L) readByte() else return @@ -344,11 +344,11 @@ internal class GroupOrMemberListNoticeProcessor( */ data.msgData.read { - readUInt().toLong() // groupCode + readInt().toUInt().toLong() // groupCode readByte().toInt() // follow type - val target = readUInt().toLong() - val kind = readUByte().toInt() - val operator = readUInt().toLong() + val target = readInt().toUInt().toLong() + val kind = readByte().toUByte().toInt() + val operator = readInt().toUInt().toLong() val groupUin = data.fromUin handleLeave(target, kind, operator, groupUin) } diff --git a/mirai-core/src/commonMain/kotlin/network/notice/priv/FriendNoticeProcessor.kt b/mirai-core/src/commonMain/kotlin/network/notice/priv/FriendNoticeProcessor.kt index 574f762b6..99e3c00f9 100644 --- a/mirai-core/src/commonMain/kotlin/network/notice/priv/FriendNoticeProcessor.kt +++ b/mirai-core/src/commonMain/kotlin/network/notice/priv/FriendNoticeProcessor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -53,23 +53,24 @@ internal class FriendNoticeProcessor( var fromGroup = 0L var pbNick = "" msgBody.msgContent.read { - readUByte() // version - discardExact(readUByte().toInt()) //skip - readUShort() //source id - readUShort() //SourceSubID - discardExact(readUShort().toLong()) //skip size - if (readUShort().toInt() != 0) { //hasExtraInfo - discardExact(readUShort().toInt()) //mail address info, skip + readByte().toUByte() // version + discardExact(readByte().toUByte().toInt()) //skip + readShort().toUShort() //source id + readShort().toUShort() //SourceSubID + discardExact(readShort().toUShort().toLong()) //skip size + if (readShort().toUShort().toInt() != 0) { //hasExtraInfo + discardExact(readShort().toUShort().toInt()) //mail address info, skip } - discardExact(4 + readUShort().toInt()) //skip - for (i in 1..readUByte().toInt()) { //pb size - val type = readUShort().toInt() - val pbArray = ByteArray(readUShort().toInt() and 0xFF) + discardExact(4 + readShort().toUShort().toInt()) //skip + for (i in 1..readByte().toUByte().toInt()) { //pb size + val type = readShort().toUShort().toInt() + val pbArray = ByteArray(readShort().toUShort().toInt() and 0xFF) readAvailable(pbArray) when (type) { 1000 -> pbArray.loadAs(FrdSysMsg.GroupInfo.serializer()).let { fromGroup = it.groupUin } 1002 -> pbArray.loadAs(FrdSysMsg.FriendMiscInfo.serializer()) .let { pbNick = it.fromuinNick } + else -> { } //ignore } diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/WtLogin.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/WtLogin.kt index 6e7d01090..cf0d59856 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/WtLogin.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/WtLogin.kt @@ -199,9 +199,9 @@ internal class WtLogin { override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): LoginPacketResponse { - val subCommand = readUShort() // subCommand + val subCommand = readShort().toUShort() // subCommand // println("subCommand=$subCommand") - val type = readUByte() + val type = readByte().toUByte() // println("type=$type") discardExact(2) @@ -520,7 +520,7 @@ internal class WtLogin { it.read { //change interval (int time) discardExact(4) - readUInt().toLong() + readInt().toUInt().toLong() } } ?: appPri @@ -571,7 +571,7 @@ internal class WtLogin { it.read { //change interval (int time) discardExact(4) - readUInt().toLong() + readInt().toUInt().toLong() } } ?: 4294967295L, // defaults {}, from asyncContext._G @@ -772,8 +772,8 @@ internal class WtLogin { writeInt(currentTimeSeconds().toInt()) writeByte(2) val bodyPacket = buildPacket(body) - writeUShort((43 + bodyPacket.remaining + 1).toUShort()) - writeUShort(command.toUShort()) + writeShort((43 + bodyPacket.remaining + 1).toUShort().toShort()) + writeShort(command) writeFully(ByteArray(21) { 0 }) writeByte(3) writeShort(0) @@ -812,13 +812,13 @@ internal class WtLogin { check(remaining >= 48) { "remaining payload is too short, current is $remaining." } discardExact(5) - readUByte() - readUShort() - val command = readUShort().toInt() + readByte().toUByte() + readShort().toUShort() + val command = readShort().toUShort().toInt() discardExact(21) - readUByte() - readUShort() - readUShort() + readByte().toUByte() + readShort().toUShort() + readShort().toUShort() readInt() readLong() @@ -830,7 +830,7 @@ internal class WtLogin { val code = readByte().toInt() check(code == 0) { "code is not 0 while parsing wtlogin.trans_emp with command 0x31." } val sig = readUShortLVByteArray() - readUShort() + readShort().toUShort() val tlv = _readTLVMap() val data = @@ -840,10 +840,10 @@ internal class WtLogin { } 0x12 -> { // qr code state - var length = readUShort().toInt() + var length = readShort().toUShort().toInt() if (length != 0) { length-- - if (readUByte().toInt() == 2) { + if (readByte().toUByte().toInt() == 2) { readLong() length -= 8 } @@ -854,7 +854,7 @@ internal class WtLogin { } readInt() - val code = readUByte().toInt() + val code = readByte().toUByte().toInt() if (code != 0) { when (code) { // code 0x30 -> Response.QRCodeStatus(Response.QRCodeStatus.State.WAITING_FOR_SCAN) @@ -871,7 +871,7 @@ internal class WtLogin { throw InconsistentBotIdException(expected = client.uin, actual = uin) } readInt() - readUShort() + readShort().toUShort() val tlv = _readTLVMap() val tmpPwd = tlv.getOrFail(0x18) { diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/wtlogin/WtLoginExt.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/wtlogin/WtLoginExt.kt index 4106838c2..b378441d7 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/wtlogin/WtLoginExt.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/wtlogin/WtLoginExt.kt @@ -128,7 +128,7 @@ internal interface WtLoginExt { // so as not to register to global extension val appid = readInt().toLong().and(4294967295L) val stKey = ByteArray(16) readAvailable(stKey) - val stSigLength = readUShort().toInt() + val stSigLength = readShort().toUShort().toInt() val stSig = ByteArray(stSigLength) readAvailable(stSig) WLoginSigInfo.EncryptedDownloadSession( @@ -150,7 +150,7 @@ internal interface WtLoginExt { // so as not to register to global extension * 设置 [QQAndroidClient.uin] */ fun QQAndroidClient.analysisTlv113(t113: ByteArray) = t113.read { - _uin = readUInt().toLong() + _uin = readInt().toUInt().toLong() /* // nothing to do @@ -166,7 +166,7 @@ internal interface WtLoginExt { // so as not to register to global extension */ fun QQAndroidClient.analysisTlv130(t130: ByteArray) = t130.read { discardExact(2) - timeDifference = readUInt().toLong() - currentTimeSeconds() + timeDifference = readInt().toUInt().toLong() - currentTimeSeconds() ipFromT149 = readBytes(4) } diff --git a/mirai-core/src/commonMain/kotlin/utils/io/output.kt b/mirai-core/src/commonMain/kotlin/utils/io/output.kt index 5c4270666..360e16aae 100644 --- a/mirai-core/src/commonMain/kotlin/utils/io/output.kt +++ b/mirai-core/src/commonMain/kotlin/utils/io/output.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -52,7 +52,7 @@ internal inline fun BytePacketBuilder.writeIntLVPacket( crossinline builder: BytePacketBuilder.() -> Unit, ): Int = buildPacket(builder).use { - if (tag != null) writeUByte(tag) + if (tag != null) writeByte(tag.toByte()) val length = lengthOffset.invoke(it.remaining).coerceAtMostOrFail(0xFFFFFFFFL) writeInt(length.toInt()) writePacket(it) @@ -64,9 +64,9 @@ internal inline fun BytePacketBuilder.writeShortLVPacket( lengthOffset: ((Long) -> Long) = { it }, crossinline builder: BytePacketBuilder.() -> Unit, ): Int = buildPacket(builder).use { - if (tag != null) writeUByte(tag) + if (tag != null) writeByte(tag.toByte()) val length = lengthOffset.invoke(it.remaining).coerceAtMostOrFail(0xFFFFFFFFL) - writeUShort(length.toUShort()) + writeShort(length.toUShort().toShort()) writePacket(it) return length.toInt() } @@ -76,7 +76,7 @@ internal inline fun BytePacketBuilder.writeShortLVString(str: String) = writeSho internal fun BytePacketBuilder.writeHex(uHex: String) { uHex.split(" ").forEach { if (it.isNotBlank()) { - writeUByte(it.toUByte(16)) + writeByte(it.toUByte(16).toByte()) } } } diff --git a/mirai-core/src/commonMain/kotlin/utils/io/serialization/tars/internal/TarsInput.kt b/mirai-core/src/commonMain/kotlin/utils/io/serialization/tars/internal/TarsInput.kt index 330669730..75ff26d5f 100644 --- a/mirai-core/src/commonMain/kotlin/utils/io/serialization/tars/internal/TarsInput.kt +++ b/mirai-core/src/commonMain/kotlin/utils/io/serialization/tars/internal/TarsInput.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -79,7 +79,7 @@ internal class TarsInput( return null } val var2 = try { - input.readUByte() + input.readByte().toUByte() } catch (e: EOFException) { // somehow `endOfInput` still returns false return null @@ -87,7 +87,7 @@ internal class TarsInput( val type = var2 and 15u var tag = var2.toUInt() shr 4 if (tag == 15u) { - tag = input.readUByte().toUInt() + tag = input.readByte().toUByte().toUInt() } return TarsHead( tag = tag.toInt(), @@ -171,7 +171,7 @@ internal class TarsInput( Tars.LONG -> this.input.discardExact(8) Tars.FLOAT -> this.input.discardExact(4) Tars.DOUBLE -> this.input.discardExact(8) - Tars.STRING1 -> this.input.discardExact(this.input.readUByte().toInt()) + Tars.STRING1 -> this.input.discardExact(this.input.readByte().toUByte().toInt()) Tars.STRING4 -> this.input.discardExact(this.input.readInt()) Tars.MAP -> { // map debugLogger.structureHierarchy++ @@ -279,9 +279,9 @@ internal class TarsInput( fun readTarsStringValue(head: TarsHead): String { //debugLogger.println("readTarsStringValue: $head") return when (head.type) { - Tars.STRING1 -> input.readString(input.readUByte().toInt(), charset = charset) + Tars.STRING1 -> input.readString(input.readByte().toUByte().toInt(), charset = charset) Tars.STRING4 -> input.readString( - input.readUInt().toInt().also { require(it in 1 until 104857600) { "bad string length: $it" } }, + input.readInt().toUInt().toInt().also { require(it in 1 until 104857600) { "bad string length: $it" } }, charset = charset ) else -> error("type mismatch: $head, expecting 6 or 7 (for string)") diff --git a/mirai-core/src/nativeMain/kotlin/contact/GroupImpl.kt b/mirai-core/src/nativeMain/kotlin/contact/GroupImpl.kt index f73074a7f..40246af70 100644 --- a/mirai-core/src/nativeMain/kotlin/contact/GroupImpl.kt +++ b/mirai-core/src/nativeMain/kotlin/contact/GroupImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -22,5 +22,5 @@ internal actual class GroupImpl actual constructor( groupInfo: GroupInfo, members: ContactList, ) : Group, CommonGroupImpl(bot, parentCoroutineContext, id, groupInfo, members) { - actual companion object; + actual companion object } \ No newline at end of file diff --git a/mirai-dokka/src/system.kt b/mirai-dokka/src/system.kt index 9891e4ee6..102e5f2d5 100644 --- a/mirai-dokka/src/system.kt +++ b/mirai-dokka/src/system.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 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. @@ -9,10 +9,13 @@ package net.mamoe.mirai.dokka +import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.json.Json import java.io.File val pages = File("mirai-dokka/pages") + +@OptIn(ExperimentalSerializationApi::class) val json = Json { prettyPrint = true prettyPrintIndent = " "