From 90c0c5c549838795f396ba0229a668c0629d3fd6 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 10 May 2020 02:22:16 +0800 Subject: [PATCH] Optimize experimental API usages --- .../compatibility/CombinedMessageTest.kt | 2 +- mirai-core-qqandroid/build.gradle.kts | 7 ++++ .../net/mamoe/mirai/qqandroid/QQAndroid.kt | 2 -- .../mirai/qqandroid/QQAndroidBot.android.kt | 1 - .../qqandroid/utils/cryptor/ECDHAndroid.kt | 1 - .../net/mamoe/mirai/qqandroid/BotAccount.kt | 4 +-- .../mirai/qqandroid/QQAndroidBot.common.kt | 5 +-- .../mirai/qqandroid/contact/FriendImpl.kt | 3 +- .../mirai/qqandroid/contact/GroupImpl.kt | 8 ----- .../mirai/qqandroid/contact/MemberImpl.kt | 7 ++-- .../net/mamoe/mirai/qqandroid/contact/util.kt | 5 --- .../mirai/qqandroid/message/convension.kt | 2 -- .../network/QQAndroidBotNetworkHandler.kt | 10 +++--- .../qqandroid/network/QQAndroidClient.kt | 3 -- .../network/highway/HighwayHelper.kt | 9 ++---- .../qqandroid/network/highway/highway.kt | 4 +-- .../network/protocol/packet/EncryptMethod.kt | 1 - .../protocol/packet/OutgoingPacketAndroid.kt | 7 ++-- .../network/protocol/packet/PacketFactory.kt | 6 ---- .../qqandroid/network/protocol/packet/Tlv.kt | 9 +++--- .../network/protocol/packet/chat/MultiMsg.kt | 5 +-- .../chat/receive/MessageSvc.PbGetMsg.kt | 32 ++++++------------- .../chat/receive/OnlinePush.PbPushTransMsg.kt | 2 +- .../packet/chat/receive/OnlinePush.ReqPush.kt | 2 -- .../network/protocol/packet/login/StatSvc.kt | 3 +- .../network/protocol/packet/login/WtLogin.kt | 7 ---- .../mamoe/mirai/qqandroid/utils/byteArrays.kt | 4 --- .../mamoe/mirai/qqandroid/utils/io/input.kt | 2 -- .../mamoe/mirai/qqandroid/utils/io/output.kt | 3 +- .../utils/PlatformUtilsTest.kt | 2 -- .../net/mamoe/mirai/qqandroid/QQAndroid.kt | 1 - .../mamoe/mirai/qqandroid/QQAndroidBot.jvm.kt | 4 +-- .../mirai/qqandroid/utils/PlatformSocket.kt | 1 - .../mirai/qqandroid/utils/cryptor/ECDHJvm.kt | 1 - mirai-core/build.gradle.kts | 7 ++++ .../net/mamoe/mirai/BotJavaFriendlyAPI.kt | 3 +- .../kotlin/net/mamoe/mirai/contact/Member.kt | 1 - .../net/mamoe/mirai/message/MessagePacket.kt | 1 - .../mirai/utils/ExternalImage.android.kt | 1 - .../mirai/utils/SystemDeviceInfo.android.kt | 2 -- .../commonMain/kotlin/net.mamoe.mirai/Bot.kt | 2 -- .../kotlin/net.mamoe.mirai/BotImpl.kt | 3 +- .../kotlin/net.mamoe.mirai/contact/Group.kt | 6 ++-- .../kotlin/net.mamoe.mirai/contact/Member.kt | 3 +- .../kotlin/net.mamoe.mirai/event/Event.kt | 2 -- .../net.mamoe.mirai/event/deprecated.kt | 5 --- .../net.mamoe.mirai/event/events/BotEvents.kt | 1 - .../net.mamoe.mirai/event/events/types.kt | 2 -- .../event/internal/InternalEventListeners.kt | 9 +++--- .../kotlin/net.mamoe.mirai/event/select.kt | 3 -- .../event/subscribeMessages.kt | 6 +--- .../event/subscriberDeprecated.kt | 5 --- .../net.mamoe.mirai/message/MessageReceipt.kt | 2 -- .../message/data/CombinedMessage.kt | 5 ++- .../message/data/CustomMessage.kt | 3 -- .../message/data/ForwardMessage.kt | 2 -- .../message/data/HummerMessage.kt | 10 ++---- .../net.mamoe.mirai/message/data/Image.kt | 4 --- .../net.mamoe.mirai/message/data/Message.kt | 7 ---- .../message/data/MessageChain.kt | 4 --- .../message/data/MessageChainBuilder.kt | 2 -- .../message/data/MessageSource.kt | 8 ++--- .../message/data/QuoteReply.kt | 2 -- .../message/data/RichMessage.kt | 2 +- .../net.mamoe.mirai/message/data/impl.kt | 8 +---- .../network/BotNetworkHandler.kt | 2 +- .../net.mamoe.mirai/utils/BotConfiguration.kt | 3 -- .../net.mamoe.mirai/utils/DeviceInfo.kt | 1 - .../internal/DeferredReusableInput.common.kt | 3 +- .../mirai/message.data/CombinedMessageTest.kt | 3 +- .../mirai/message.data/ConstrainSingleTest.kt | 7 ++-- .../mirai/utils/FileCacheStrategy.jvm.kt | 1 - .../net/mamoe/mirai/utils/LoginSolver.jvm.kt | 2 +- .../net/mamoe/mirai/utils/SystemDeviceInfo.kt | 1 - .../internal/DeferredReusableInput.jvm.kt | 2 +- .../net/mamoe/mirai/event/EventTests.kt | 1 - .../mamoe/mirai/event/JvmMethodEventsTest.kt | 14 ++++++-- .../mirai/utils/LockFreeLinkedListTest.kt | 4 +-- 78 files changed, 93 insertions(+), 237 deletions(-) diff --git a/compatibility-validator/src/test/kotlin/compatibility/CombinedMessageTest.kt b/compatibility-validator/src/test/kotlin/compatibility/CombinedMessageTest.kt index a3aafeaef..d0271336c 100644 --- a/compatibility-validator/src/test/kotlin/compatibility/CombinedMessageTest.kt +++ b/compatibility-validator/src/test/kotlin/compatibility/CombinedMessageTest.kt @@ -5,7 +5,7 @@ import net.mamoe.mirai.utils.MiraiInternalAPI import kotlin.test.Test import kotlin.test.assertEquals -@OptIn(MiraiInternalAPI::class) + internal class CombinedMessageTest { diff --git a/mirai-core-qqandroid/build.gradle.kts b/mirai-core-qqandroid/build.gradle.kts index b20a1ff8b..750b0a564 100644 --- a/mirai-core-qqandroid/build.gradle.kts +++ b/mirai-core-qqandroid/build.gradle.kts @@ -40,6 +40,13 @@ kotlin { all { languageSettings.enableLanguageFeature("InlineClasses") languageSettings.useExperimentalAnnotation("kotlin.Experimental") + languageSettings.useExperimentalAnnotation("net.mamoe.mirai.utils.MiraiInternalAPI") + languageSettings.useExperimentalAnnotation("net.mamoe.mirai.utils.MiraiExperimentalAPI") + languageSettings.useExperimentalAnnotation("net.mamoe.mirai.LowLevelAPI") + languageSettings.useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes") + languageSettings.useExperimentalAnnotation("kotlin.experimental.ExperimentalTypeInference") + languageSettings.useExperimentalAnnotation("kotlin.time.ExperimentalTime") + languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") languageSettings.progressiveMode = true dependencies { diff --git a/mirai-core-qqandroid/src/androidMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroid.kt b/mirai-core-qqandroid/src/androidMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroid.kt index 63c3d23b7..94b37a120 100644 --- a/mirai-core-qqandroid/src/androidMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroid.kt +++ b/mirai-core-qqandroid/src/androidMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroid.kt @@ -22,7 +22,6 @@ import net.mamoe.mirai.utils.MiraiInternalAPI */ @Suppress("INAPPLICABLE_JVM_NAME") actual object QQAndroid : BotFactory { - @OptIn(MiraiInternalAPI::class) @JvmName("newBot") actual override fun Bot(context: Context, qq: Long, password: String, configuration: BotConfiguration): Bot { return QQAndroidBot(context, BotAccount(qq, password), configuration) @@ -31,7 +30,6 @@ actual object QQAndroid : BotFactory { /** * 使用指定的 [配置][configuration] 构造 [Bot] 实例 */ - @OptIn(MiraiInternalAPI::class) @JvmName("newBot") actual override fun Bot( context: Context, diff --git a/mirai-core-qqandroid/src/androidMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.android.kt b/mirai-core-qqandroid/src/androidMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.android.kt index e03b605bf..435bd90e7 100644 --- a/mirai-core-qqandroid/src/androidMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.android.kt +++ b/mirai-core-qqandroid/src/androidMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.android.kt @@ -21,7 +21,6 @@ import net.mamoe.mirai.qqandroid.utils.toReadPacket import net.mamoe.mirai.utils.MiraiInternalAPI import java.nio.ByteBuffer -@OptIn(MiraiInternalAPI::class) @Suppress("DEPRECATION") internal actual fun ByteReadChannel.toKotlinByteReadChannel(): kotlinx.coroutines.io.ByteReadChannel { return object : kotlinx.coroutines.io.ByteReadChannel { diff --git a/mirai-core-qqandroid/src/androidMain/kotlin/net/mamoe/mirai/qqandroid/utils/cryptor/ECDHAndroid.kt b/mirai-core-qqandroid/src/androidMain/kotlin/net/mamoe/mirai/qqandroid/utils/cryptor/ECDHAndroid.kt index 9972c0045..f37acab06 100644 --- a/mirai-core-qqandroid/src/androidMain/kotlin/net/mamoe/mirai/qqandroid/utils/cryptor/ECDHAndroid.kt +++ b/mirai-core-qqandroid/src/androidMain/kotlin/net/mamoe/mirai/qqandroid/utils/cryptor/ECDHAndroid.kt @@ -85,7 +85,6 @@ internal actual class ECDH actual constructor(actual val keyPair: ECDHKeyPair) { .genKeyPair()) } - @OptIn(MiraiInternalAPI::class) actual fun calculateShareKey( privateKey: ECDHPrivateKey, publicKey: ECDHPublicKey diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/BotAccount.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/BotAccount.kt index 6530230af..19f8e5597 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/BotAccount.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/BotAccount.kt @@ -26,8 +26,6 @@ internal data class BotAccount( val passwordMd5: ByteArray // md5 ) { constructor(id: Long, passwordPlainText: String) : this(id, MiraiPlatformUtils.md5(passwordPlainText.toByteArray())) - - @OptIn(MiraiInternalAPI::class) override fun equals(other: Any?): Boolean { if (this === other) return true if (other == null || this::class != other::class) return false @@ -40,7 +38,7 @@ internal data class BotAccount( return true } - @OptIn(MiraiInternalAPI::class) + override fun hashCode(): Int { var result = id.hashCode() result = 31 * result + passwordMd5.contentHashCode() diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt index 668dbcbbd..d102c0881 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt @@ -70,7 +70,6 @@ internal fun Bot.asQQAndroidBot(): QQAndroidBot { } @Suppress("INVISIBLE_MEMBER", "BooleanLiteralArgument") -@OptIn(MiraiInternalAPI::class) internal class QQAndroidBot constructor( context: Context, account: BotAccount, @@ -232,7 +231,7 @@ internal class QQAndroidBot constructor( } } -@OptIn(MiraiInternalAPI::class, MiraiExperimentalAPI::class) + internal abstract class QQAndroidBotBase constructor( context: Context, private val account: BotAccount, @@ -771,11 +770,9 @@ internal abstract class QQAndroidBotBase constructor( internal val EMPTY_BYTE_ARRAY = ByteArray(0) @Suppress("DEPRECATION") -@OptIn(MiraiInternalAPI::class) internal expect fun io.ktor.utils.io.ByteReadChannel.toKotlinByteReadChannel(): ByteReadChannel -@OptIn(MiraiInternalAPI::class) private fun RichMessage.Templates.longMessage(brief: String, resId: String, timeSeconds: Long): RichMessage { val limited: String = if (brief.length > 30) { brief.take(30) + "…" diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/FriendImpl.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/FriendImpl.kt index 86f7f7426..585e3aa06 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/FriendImpl.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/FriendImpl.kt @@ -41,7 +41,6 @@ import kotlin.contracts.contract import kotlin.coroutines.CoroutineContext import kotlin.jvm.JvmSynthetic import kotlin.math.roundToInt -import kotlin.time.ExperimentalTime import kotlin.time.measureTime internal inline class FriendInfoImpl( @@ -85,7 +84,7 @@ internal class FriendImpl( } @JvmSynthetic - @OptIn(MiraiInternalAPI::class, ExperimentalStdlibApi::class, ExperimentalTime::class) + override suspend fun uploadImage(image: ExternalImage): Image = try { @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") if (image.input is net.mamoe.mirai.utils.internal.DeferredReusableInput) { diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt index 2040aa7f7..9265db0ae 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt @@ -36,13 +36,11 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive.MessageSvc import net.mamoe.mirai.qqandroid.network.protocol.packet.list.ProfileService import net.mamoe.mirai.qqandroid.utils.estimateLength import net.mamoe.mirai.utils.* -import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract import kotlin.coroutines.CoroutineContext import kotlin.jvm.JvmSynthetic import kotlin.time.ExperimentalTime -@OptIn(ExperimentalContracts::class) internal fun GroupImpl.Companion.checkIsInstance(instance: Group) { contract { returns() implies (instance is GroupImpl) @@ -50,7 +48,6 @@ internal fun GroupImpl.Companion.checkIsInstance(instance: Group) { check(instance is GroupImpl) { "group is not an instanceof GroupImpl!! DO NOT interlace two or more protocol implementations!!" } } -@OptIn(ExperimentalContracts::class) internal fun Group.checkIsGroupImpl() { contract { returns() implies (this@checkIsGroupImpl is GroupImpl) @@ -58,7 +55,6 @@ internal fun Group.checkIsGroupImpl() { GroupImpl.checkIsInstance(this) } -@OptIn(MiraiExperimentalAPI::class, LowLevelAPI::class) @Suppress("PropertyName") internal class GroupImpl( bot: QQAndroidBot, @@ -249,10 +245,8 @@ internal class GroupImpl( return true } - @OptIn(MiraiExperimentalAPI::class) override fun newMember(memberInfo: MemberInfo): Member { return MemberImpl( - @OptIn(LowLevelAPI::class) bot._lowLevelNewFriend(memberInfo) as FriendImpl, this, this.coroutineContext, @@ -290,7 +284,6 @@ internal class GroupImpl( return members.firstOrNull { it.id == id } } - @OptIn(MiraiExperimentalAPI::class, LowLevelAPI::class) @JvmSynthetic override suspend fun sendMessage(message: Message): MessageReceipt { require(message.isContentNotEmpty()) { "message is empty" } @@ -301,7 +294,6 @@ internal class GroupImpl( } } - @OptIn(MiraiExperimentalAPI::class) private suspend fun sendMessageImpl(message: Message, isForward: Boolean): MessageReceipt { if (message is MessageChain) { if (message.anyIsInstance()) { diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt index 467818cdf..b967dba86 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt @@ -33,7 +33,10 @@ import net.mamoe.mirai.qqandroid.message.MessageSourceToTempImpl import net.mamoe.mirai.qqandroid.network.protocol.data.jce.StTroopMemberInfo import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.TroopManagement import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive.MessageSvcPbSendMsg -import net.mamoe.mirai.utils.* +import net.mamoe.mirai.utils.ExternalImage +import net.mamoe.mirai.utils.currentTimeSeconds +import net.mamoe.mirai.utils.getValue +import net.mamoe.mirai.utils.unsafeWeakRef import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract import kotlin.coroutines.CoroutineContext @@ -189,7 +192,7 @@ internal class MemberImpl constructor( net.mamoe.mirai.event.events.MemberUnmuteEvent(this@MemberImpl, null).broadcast() } - @OptIn(MiraiInternalAPI::class) + @JvmSynthetic override suspend fun kick(message: String) { checkBotPermissionHigherThanThis() diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/util.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/util.kt index 65afec207..800882390 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/util.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/util.kt @@ -24,11 +24,8 @@ import net.mamoe.mirai.qqandroid.message.ensureSequenceIdAvailable import net.mamoe.mirai.qqandroid.message.firstIsInstanceOrNull import net.mamoe.mirai.qqandroid.network.QQAndroidBotNetworkHandler import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive.MessageSvcPbSendMsg -import net.mamoe.mirai.utils.MiraiExperimentalAPI -import net.mamoe.mirai.utils.MiraiInternalAPI import net.mamoe.mirai.utils.verbose -@OptIn(MiraiInternalAPI::class) internal suspend fun Friend.sendMessageImpl(generic: T, message: Message): MessageReceipt { val event = MessageSendEvent.FriendMessageSendEvent(this, message.asMessageChain()).broadcast() if (event.isCancelled) { @@ -50,7 +47,6 @@ internal suspend fun Friend.sendMessageImpl(generic: T, message: M return MessageReceipt(source, generic, null) } -@OptIn(MiraiInternalAPI::class, MiraiExperimentalAPI::class) internal fun Contact.logMessageSent(message: Message) { @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") if (message !is net.mamoe.mirai.message.data.LongMessage) { @@ -58,7 +54,6 @@ internal fun Contact.logMessageSent(message: Message) { } } -@OptIn(MiraiInternalAPI::class, MiraiExperimentalAPI::class) internal fun MessageEvent.logMessageReceived() { when (this) { is GroupMessageEvent -> bot.logger.verbose { diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/convension.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/convension.kt index c2770bee5..be026c9f4 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/convension.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/convension.kt @@ -36,7 +36,6 @@ private val UNSUPPORTED_POKE_MESSAGE_PLAIN = PlainText("[戳一戳]请使用最 private val UNSUPPORTED_FLASH_MESSAGE_PLAIN = PlainText("[闪照]请使用新版手机QQ查看闪照。") @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") -@OptIn(MiraiInternalAPI::class, MiraiExperimentalAPI::class) internal fun MessageChain.toRichTextElems(forGroup: Boolean, withGeneralFlags: Boolean): MutableList { val elements = ArrayList(this.size) @@ -302,7 +301,6 @@ internal inline fun Iterable<*>.firstIsInstanceOrNull(): R? { internal val MIRAI_CUSTOM_ELEM_TYPE = "mirai".hashCode() // 103904510 @Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") -@OptIn(MiraiInternalAPI::class, LowLevelAPI::class, ExperimentalStdlibApi::class) internal fun List.joinToMessageChain(groupIdOrZero: Long, bot: Bot, list: MessageChainBuilder) { // (this._miraiContentToString()) this.forEach { element -> diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt index 4af5e3b1b..e3a74a567 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt @@ -20,7 +20,6 @@ import kotlinx.io.core.ByteReadPacket import kotlinx.io.core.buildPacket import kotlinx.io.core.use import net.mamoe.mirai.event.* -import net.mamoe.mirai.event.Listener.EventPriority.MONITOR import net.mamoe.mirai.event.events.BotOfflineEvent import net.mamoe.mirai.event.events.BotOnlineEvent import net.mamoe.mirai.event.events.BotReloginEvent @@ -50,10 +49,8 @@ import net.mamoe.mirai.utils.* import kotlin.coroutines.CoroutineContext import kotlin.jvm.JvmField import kotlin.jvm.Volatile -import kotlin.time.ExperimentalTime @Suppress("MemberVisibilityCanBePrivate") -@OptIn(MiraiInternalAPI::class) internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bot: QQAndroidBot) : BotNetworkHandler() { override val bot: QQAndroidBot by bot.unsafeWeakRef() override val supervisor: CompletableJob = SupervisorJob(coroutineContext[Job]) @@ -114,7 +111,7 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo }.also { heartbeatJob = it } } - @OptIn(MiraiExperimentalAPI::class) + override suspend fun closeEverythingAndRelogin(host: String, port: Int, cause: Throwable?) { heartbeatJob?.cancel(CancellationException("relogin", cause)) heartbeatJob?.join() @@ -314,7 +311,7 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo initGroupOk = true } - @OptIn(MiraiExperimentalAPI::class, ExperimentalTime::class) + override suspend fun init(): Unit = coroutineScope { check(bot.isActive) { "bot is dead therefore network can't init" } check(this@QQAndroidBotNetworkHandler.isActive) { "network is dead therefore can't init" } @@ -390,7 +387,8 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo } init { - val listener = bot.subscribeAlways(priority = MONITOR) { + @Suppress("RemoveRedundantQualifierName") + val listener = bot.subscribeAlways(priority = Listener.EventPriority.MONITOR) { if (bot != this.bot) return@subscribeAlways this@QQAndroidBotNetworkHandler.launch { syncMessageSvc() } } diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt index d2fae3d0c..406e5fc20 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt @@ -35,7 +35,6 @@ internal val DeviceInfo.guid: ByteArray get() = generateGuid(androidId, macAddre * Defaults "%4;7t>;28> by setOf( DOMAINS Pskey: "openmobile.qq.com" */ -@OptIn(MiraiExperimentalAPI::class, MiraiInternalAPI::class) @PublishedApi internal open class QQAndroidClient( context: Context, @@ -270,7 +268,6 @@ internal open class QQAndroidClient( } @Suppress("RemoveRedundantQualifierName") // bug -@OptIn(MiraiInternalAPI::class) internal fun generateTgtgtKey(guid: ByteArray): ByteArray = net.mamoe.mirai.qqandroid.utils.MiraiPlatformUtils.md5(getRandomByteArray(16) + guid) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/highway/HighwayHelper.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/highway/HighwayHelper.kt index 817edac2f..e3fa1df69 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/highway/HighwayHelper.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/highway/HighwayHelper.kt @@ -26,7 +26,6 @@ import kotlinx.coroutines.isActive import kotlinx.coroutines.withTimeoutOrNull import kotlinx.io.core.discardExact import kotlinx.io.core.use -import kotlinx.serialization.InternalSerializationApi import net.mamoe.mirai.qqandroid.QQAndroidBot import net.mamoe.mirai.qqandroid.network.QQAndroidClient import net.mamoe.mirai.qqandroid.network.protocol.data.proto.CSDataHighwayHead @@ -36,8 +35,6 @@ import net.mamoe.mirai.qqandroid.utils.addSuppressedMirai import net.mamoe.mirai.qqandroid.utils.io.serialization.readProtoBuf import net.mamoe.mirai.qqandroid.utils.io.withUse import net.mamoe.mirai.qqandroid.utils.toIpV4AddressString -import net.mamoe.mirai.utils.MiraiExperimentalAPI -import net.mamoe.mirai.utils.MiraiInternalAPI import net.mamoe.mirai.utils.internal.ReusableInput import net.mamoe.mirai.utils.verbose import kotlin.coroutines.EmptyCoroutineContext @@ -45,7 +42,7 @@ import kotlin.math.roundToInt import kotlin.time.ExperimentalTime import kotlin.time.measureTime -@OptIn(MiraiInternalAPI::class, InternalSerializationApi::class) + @Suppress("SpellCheckingInspection") internal suspend fun HttpClient.postImage( htcmd: String, @@ -77,7 +74,7 @@ internal suspend fun HttpClient.postImage( override val contentType: ContentType = ContentType.Image.Any override val contentLength: Long = imageInput.size - @OptIn(MiraiExperimentalAPI::class) + override suspend fun writeTo(channel: ByteWriteChannel) { imageInput.writeTo(channel) @@ -85,7 +82,7 @@ internal suspend fun HttpClient.postImage( } } == HttpStatusCode.OK -@OptIn(MiraiInternalAPI::class, InternalSerializationApi::class) + internal object HighwayHelper { @Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") suspend fun uploadImageToServers( diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/highway/highway.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/highway/highway.kt index 6a8e174c6..b679bf9e8 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/highway/highway.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/highway/highway.kt @@ -14,20 +14,18 @@ package net.mamoe.mirai.qqandroid.network.highway import kotlinx.io.core.ByteReadPacket import kotlinx.io.core.buildPacket import kotlinx.io.core.writeFully -import kotlinx.serialization.InternalSerializationApi import net.mamoe.mirai.qqandroid.network.QQAndroidClient import net.mamoe.mirai.qqandroid.network.protocol.data.proto.CSDataHighwayHead import net.mamoe.mirai.qqandroid.network.protocol.packet.EMPTY_BYTE_ARRAY import net.mamoe.mirai.qqandroid.utils.ByteArrayPool import net.mamoe.mirai.qqandroid.utils.MiraiPlatformUtils import net.mamoe.mirai.qqandroid.utils.io.serialization.toByteArray -import net.mamoe.mirai.utils.MiraiInternalAPI import net.mamoe.mirai.utils.internal.ChunkedFlowSession import net.mamoe.mirai.utils.internal.ChunkedInput import net.mamoe.mirai.utils.internal.ReusableInput import net.mamoe.mirai.utils.internal.map -@OptIn(MiraiInternalAPI::class, InternalSerializationApi::class) + internal fun createImageDataPacketSequence( // RequestDataTrans client: QQAndroidClient, diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/EncryptMethod.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/EncryptMethod.kt index f663a0f9a..df1b7d3bb 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/EncryptMethod.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/EncryptMethod.kt @@ -19,7 +19,6 @@ import net.mamoe.mirai.qqandroid.utils.cryptor.ECDHKeyPair import net.mamoe.mirai.qqandroid.utils.io.encryptAndWrite import net.mamoe.mirai.qqandroid.utils.io.writeShortLVByteArray -@OptIn(ExperimentalUnsignedTypes::class) internal interface EncryptMethod { val id: Int diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/OutgoingPacketAndroid.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/OutgoingPacketAndroid.kt index d635a21e0..311079835 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/OutgoingPacketAndroid.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/OutgoingPacketAndroid.kt @@ -35,7 +35,6 @@ internal val KEY_16_ZEROS = ByteArray(16) internal val EMPTY_BYTE_ARRAY = ByteArray(0) @Suppress("DuplicatedCode") -@OptIn(MiraiInternalAPI::class) internal inline fun OutgoingPacketFactory<*>.buildOutgoingUniPacket( client: QQAndroidClient, bodyType: Byte = 1, // 1: PB? @@ -67,7 +66,6 @@ internal inline fun OutgoingPacketFactory<*>.buildOutgoingUniPacket( } -@OptIn(MiraiInternalAPI::class) internal inline fun IncomingPacketFactory<*>.buildResponseUniPacket( client: QQAndroidClient, bodyType: Byte = 1, // 1: PB? @@ -98,7 +96,7 @@ internal inline fun IncomingPacketFactory<*>.buildResponseUniPacket( }) } -@OptIn(MiraiInternalAPI::class) + private inline fun BytePacketBuilder.writeUniPacket( commandName: String, unknownData: ByteArray, @@ -131,7 +129,6 @@ internal val NO_ENCRYPT: ByteArray = ByteArray(0) /** * com.tencent.qphone.base.util.CodecWarpper#encodeRequest(int, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, byte[], int, int, java.lang.String, byte, byte, byte, byte[], byte[], boolean) */ -@OptIn(MiraiInternalAPI::class) internal inline fun OutgoingPacketFactory<*>.buildLoginOutgoingPacket( client: QQAndroidClient, bodyType: Byte, @@ -169,7 +166,7 @@ internal inline fun OutgoingPacketFactory<*>.buildLoginOutgoingPacket( private inline val BRP_STUB get() = ByteReadPacket.Empty -@OptIn(MiraiInternalAPI::class) + internal inline fun BytePacketBuilder.writeSsoPacket( client: QQAndroidClient, subAppId: Long, diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/PacketFactory.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/PacketFactory.kt index 54be09f01..2c1e28cdb 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/PacketFactory.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/PacketFactory.kt @@ -54,7 +54,6 @@ internal sealed class PacketFactory { * * @param TPacket 服务器回复包解析结果 */ -@OptIn(ExperimentalUnsignedTypes::class) internal abstract class OutgoingPacketFactory( /** * 命令名. 如 `wtlogin.login`, `ConfigPushSvc.PushDomain` @@ -125,7 +124,6 @@ internal typealias PacketConsumer = suspend (packetFactory: PacketFactory, @PublishedApi internal val PacketLogger: MiraiLoggerWithSwitch = DefaultLogger("Packet").withSwitch(false) -@OptIn(ExperimentalUnsignedTypes::class) internal object KnownPacketFactories { object OutgoingFactories : List> by mutableListOf( WtLogin.Login, @@ -174,7 +172,6 @@ internal object KnownPacketFactories { } // do not inline. Exceptions thrown will not be reported correctly - @OptIn(MiraiInternalAPI::class) @Suppress("UNCHECKED_CAST") suspend fun parseIncomingPacket( bot: QQAndroidBot, @@ -235,7 +232,6 @@ internal object KnownPacketFactories { } } - @OptIn(MiraiInternalAPI::class) internal suspend fun handleIncomingPacket( it: IncomingPacket, bot: QQAndroidBot, @@ -296,7 +292,6 @@ internal object KnownPacketFactories { lateinit var consumer: PacketConsumer } - @OptIn(ExperimentalUnsignedTypes::class, MiraiInternalAPI::class) private fun parseSsoFrame(bot: QQAndroidBot, input: ByteReadPacket): IncomingPacket<*> { val commandName: String val ssoSequenceId: Int @@ -355,7 +350,6 @@ internal object KnownPacketFactories { return IncomingPacket(packetFactory, ssoSequenceId, packet, commandName) } - @OptIn(MiraiInternalAPI::class) private suspend fun ByteReadPacket.parseOicqResponse( bot: QQAndroidBot, packetFactory: OutgoingPacketFactory, diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/Tlv.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/Tlv.kt index 36181578d..19a6aff65 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/Tlv.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/Tlv.kt @@ -20,7 +20,6 @@ import net.mamoe.mirai.qqandroid.utils.MiraiPlatformUtils import net.mamoe.mirai.qqandroid.utils.NetworkType import net.mamoe.mirai.qqandroid.utils.io.* import net.mamoe.mirai.qqandroid.utils.toByteArray -import net.mamoe.mirai.utils.MiraiInternalAPI import net.mamoe.mirai.utils.currentTimeMillis import kotlin.random.Random @@ -80,7 +79,7 @@ internal fun BytePacketBuilder.t18( } shouldEqualsTo 22 } -@OptIn(MiraiInternalAPI::class) + internal fun BytePacketBuilder.t106( appId: Long = 16L, subAppId: Long, @@ -326,7 +325,7 @@ internal fun BytePacketBuilder.t144( } } -@OptIn(MiraiInternalAPI::class) + internal fun BytePacketBuilder.t109( androidId: ByteArray ) { @@ -562,7 +561,7 @@ internal fun BytePacketBuilder.t400( } } -@OptIn(MiraiInternalAPI::class) + internal fun BytePacketBuilder.t187( macAddress: ByteArray ) { @@ -572,7 +571,7 @@ internal fun BytePacketBuilder.t187( } } -@OptIn(MiraiInternalAPI::class) + internal fun BytePacketBuilder.t188( androidId: ByteArray ) { diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/MultiMsg.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/MultiMsg.kt index eb704131c..b3ce0bf79 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/MultiMsg.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/MultiMsg.kt @@ -31,9 +31,8 @@ import net.mamoe.mirai.qqandroid.utils._miraiContentToString import net.mamoe.mirai.qqandroid.utils.io.serialization.readProtoBuf import net.mamoe.mirai.qqandroid.utils.io.serialization.toByteArray import net.mamoe.mirai.qqandroid.utils.io.serialization.writeProtoBuf -import net.mamoe.mirai.utils.MiraiInternalAPI -internal class MessageValidationData @OptIn(MiraiInternalAPI::class) constructor( +internal class MessageValidationData( val data: ByteArray, val md5: ByteArray = MiraiPlatformUtils.md5(data) ) { @@ -44,8 +43,6 @@ internal class MessageValidationData @OptIn(MiraiInternalAPI::class) constructor @Suppress("NOTHING_TO_INLINE") internal inline fun Int.toLongUnsigned(): Long = this.toLong().and(0xFFFF_FFFF) - -@OptIn(MiraiInternalAPI::class) internal fun Collection.calculateValidationDataForGroup( sequenceId: Int, random: Int, diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.PbGetMsg.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.PbGetMsg.kt index 7a31849fe..1c1792713 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.PbGetMsg.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.PbGetMsg.kt @@ -14,7 +14,6 @@ import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.* import kotlinx.io.core.ByteReadPacket import kotlinx.io.core.discardExact -import net.mamoe.mirai.LowLevelAPI import net.mamoe.mirai.contact.Group import net.mamoe.mirai.contact.MemberPermission import net.mamoe.mirai.data.MemberInfo @@ -48,13 +47,15 @@ import net.mamoe.mirai.qqandroid.utils.io.serialization.writeProtoBuf import net.mamoe.mirai.qqandroid.utils.read import net.mamoe.mirai.qqandroid.utils.soutv import net.mamoe.mirai.qqandroid.utils.toUHexString -import net.mamoe.mirai.utils.* +import net.mamoe.mirai.utils.MiraiInternalAPI +import net.mamoe.mirai.utils.currentTimeSeconds +import net.mamoe.mirai.utils.debug +import net.mamoe.mirai.utils.warning /** * 获取好友消息和消息记录 */ -@OptIn(MiraiInternalAPI::class) internal object MessageSvcPbGetMsg : OutgoingPacketFactory("MessageSvc.PbGetMsg") { @Suppress("SpellCheckingInspection") operator fun invoke( @@ -86,7 +87,6 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory) : Response(MsgSvc.SyncFlag.STOP, delegate), Event, Packet.NoLog { override fun toString(): String = "MessageSvcPbGetMsg.GetMsgSuccess(messages=))" @@ -143,7 +143,6 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory { msg -> @@ -375,12 +372,9 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory = messages.toList() if (resp.syncFlag == MsgSvc.SyncFlag.STOP) { - return GetMsgSuccess( - list) + return GetMsgSuccess(list) } - return Response( - resp.syncFlag, - list) + return Response(resp.syncFlag, list) } override suspend fun QQAndroidBot.handle(packet: Response) { @@ -388,20 +382,14 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory return MsgSvc.SyncFlag.START -> { network.run { - MessageSvcPbGetMsg( - client, - MsgSvc.SyncFlag.CONTINUE, - currentTimeSeconds).sendAndExpect() + MessageSvcPbGetMsg(client, MsgSvc.SyncFlag.CONTINUE, currentTimeSeconds).sendAndExpect() } return } MsgSvc.SyncFlag.CONTINUE -> { network.run { - MessageSvcPbGetMsg( - client, - MsgSvc.SyncFlag.CONTINUE, - currentTimeSeconds).sendAndExpect() + MessageSvcPbGetMsg(client, MsgSvc.SyncFlag.CONTINUE, currentTimeSeconds).sendAndExpect() } return } diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.PbPushTransMsg.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.PbPushTransMsg.kt index a1a20bc4f..74d6e3600 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.PbPushTransMsg.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.PbPushTransMsg.kt @@ -42,7 +42,7 @@ import net.mamoe.mirai.utils.MiraiInternalAPI internal object OnlinePushPbPushTransMsg : IncomingPacketFactory("OnlinePush.PbPushTransMsg", "OnlinePush.RespPush") { - @OptIn(MiraiInternalAPI::class) + override suspend fun ByteReadPacket.decode(bot: QQAndroidBot, sequenceId: Int): Packet? { val content = this.readProtoBuf(OnlinePushTrans.PbMsgInfo.serializer()) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt index 77e2800bd..62d8a384b 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt @@ -23,7 +23,6 @@ import kotlinx.io.core.readBytes import kotlinx.io.core.readUInt import kotlinx.serialization.Serializable import net.mamoe.mirai.JavaFriendlyAPI -import net.mamoe.mirai.LowLevelAPI import net.mamoe.mirai.data.FriendInfo import net.mamoe.mirai.event.events.* import net.mamoe.mirai.getFriendOrNull @@ -352,7 +351,6 @@ internal inline fun lambda528(crossinline block: MsgType0x210.(QQAndroidBot) -> /** * @see MsgType0x210 */ -@OptIn(LowLevelAPI::class, MiraiInternalAPI::class) internal object Transformers528 : Map by mapOf( // Network(1994701021) 16:03:54 : unknown group 528 type 0x0000000000000026, data: 08 01 12 40 0A 06 08 F4 EF BB 8F 04 10 E7 C1 AD B8 02 18 01 22 2C 10 01 1A 1A 18 B4 DC F8 9B 0C 20 E7 C1 AD B8 02 28 06 30 02 A2 01 04 08 93 D6 03 A8 01 08 20 00 28 00 32 08 18 01 20 FE AF AF F5 05 28 00 diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/StatSvc.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/StatSvc.kt index 52733ddf2..4ec673d9e 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/StatSvc.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/StatSvc.kt @@ -28,7 +28,6 @@ import net.mamoe.mirai.qqandroid.utils.NetworkType import net.mamoe.mirai.qqandroid.utils.encodeToString import net.mamoe.mirai.qqandroid.utils.io.serialization.* import net.mamoe.mirai.qqandroid.utils.toReadPacket -import net.mamoe.mirai.utils.MiraiInternalAPI @Suppress("EnumEntryName", "unused") internal enum class RegPushReason { @@ -89,7 +88,7 @@ internal class StatSvc { override fun toString(): String = "Response(StatSvc.register)" } - @OptIn(MiraiInternalAPI::class) + operator fun invoke( client: QQAndroidClient, regPushReason: RegPushReason = RegPushReason.appRegister diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/WtLogin.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/WtLogin.kt index dbf39123a..4f68a5b42 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/WtLogin.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/WtLogin.kt @@ -10,7 +10,6 @@ package net.mamoe.mirai.qqandroid.network.protocol.packet.login -import io.ktor.util.InternalAPI import kotlinx.io.core.* import net.mamoe.mirai.qqandroid.QQAndroidBot import net.mamoe.mirai.qqandroid.network.* @@ -20,8 +19,6 @@ import net.mamoe.mirai.qqandroid.utils.* import net.mamoe.mirai.qqandroid.utils.cryptor.TEA import net.mamoe.mirai.qqandroid.utils.guidFlag import net.mamoe.mirai.qqandroid.utils.io.* -import net.mamoe.mirai.utils.MiraiExperimentalAPI -import net.mamoe.mirai.utils.MiraiInternalAPI import net.mamoe.mirai.utils.currentTimeSeconds import net.mamoe.mirai.utils.error @@ -30,7 +27,6 @@ internal class WtLogin { * OicqRequest */ @Suppress("FunctionName") - @OptIn(ExperimentalUnsignedTypes::class, MiraiInternalAPI::class) internal object Login : OutgoingPacketFactory("wtlogin.login") { /** * 提交验证码 @@ -125,7 +121,6 @@ internal class WtLogin { object SubCommand9 { private const val appId = 16L - @OptIn(MiraiInternalAPI::class, MiraiExperimentalAPI::class) operator fun invoke( client: QQAndroidClient ): OutgoingPacket = buildLoginOutgoingPacket(client, bodyType = 2) { sequenceId -> @@ -306,7 +301,6 @@ internal class WtLogin { } } - @InternalAPI override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): LoginPacketResponse { discardExact(2) // subCommand @@ -364,7 +358,6 @@ internal class WtLogin { } } - @InternalAPI private fun onSolveLoginCaptcha(tlvMap: TlvMap, bot: QQAndroidBot): LoginPacketResponse.Captcha { /* java.lang.IllegalStateException: UNKNOWN CAPTCHA QUESTION: diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/byteArrays.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/byteArrays.kt index a149413de..986056bb9 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/byteArrays.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/byteArrays.kt @@ -18,7 +18,6 @@ import kotlinx.io.charsets.Charsets import kotlinx.io.core.ByteReadPacket import kotlinx.io.core.String import kotlinx.io.core.use -import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.jvm.JvmMultifileClass @@ -29,7 +28,6 @@ import kotlin.jvm.JvmSynthetic @JvmOverloads @Suppress("DuplicatedCode") // false positive. foreach is not common to UByteArray and ByteArray -@OptIn(ExperimentalUnsignedTypes::class) internal fun List.toUHexString(separator: String = " ", offset: Int = 0, length: Int = this.size - offset): String { require(offset >= 0) { "offset shouldn't be negative: $offset" } require(length >= 0) { "length shouldn't be negative: $length" } @@ -53,7 +51,6 @@ internal fun List.toUHexString(separator: String = " ", offset: Int = 0, l @JvmOverloads @Suppress("DuplicatedCode") // false positive. foreach is not common to UByteArray and ByteArray -@OptIn(ExperimentalUnsignedTypes::class) internal fun ByteArray.toUHexString(separator: String = " ", offset: Int = 0, length: Int = this.size - offset): String { this.checkOffsetAndLength(offset, length) if (length == 0) { @@ -100,7 +97,6 @@ internal inline fun ByteArray.encodeToString(offset: Int = 0, charset: Charset = internal inline fun ByteArray.toReadPacket(offset: Int = 0, length: Int = this.size - offset) = ByteReadPacket(this, offset = offset, length = length) -@OptIn(ExperimentalContracts::class) internal inline fun ByteArray.read(t: ByteReadPacket.() -> R): R { contract { callsInPlace(t, InvocationKind.EXACTLY_ONCE) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/io/input.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/io/input.kt index 0b374df63..c1f976345 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/io/input.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/io/input.kt @@ -20,7 +20,6 @@ import net.mamoe.mirai.qqandroid.utils.ByteArrayPool import net.mamoe.mirai.qqandroid.utils.toReadPacket import net.mamoe.mirai.qqandroid.utils.toUHexString import net.mamoe.mirai.utils.MiraiInternalAPI -import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.jvm.JvmMultifileClass @@ -40,7 +39,6 @@ internal inline fun ByteReadPacket.readPacketExact( n: Int = remaining.toInt()//not that safe but adequate ): ByteReadPacket = this.readBytes(n).toReadPacket() -@OptIn(ExperimentalContracts::class) internal inline fun C.withUse(block: C.() -> R): R { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/io/output.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/io/output.kt index 88988f5bd..bffa648c4 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/io/output.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/io/output.kt @@ -16,7 +16,6 @@ package net.mamoe.mirai.qqandroid.utils.io import kotlinx.io.core.* import net.mamoe.mirai.qqandroid.utils.coerceAtMostOrFail import net.mamoe.mirai.qqandroid.utils.cryptor.TEA -import net.mamoe.mirai.utils.MiraiInternalAPI import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName @@ -66,6 +65,6 @@ internal fun BytePacketBuilder.writeHex(uHex: String) { } } -@OptIn(MiraiInternalAPI::class) + internal inline fun BytePacketBuilder.encryptAndWrite(key: ByteArray, encoder: BytePacketBuilder.() -> Unit) = TEA.encrypt(BytePacketBuilder().apply(encoder).build(), key) { decrypted -> writeFully(decrypted) } \ No newline at end of file diff --git a/mirai-core-qqandroid/src/commonTest/kotlin/net.mamoe.mirai.qqandroid/utils/PlatformUtilsTest.kt b/mirai-core-qqandroid/src/commonTest/kotlin/net.mamoe.mirai.qqandroid/utils/PlatformUtilsTest.kt index ca1520cbf..3f83bdf09 100644 --- a/mirai-core-qqandroid/src/commonTest/kotlin/net.mamoe.mirai.qqandroid/utils/PlatformUtilsTest.kt +++ b/mirai-core-qqandroid/src/commonTest/kotlin/net.mamoe.mirai.qqandroid/utils/PlatformUtilsTest.kt @@ -10,11 +10,9 @@ package net.mamoe.mirai.qqandroid.utils import kotlinx.io.core.toByteArray -import net.mamoe.mirai.utils.MiraiInternalAPI import kotlin.test.Test import kotlin.test.assertEquals -@OptIn(MiraiInternalAPI::class) internal class PlatformUtilsTest { @Test diff --git a/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroid.kt b/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroid.kt index 5bbe3976a..23938f132 100644 --- a/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroid.kt +++ b/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroid.kt @@ -22,7 +22,6 @@ import net.mamoe.mirai.utils.MiraiInternalAPI * QQ for Android */ @Suppress("INAPPLICABLE_JVM_NAME") -@OptIn(MiraiInternalAPI::class) actual object QQAndroid : BotFactory { /** diff --git a/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.jvm.kt b/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.jvm.kt index 93d9a9d19..cb1059d4b 100644 --- a/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.jvm.kt +++ b/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.jvm.kt @@ -23,12 +23,10 @@ import net.mamoe.mirai.utils.ContextImpl import net.mamoe.mirai.utils.MiraiInternalAPI import java.nio.ByteBuffer -@OptIn(MiraiInternalAPI::class) + @Suppress("FunctionName") internal fun QQAndroidBot(account: BotAccount, configuration: BotConfiguration): QQAndroidBot = QQAndroidBot(ContextImpl(), account, configuration) - -@OptIn(MiraiInternalAPI::class) @Suppress("DEPRECATION") internal actual fun ByteReadChannel.toKotlinByteReadChannel(): kotlinx.coroutines.io.ByteReadChannel { return object : kotlinx.coroutines.io.ByteReadChannel { diff --git a/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/utils/PlatformSocket.kt b/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/utils/PlatformSocket.kt index c89fd49cb..6503bfb8a 100644 --- a/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/utils/PlatformSocket.kt +++ b/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/utils/PlatformSocket.kt @@ -81,7 +81,6 @@ internal actual class PlatformSocket : Closeable { } } - @OptIn(ExperimentalIoApi::class) actual suspend fun connect(coroutineContext: CoroutineContext, serverHost: String, serverPort: Int) { withContext(Dispatchers.IO) { socket = Socket(serverHost, serverPort) diff --git a/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/utils/cryptor/ECDHJvm.kt b/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/utils/cryptor/ECDHJvm.kt index c194bce25..7dba21c72 100644 --- a/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/utils/cryptor/ECDHJvm.kt +++ b/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/utils/cryptor/ECDHJvm.kt @@ -71,7 +71,6 @@ internal actual class ECDH actual constructor(actual val keyPair: ECDHKeyPair) { .genKeyPair()) } - @OptIn(MiraiInternalAPI::class) actual fun calculateShareKey( privateKey: ECDHPrivateKey, publicKey: ECDHPublicKey diff --git a/mirai-core/build.gradle.kts b/mirai-core/build.gradle.kts index dd5041424..6d598a7a9 100644 --- a/mirai-core/build.gradle.kts +++ b/mirai-core/build.gradle.kts @@ -41,6 +41,13 @@ kotlin { all { languageSettings.enableLanguageFeature("InlineClasses") languageSettings.useExperimentalAnnotation("kotlin.Experimental") + languageSettings.useExperimentalAnnotation("net.mamoe.mirai.utils.MiraiInternalAPI") + languageSettings.useExperimentalAnnotation("net.mamoe.mirai.utils.MiraiExperimentalAPI") + languageSettings.useExperimentalAnnotation("net.mamoe.mirai.LowLevelAPI") + languageSettings.useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes") + languageSettings.useExperimentalAnnotation("kotlin.experimental.ExperimentalTypeInference") + languageSettings.useExperimentalAnnotation("kotlin.time.ExperimentalTime") + languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") languageSettings.progressiveMode = true } diff --git a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/BotJavaFriendlyAPI.kt b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/BotJavaFriendlyAPI.kt index ec484b75b..0a138e259 100644 --- a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/BotJavaFriendlyAPI.kt +++ b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/BotJavaFriendlyAPI.kt @@ -125,14 +125,13 @@ actual abstract class BotJavaFriendlyAPI actual constructor() { * @param message 若需要验证请求时的验证消息. * @param remark 好友备注 */ - @OptIn(MiraiExperimentalAPI::class) @JvmName("addFriend") fun __addFriendBlockingForJava__( id: Long, message: String? = null, remark: String? = null ): AddFriendResult { - @OptIn(MiraiExperimentalAPI::class) + return runBlocking { addFriend(id, message, remark) } } diff --git a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/contact/Member.kt b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/contact/Member.kt index 2dcc96814..a3773cb5f 100644 --- a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/contact/Member.kt +++ b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/contact/Member.kt @@ -25,7 +25,6 @@ import net.mamoe.mirai.utils.WeakRefProperty * 群成员. */ @Suppress("INAPPLICABLE_JVM_NAME") -@OptIn(MiraiInternalAPI::class, JavaFriendlyAPI::class) actual abstract class Member : MemberJavaFriendlyAPI() { /** * 所在的群. diff --git a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/message/MessagePacket.kt b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/message/MessagePacket.kt index a41a2420b..a65479d23 100644 --- a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/message/MessagePacket.kt +++ b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/message/MessagePacket.kt @@ -29,7 +29,6 @@ import java.net.URL message = "use ContactMessage", replaceWith = ReplaceWith("ContactMessage", "net.mamoe.mirai.message.ContactMessage") ) -@OptIn(MiraiInternalAPI::class) actual abstract class MessagePacket actual constructor() : MessagePacketBase() { diff --git a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/ExternalImage.android.kt b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/ExternalImage.android.kt index 9d6351218..286bfdfca 100644 --- a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/ExternalImage.android.kt +++ b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/ExternalImage.android.kt @@ -43,7 +43,6 @@ fun Bitmap.toExternalImage(formatName: String = "gif"): ExternalImage { /** * 读取文件头识别图片属性, 然后构造 [ExternalImage] */ -@OptIn(MiraiInternalAPI::class) @Throws(IOException::class) fun File.toExternalImage(): ExternalImage { val input = BitmapFactory.decodeFile(this.absolutePath) diff --git a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.android.kt b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.android.kt index 478960ce6..ce4c586b2 100644 --- a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.android.kt +++ b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.android.kt @@ -108,8 +108,6 @@ actual open class SystemDeviceInfo actual constructor() : DeviceInfo() { (context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager).connectionInfo.ssid.orEmpty() .toByteArray() }.getOrEmpty() - - @OptIn(MiraiInternalAPI::class) override val imsiMd5: ByteArray @SuppressLint("HardwareIds") get() = kotlin.runCatching { diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt index 260202d30..791a1b8b8 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt @@ -49,7 +49,6 @@ suspend inline fun B.alsoLogin(): B = also { login() } * @see BotFactory 构造 [Bot] 的工厂, [Bot] 唯一的构造方式. */ @Suppress("INAPPLICABLE_JVM_NAME") -@OptIn(MiraiInternalAPI::class, LowLevelAPI::class) abstract class Bot : CoroutineScope, LowLevelBotAPIAccessor, BotJavaFriendlyAPI(), ContactOrBot { companion object { /** @@ -269,7 +268,6 @@ abstract class Bot : CoroutineScope, LowLevelBotAPIAccessor, BotJavaFriendlyAPI( */ abstract fun close(cause: Throwable? = null) - @OptIn(LowLevelAPI::class, MiraiExperimentalAPI::class) final override fun toString(): String = "Bot($id)" /** diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt index a18ebb458..e470147d3 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt @@ -30,7 +30,6 @@ import kotlin.time.measureTime /* * 泛型 N 不需要向外(接口)暴露. */ -@OptIn(MiraiExperimentalAPI::class) @MiraiInternalAPI abstract class BotImpl constructor( context: Context, @@ -254,7 +253,7 @@ abstract class BotImpl constructor( } } - @OptIn(MiraiInternalAPI::class) + override fun close(cause: Throwable?) { if (!this.isActive) { // already cancelled diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt index 9ba6ef3f8..449cf32d7 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt @@ -23,7 +23,10 @@ import net.mamoe.mirai.message.MessageReceipt import net.mamoe.mirai.message.data.Image import net.mamoe.mirai.message.data.Message import net.mamoe.mirai.message.data.toMessage -import net.mamoe.mirai.utils.* +import net.mamoe.mirai.utils.ExternalImage +import net.mamoe.mirai.utils.MiraiExperimentalAPI +import net.mamoe.mirai.utils.OverFileSizeMaxException +import net.mamoe.mirai.utils.get import net.mamoe.mirai.utils.internal.runBlocking import kotlin.jvm.JvmName import kotlin.jvm.JvmStatic @@ -190,7 +193,6 @@ abstract class Group : Contact(), CoroutineScope { /** * @see quit */ - @OptIn(MiraiInternalAPI::class) @Suppress("FunctionName") @JvmName("quit") @JavaFriendlyAPI diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Member.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Member.kt index 54fe722c0..4c873a28c 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Member.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Member.kt @@ -18,7 +18,6 @@ import net.mamoe.mirai.getFriendOrNull import net.mamoe.mirai.message.MessageReceipt import net.mamoe.mirai.message.data.Message import net.mamoe.mirai.message.data.toMessage -import net.mamoe.mirai.utils.MiraiInternalAPI import net.mamoe.mirai.utils.WeakRefProperty import kotlin.jvm.JvmSynthetic import kotlin.time.Duration @@ -34,7 +33,7 @@ import kotlin.time.ExperimentalTime * [Member.isFriend] 判断此成员是否为好友 */ @Suppress("INAPPLICABLE_JVM_NAME") -@OptIn(MiraiInternalAPI::class, JavaFriendlyAPI::class) +@OptIn(JavaFriendlyAPI::class) abstract class Member : MemberJavaFriendlyAPI() { /** * 所在的群. diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Event.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Event.kt index 85ed66430..9f5c91f52 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Event.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Event.kt @@ -14,7 +14,6 @@ package net.mamoe.mirai.event import kotlinx.coroutines.CoroutineScope import net.mamoe.mirai.event.internal.broadcastInternal import net.mamoe.mirai.utils.MiraiExperimentalAPI -import net.mamoe.mirai.utils.MiraiInternalAPI import net.mamoe.mirai.utils.SinceMirai import kotlin.jvm.JvmSynthetic import kotlin.jvm.Volatile @@ -142,7 +141,6 @@ interface CancellableEvent : Event { /** * 广播一个事件的唯一途径. */ -@OptIn(MiraiInternalAPI::class) suspend fun E.broadcast(): E = apply { if (this is BroadcastControllable && !this.shouldBroadcast) { return@apply diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/deprecated.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/deprecated.kt index 1ffc3b69a..2a2b06ce3 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/deprecated.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/deprecated.kt @@ -26,7 +26,6 @@ import kotlinx.coroutines.channels.ReceiveChannel import net.mamoe.mirai.Bot import net.mamoe.mirai.event.events.BotEvent import net.mamoe.mirai.utils.PlannedRemoval -import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.coroutines.CoroutineContext @@ -64,7 +63,6 @@ abstract class AbstractCancellableEvent : AbstractEvent(), CancellableEvent level = DeprecationLevel.HIDDEN ) @kotlin.internal.LowPriorityInOverloadResolution -@OptIn(ExperimentalContracts::class) fun Bot.subscribeMessages( coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT, @@ -90,7 +88,6 @@ fun Bot.subscribeMessages( "Deprecated for better Coroutine life cycle management. Please filter bot instance on your own.", level = DeprecationLevel.HIDDEN ) -@OptIn(ExperimentalContracts::class) fun Bot.subscribeGroupMessages( coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT, @@ -116,7 +113,6 @@ fun Bot.subscribeGroupMessages( "Deprecated for better Coroutine life cycle management. Please filter bot instance on your own.", level = DeprecationLevel.HIDDEN ) -@OptIn(ExperimentalContracts::class) fun Bot.subscribeFriendMessages( coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT, @@ -143,7 +139,6 @@ fun Bot.subscribeFriendMessages( "Deprecated for better Coroutine life cycle management. Please filter bot instance on your own.", level = DeprecationLevel.HIDDEN ) -@OptIn(ExperimentalContracts::class) fun Bot.subscribeTempMessages( coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT, diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt index 8c7efc9f8..a34bb4736 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt @@ -187,7 +187,6 @@ sealed class MessageRecallEvent : BotEvent, AbstractEvent() { ) : MessageRecallEvent(), GroupOperableEvent, Packet } -@OptIn(MiraiExperimentalAPI::class) val MessageRecallEvent.GroupRecall.author: Member get() = if (authorId == bot.id) group.botAsMember else group[authorId] diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/types.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/types.kt index 613f67861..04029aa56 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/types.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/types.kt @@ -14,7 +14,6 @@ import net.mamoe.mirai.contact.Friend import net.mamoe.mirai.contact.Group import net.mamoe.mirai.contact.Member import net.mamoe.mirai.event.Event -import net.mamoe.mirai.utils.MiraiExperimentalAPI /** * 有关一个 [Bot] 的事件 @@ -76,7 +75,6 @@ val GroupOperableEvent.isByBot: Boolean * 当操作人为 [Member] 时获取这个 [Member], * 当操作人为 [Bot] 时获取 [Group.botAsMember] */ -@OptIn(MiraiExperimentalAPI::class) val GroupOperableEvent.operatorOrBot: Member get() = this.operator ?: this.group.botAsMember diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/internal/InternalEventListeners.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/internal/InternalEventListeners.kt index 202100812..ba724d2f9 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/internal/InternalEventListeners.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/internal/InternalEventListeners.kt @@ -15,7 +15,10 @@ import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import net.mamoe.mirai.event.* import net.mamoe.mirai.event.events.BotEvent -import net.mamoe.mirai.utils.* +import net.mamoe.mirai.utils.LockFreeLinkedList +import net.mamoe.mirai.utils.MiraiInternalAPI +import net.mamoe.mirai.utils.MiraiLogger +import net.mamoe.mirai.utils.PlannedRemoval import kotlin.coroutines.CoroutineContext import kotlin.coroutines.coroutineContext import kotlin.jvm.JvmField @@ -26,10 +29,8 @@ internal fun , E : Event> KClass.subscribeInternal(listen with(GlobalEventListeners[listener.priority]) { @Suppress("UNCHECKED_CAST") val node = ListenerNode(listener as Listener, this@subscribeInternal) - @OptIn(MiraiInternalAPI::class) addLast(node) listener.invokeOnCompletion { - @OptIn(MiraiInternalAPI::class) this.remove(node) } } @@ -128,13 +129,11 @@ internal expect class MiraiAtomicBoolean(initial: Boolean) { // inline: NO extra Continuation @Suppress("UNCHECKED_CAST") internal suspend inline fun Event.broadcastInternal() { - @OptIn(MiraiExperimentalAPI::class) if (EventDisabled) return callAndRemoveIfRequired(this@broadcastInternal as? AbstractEvent ?: error("Events must extends AbstractEvent")) } @Suppress("DuplicatedCode") -@OptIn(MiraiInternalAPI::class) internal suspend fun callAndRemoveIfRequired( event: E ) { diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt index fa1a4b778..dce4720f7 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt @@ -18,7 +18,6 @@ import net.mamoe.mirai.message.data.PlainText import net.mamoe.mirai.message.isContextIdenticalWith import net.mamoe.mirai.message.nextMessage import net.mamoe.mirai.utils.MiraiExperimentalAPI -import kotlin.experimental.ExperimentalTypeInference import kotlin.jvm.JvmName import kotlin.jvm.JvmSynthetic @@ -69,7 +68,6 @@ suspend inline fun T.whileSelectMessages( /** * [selectMessages] 的 [Unit] 返回值捷径 (由于 Kotlin 无法推断 [Unit] 类型) */ -@OptIn(ExperimentalTypeInference::class) @MiraiExperimentalAPI @JvmName("selectMessages1") suspend inline fun T.selectMessagesUnit( @@ -474,7 +472,6 @@ internal val ExceptionHandlerIgnoringCancellationException = CoroutineExceptionH @PublishedApi @BuilderInference -@OptIn(ExperimentalTypeInference::class) internal suspend inline fun T.selectMessagesImpl( timeoutMillis: Long = -1, isUnit: Boolean, diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt index 77c84916e..d72627e4d 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt @@ -22,7 +22,6 @@ import net.mamoe.mirai.message.FriendMessageEvent import net.mamoe.mirai.message.GroupMessageEvent import net.mamoe.mirai.message.MessageEvent import net.mamoe.mirai.message.TempMessageEvent -import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.coroutines.CoroutineContext @@ -39,7 +38,7 @@ typealias MessagePacketSubscribersBuilder = MessageSubscribersBuilder CoroutineScope.subscribeMessages( coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT, @@ -73,7 +72,6 @@ typealias GroupMessageSubscribersBuilder = MessageSubscribersBuilder CoroutineScope.subscribeGroupMessages( coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT, @@ -101,7 +99,6 @@ typealias FriendMessageSubscribersBuilder = MessageSubscribersBuilder CoroutineScope.subscribeFriendMessages( coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT, @@ -129,7 +126,6 @@ typealias TempMessageSubscribersBuilder = MessageSubscribersBuilder CoroutineScope.subscribeTempMessages( coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT, diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscriberDeprecated.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscriberDeprecated.kt index 6c4c075d3..ac35f69c8 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscriberDeprecated.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscriberDeprecated.kt @@ -22,7 +22,6 @@ import net.mamoe.mirai.event.Listener.EventPriority.NORMAL import net.mamoe.mirai.event.events.BotEvent import net.mamoe.mirai.event.internal.Handler import net.mamoe.mirai.event.internal.subscribeInternal -import net.mamoe.mirai.utils.MiraiInternalAPI import net.mamoe.mirai.utils.PlannedRemoval import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext @@ -41,7 +40,6 @@ import kotlin.reflect.KClass @Suppress("DeprecatedCallableAddReplaceWith", "DEPRECATION") @JvmSynthetic @JvmName("subscribeAlwaysForBot") -@OptIn(MiraiInternalAPI::class) @kotlin.internal.LowPriorityInOverloadResolution @Deprecated( "Deprecated for better Coroutine life cycle management. Please filter bot instance on your own.", @@ -80,7 +78,6 @@ fun Bot.subscribe( @JvmSynthetic @JvmName("subscribeAlwaysForBot1") @kotlin.internal.LowPriorityInOverloadResolution -@OptIn(MiraiInternalAPI::class) @Deprecated( "Deprecated for better Coroutine life cycle management. Please filter bot instance on your own.", level = DeprecationLevel.HIDDEN @@ -248,7 +245,6 @@ fun CoroutineScope.subscribeOnceDeprecated( @PlannedRemoval("1.2.0") @JvmSynthetic @JvmName("subscribeAlwaysForBot") -@OptIn(MiraiInternalAPI::class) @Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN) @Suppress("unused") inline fun Bot.subscribeDeprecated( @@ -285,7 +281,6 @@ fun Bot.subscribeDeprecated( @JvmName("subscribeAlwaysForBot1") @Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN) @Suppress("unused") -@OptIn(MiraiInternalAPI::class) inline fun Bot.subscribeAlwaysDeprecated( coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrency: Listener.ConcurrencyKind = CONCURRENT, diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt index b6e5c771c..160d525ab 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt @@ -18,7 +18,6 @@ import net.mamoe.mirai.contact.* import net.mamoe.mirai.message.data.* import net.mamoe.mirai.recallIn import net.mamoe.mirai.utils.MiraiExperimentalAPI -import net.mamoe.mirai.utils.MiraiInternalAPI import net.mamoe.mirai.utils.internal.runBlocking import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext @@ -42,7 +41,6 @@ import kotlin.jvm.JvmSynthetic * @see MessageReceipt.sourceId 源 id * @see MessageReceipt.sourceTime 源时间 */ -@OptIn(MiraiInternalAPI::class) open class MessageReceipt( /** * 指代发送出去的消息. diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/CombinedMessage.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/CombinedMessage.kt index 70d9e925e..eec363ed2 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/CombinedMessage.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/CombinedMessage.kt @@ -12,7 +12,6 @@ package net.mamoe.mirai.message.data -import net.mamoe.mirai.utils.MiraiExperimentalAPI import net.mamoe.mirai.utils.PlannedRemoval import kotlin.jvm.JvmField import kotlin.jvm.JvmMultifileClass @@ -53,7 +52,7 @@ internal constructor( private var toStringCache: String? = null - @OptIn(MiraiExperimentalAPI::class) + override fun toString(): String = toStringCache ?: (left.toString() + tail.toString()).also { toStringCache = it } private var contentToStringCache: String? = null @@ -70,7 +69,7 @@ internal constructor( /* @JvmSynthetic // 不要把它用作 local function, 会编译错误 -@OptIn(MiraiExperimentalAPI::class, MiraiInternalAPI::class) + private suspend fun SequenceScope.yieldCombinedOrElementsFlatten(message: Message) { when (message) { is CombinedMessage -> { diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/CustomMessage.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/CustomMessage.kt index 7d11bc193..5d91feb3f 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/CustomMessage.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/CustomMessage.kt @@ -114,7 +114,6 @@ sealed class CustomMessage : SingleMessage { override val typeName: String get() = "CustomMessage" private val factories: LockFreeLinkedList> = LockFreeLinkedList() - @OptIn(MiraiInternalAPI::class) internal fun register(factory: Factory) { factories.removeIf { it::class == factory::class } val exist = factories.asSequence().firstOrNull { it.typeName == factory.typeName } @@ -135,7 +134,6 @@ sealed class CustomMessage : SingleMessage { class CustomMessageFullDataDeserializeUserException(val body: ByteArray, cause: Throwable?) : RuntimeException(cause) - @OptIn(MiraiInternalAPI::class) internal fun deserialize(fullData: ByteReadPacket): CustomMessage? { val msg = kotlin.runCatching { val length = fullData.readInt() @@ -194,7 +192,6 @@ abstract class CustomMessageMetadata : CustomMessage(), MessageMetadata { @Suppress("NOTHING_TO_INLINE") -@OptIn(MiraiExperimentalAPI::class) internal inline fun T.customToStringImpl(factory: CustomMessage.Factory<*>): ByteArray { @Suppress("UNCHECKED_CAST") return (factory as CustomMessage.Factory).serialize(this) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/ForwardMessage.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/ForwardMessage.kt index 8390cf0d6..634fdb0c9 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/ForwardMessage.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/ForwardMessage.kt @@ -542,8 +542,6 @@ class ForwardMessageBuilder private constructor( /** 构造 [ForwardMessage] */ fun build(): ForwardMessage = ForwardMessage(container.toList(), this.displayStrategy) - - @OptIn(MiraiExperimentalAPI::class) internal fun Bot.smartName(): String = when (val c = this@ForwardMessageBuilder.context) { is Group -> c.botAsMember.nameCardOrNick else -> nick diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/HummerMessage.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/HummerMessage.kt index a79a2b17a..387b5732c 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/HummerMessage.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/HummerMessage.kt @@ -15,8 +15,6 @@ package net.mamoe.mirai.message.data import net.mamoe.mirai.message.data.PokeMessage.Types import net.mamoe.mirai.message.data.VipFace.Companion -import net.mamoe.mirai.utils.MiraiExperimentalAPI -import net.mamoe.mirai.utils.MiraiInternalAPI import kotlin.jvm.* /** @@ -42,7 +40,6 @@ sealed class HummerMessage : MessageContent { * * @see Types 使用伴生对象中的常量 */ -@OptIn(MiraiInternalAPI::class) data class PokeMessage internal constructor( /** * 仅 mirai, 显示的名称 @@ -133,7 +130,7 @@ data class PokeMessage internal constructor( ) } - @OptIn(MiraiExperimentalAPI::class) + private val stringValue = "[mirai:poke:$type,$id]" override fun toString(): String = stringValue @@ -155,7 +152,6 @@ data class PokeMessage internal constructor( * * @see Types 使用伴生对象中的常量 */ -@OptIn(MiraiInternalAPI::class) data class VipFace internal constructor( /** * 使用 [Companion] 中常量. @@ -217,7 +213,7 @@ data class VipFace internal constructor( private infix fun Int.to(name: String): Kind = Kind(this, name) } - @OptIn(MiraiExperimentalAPI::class) + private val stringValue = "[mirai:vipface:$kind,$count]" override fun toString(): String = stringValue @@ -245,7 +241,7 @@ sealed class FlashImage : MessageContent, HummerMessage() { @JvmStatic @JvmName("from") operator fun invoke(image: Image): FlashImage { - @OptIn(MiraiInternalAPI::class) + return when (image) { is GroupImage -> GroupFlashImage(image) is FriendImage -> FriendFlashImage(image) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt index 98cb178a6..7e05bce72 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt @@ -100,7 +100,6 @@ expect interface Image : Message, MessageContent { @PlannedRemoval("1.2.0") // make internal @Suppress("DEPRECATION_ERROR") // CustomFace -@OptIn(MiraiInternalAPI::class) sealed class GroupImage : AbstractImage() { companion object Key : Message.Key { override val typeName: String get() = "GroupImage" @@ -124,7 +123,6 @@ val Image.md5: ByteArray */ // NotOnlineImage @PlannedRemoval("1.2.0") // make internal @Suppress("DEPRECATION_ERROR") -@OptIn(MiraiInternalAPI::class) sealed class FriendImage : AbstractImage() { companion object Key : Message.Key { override val typeName: String get() = "FriendImage" @@ -190,7 +188,6 @@ fun Image(imageId: String): OfflineImage = when { @JvmSynthetic suspend fun Image.queryUrl(): String { @Suppress("DEPRECATION") - @OptIn(MiraiInternalAPI::class) return when (this) { is OnlineImage -> this.originUrl else -> BotImpl.instances.peekFirst().get()?.queryImageUrl(this) @@ -248,7 +245,6 @@ interface OfflineImage : Image { ) @JvmSynthetic suspend fun OfflineImage.queryUrl(): String { - @OptIn(MiraiInternalAPI::class) return BotImpl.instances.peekFirst().get()?.queryImageUrl(this) ?: error("No Bot available to query image url") } diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt index 88ec92411..34e6d7770 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt @@ -17,9 +17,7 @@ import net.mamoe.mirai.contact.Contact import net.mamoe.mirai.message.MessageEvent import net.mamoe.mirai.message.MessageReceipt import net.mamoe.mirai.message.data.Message.Key -import net.mamoe.mirai.utils.MiraiInternalAPI import net.mamoe.mirai.utils.PlannedRemoval -import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName @@ -78,7 +76,6 @@ import kotlin.jvm.JvmSynthetic * * @see Contact.sendMessage 发送消息 */ -@OptIn(MiraiInternalAPI::class) interface Message { // must be interface. Don't consider any changes. /** * 类型 Key. 由伴生对象实现, 表示一个 [Message] 对象的类型. @@ -205,7 +202,6 @@ inline val Message.content: String * - [PlainText] 长度为 0 * - [MessageChain] 所有元素都满足 [isContentEmpty] */ -@OptIn(ExperimentalContracts::class) fun Message.isContentEmpty(): Boolean { contract { returns(false) implies (this@isContentEmpty is MessageContent) @@ -218,7 +214,6 @@ fun Message.isContentEmpty(): Boolean { } } -@OptIn(ExperimentalContracts::class) inline fun Message.isContentNotEmpty(): Boolean { contract { returns(true) implies (this@isContentNotEmpty is MessageContent) @@ -226,7 +221,6 @@ inline fun Message.isContentNotEmpty(): Boolean { return !this.isContentEmpty() } -@OptIn(ExperimentalContracts::class) inline fun Message.isPlain(): Boolean { contract { returns(true) implies (this@isPlain is PlainText) @@ -235,7 +229,6 @@ inline fun Message.isPlain(): Boolean { return this is PlainText } -@OptIn(ExperimentalContracts::class) inline fun Message.isNotPlain(): Boolean { contract { returns(false) implies (this@isNotPlain is PlainText) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt index d8c849932..73cacb170 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt @@ -15,7 +15,6 @@ package net.mamoe.mirai.message.data import net.mamoe.mirai.JavaFriendlyAPI -import net.mamoe.mirai.utils.MiraiExperimentalAPI import net.mamoe.mirai.utils.MiraiInternalAPI import net.mamoe.mirai.utils.PlannedRemoval import kotlin.js.JsName @@ -173,7 +172,6 @@ inline fun MessageChain.anyIsInstance(): Boolean = this.an /** * 获取第一个 [M] 类型的 [Message] 实例 */ -@OptIn(MiraiExperimentalAPI::class) @JvmSynthetic @Suppress("UNCHECKED_CAST") fun MessageChain.firstOrNull(key: Message.Key): M? = firstOrNullImpl(key) @@ -278,7 +276,6 @@ inline fun messageChainOf(vararg messages: Message): MessageChain = messages.asM @JvmName("newChain") @JsName("newChain") @Suppress("UNCHECKED_CAST") -@OptIn(MiraiInternalAPI::class) fun Message.asMessageChain(): MessageChain = when (this) { is MessageChain -> this is CombinedMessage -> (this as Iterable).asMessageChain() @@ -409,7 +406,6 @@ inline fun Array.flatten(): Sequence = this.as * - 其他: 返回 `sequenceOf(this)` */ fun Message.flatten(): Sequence { - @OptIn(MiraiInternalAPI::class) return when (this) { is MessageChain -> this.asSequence() is CombinedMessage -> this.asSequence() // already constrained single. diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChainBuilder.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChainBuilder.kt index 494d81dd5..1a49bfa06 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChainBuilder.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChainBuilder.kt @@ -13,7 +13,6 @@ package net.mamoe.mirai.message.data -import net.mamoe.mirai.utils.MiraiExperimentalAPI import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName import kotlin.jvm.JvmSynthetic @@ -48,7 +47,6 @@ inline fun buildMessageChain(initialSize: Int, block: MessageChainBuilder.() -> * @see buildMessageChain 推荐使用 * @see asMessageChain 完成构建 */ -@OptIn(MiraiExperimentalAPI::class) open class MessageChainBuilder private constructor( private val container: MutableList ) : MutableList by container, Appendable { diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt index 7e58f2c60..a6a310bea 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt @@ -20,8 +20,6 @@ import net.mamoe.mirai.message.MessageEvent import net.mamoe.mirai.message.MessageReceipt import net.mamoe.mirai.recallIn import net.mamoe.mirai.utils.LazyProperty -import net.mamoe.mirai.utils.MiraiExperimentalAPI -import net.mamoe.mirai.utils.MiraiInternalAPI import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext import kotlin.jvm.JvmMultifileClass @@ -58,7 +56,6 @@ import kotlin.jvm.JvmSynthetic * @see OnlineMessageSource 在线消息的 [MessageSource] * @see OfflineMessageSource 离线消息的 [MessageSource] */ -@OptIn(MiraiExperimentalAPI::class) sealed class MessageSource : Message, MessageMetadata, ConstrainSingle { companion object Key : Message.Key { override val typeName: String get() = "MessageSource" @@ -156,7 +153,6 @@ sealed class MessageSource : Message, MessageMetadata, ConstrainSingle { override val typeName: String get() = "OnlineMessageSource" @@ -336,7 +332,7 @@ inline fun MessageSource.isAboutFriend(): Boolean { * @see QuoteReply */ fun MessageSource.quote(): QuoteReply { - @OptIn(MiraiInternalAPI::class) + return QuoteReply(this) } @@ -345,7 +341,7 @@ fun MessageSource.quote(): QuoteReply { * @see QuoteReply */ fun MessageChain.quote(): QuoteReply { - @OptIn(MiraiInternalAPI::class) + return QuoteReply(this.source) } diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt index fd424fd42..a3acc16bf 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt @@ -15,7 +15,6 @@ package net.mamoe.mirai.message.data import kotlinx.coroutines.Job import net.mamoe.mirai.Bot -import net.mamoe.mirai.utils.MiraiExperimentalAPI import net.mamoe.mirai.utils.PlannedRemoval import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext @@ -45,7 +44,6 @@ import kotlin.jvm.JvmSynthetic * * @see MessageSource 获取有关消息源的更多信息 */ -@OptIn(MiraiExperimentalAPI::class) class QuoteReply(val source: MessageSource) : Message, MessageMetadata, ConstrainSingle { companion object Key : Message.Key { override val typeName: String diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/RichMessage.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/RichMessage.kt index 387518695..0c7299414 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/RichMessage.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/RichMessage.kt @@ -227,5 +227,5 @@ internal class LongMessage internal constructor(content: String, val resId: Stri } } -@OptIn(MiraiExperimentalAPI::class) + internal class ForwardMessageInternal(content: String) : ServiceMessage(35, content) \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/impl.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/impl.kt index 14778d339..38f73e390 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/impl.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/impl.kt @@ -14,7 +14,6 @@ package net.mamoe.mirai.message.data import net.mamoe.mirai.utils.MiraiExperimentalAPI -import net.mamoe.mirai.utils.MiraiInternalAPI import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName import kotlin.jvm.JvmSynthetic @@ -23,9 +22,6 @@ import kotlin.native.concurrent.SharedImmutable ///////////////////////// //// IMPLEMENTATIONS //// ///////////////////////// - - -@OptIn(MiraiInternalAPI::class) private fun Message.hasDuplicationOfConstrain(key: Message.Key<*>): Boolean { return when (this) { is SingleMessage -> (this as? ConstrainSingle<*>)?.key == key @@ -129,7 +125,6 @@ internal fun Message.followedByImpl(tail: Message): MessageChain { } -@OptIn(MiraiExperimentalAPI::class) @JvmSynthetic internal fun Sequence.constrainSingleMessages(): List { val iterator = this.iterator() @@ -169,7 +164,7 @@ internal inline fun constrainSingleMessagesImpl(iterator: () -> SingleMessage?): } @JvmSynthetic -@OptIn(MiraiExperimentalAPI::class) + internal fun Iterable.constrainSingleMessages(): List { val iterator = this.iterator() return constrainSingleMessagesImpl supplier@{ @@ -189,7 +184,6 @@ internal inline fun List.indexOfFirst(offset: Int, predicate: (T) -> Bool } -@OptIn(MiraiExperimentalAPI::class) @JvmSynthetic @Suppress("UNCHECKED_CAST", "DEPRECATION_ERROR", "DEPRECATION") internal fun MessageChain.firstOrNullImpl(key: Message.Key): M? = when (key) { diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt index 8a695f5ca..9f35e5ed6 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt @@ -124,7 +124,7 @@ abstract class BotNetworkHandler : CoroutineScope { } @MiraiInternalAPI -@OptIn(MiraiInternalAPI::class) + suspend fun BotNetworkHandler.closeAndJoin(cause: Throwable? = null) { this.close(cause) this.supervisor.join() diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BotConfiguration.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BotConfiguration.kt index af2f1fc6a..bc964c2d3 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BotConfiguration.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BotConfiguration.kt @@ -29,7 +29,6 @@ open class BotConfiguration { var botLoggerSupplier: ((Bot) -> MiraiLogger) = { DefaultLogger("Bot(${it.id})") } /** 网络层日志构造器 */ - @OptIn(MiraiInternalAPI::class) var networkLoggerSupplier: ((BotNetworkHandler) -> MiraiLogger) = { DefaultLogger("Network(${it.bot.id})") } /** 设备信息覆盖. 默认使用随机的设备信息. */ @@ -99,7 +98,6 @@ open class BotConfiguration { /** * 不显示网络日志 */ - @OptIn(MiraiInternalAPI::class) @ConfigurationDsl fun noNetworkLog() { networkLoggerSupplier = { _: BotNetworkHandler -> SilentLogger } @@ -137,7 +135,6 @@ open class BotConfiguration { @SinceMirai("1.0.0") fun copy(): BotConfiguration { - @OptIn(MiraiExperimentalAPI::class) return BotConfiguration().also { new -> new.botLoggerSupplier = botLoggerSupplier new.networkLoggerSupplier = networkLoggerSupplier diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/DeviceInfo.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/DeviceInfo.kt index 4ace4af4a..690c05ab0 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/DeviceInfo.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/DeviceInfo.kt @@ -92,7 +92,6 @@ abstract class DeviceInfo { } } -@OptIn(MiraiInternalAPI::class) @Serializable class DeviceInfoData( override val display: ByteArray, diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/internal/DeferredReusableInput.common.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/internal/DeferredReusableInput.common.kt index bd0016dad..67178c891 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/internal/DeferredReusableInput.common.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/internal/DeferredReusableInput.common.kt @@ -1,11 +1,10 @@ package net.mamoe.mirai.utils.internal import net.mamoe.mirai.utils.FileCacheStrategy -import net.mamoe.mirai.utils.MiraiExperimentalAPI internal expect class DeferredReusableInput(input: Any, extraArg: Any?) : ReusableInput { val initialized: Boolean - @OptIn(MiraiExperimentalAPI::class) + suspend fun init(strategy: FileCacheStrategy) } \ No newline at end of file diff --git a/mirai-core/src/commonTest/kotlin/net/mamoe/mirai/message.data/CombinedMessageTest.kt b/mirai-core/src/commonTest/kotlin/net/mamoe/mirai/message.data/CombinedMessageTest.kt index 92ffc6ae3..2c61c9479 100644 --- a/mirai-core/src/commonTest/kotlin/net/mamoe/mirai/message.data/CombinedMessageTest.kt +++ b/mirai-core/src/commonTest/kotlin/net/mamoe/mirai/message.data/CombinedMessageTest.kt @@ -1,10 +1,9 @@ package net.mamoe.mirai.message.data -import net.mamoe.mirai.utils.MiraiInternalAPI import kotlin.test.Test import kotlin.test.assertEquals -@OptIn(MiraiInternalAPI::class) + internal class CombinedMessageTest { diff --git a/mirai-core/src/commonTest/kotlin/net/mamoe/mirai/message.data/ConstrainSingleTest.kt b/mirai-core/src/commonTest/kotlin/net/mamoe/mirai/message.data/ConstrainSingleTest.kt index 295082f77..9626b0750 100644 --- a/mirai-core/src/commonTest/kotlin/net/mamoe/mirai/message.data/ConstrainSingleTest.kt +++ b/mirai-core/src/commonTest/kotlin/net/mamoe/mirai/message.data/ConstrainSingleTest.kt @@ -9,15 +9,12 @@ package net.mamoe.mirai.message.data -import net.mamoe.mirai.utils.MiraiExperimentalAPI -import net.mamoe.mirai.utils.MiraiInternalAPI import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertSame import kotlin.test.assertTrue -@OptIn(MiraiExperimentalAPI::class) internal class TestConstrainSingleMessage : ConstrainSingle, Any() { companion object Key : Message.Key { override val typeName: String @@ -30,10 +27,10 @@ internal class TestConstrainSingleMessage : ConstrainSingle I.withOut(output: O, block: I.(output: O) -> R): R { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/LoginSolver.jvm.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/LoginSolver.jvm.kt index 0f8027cf9..0acfdf267 100644 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/LoginSolver.jvm.kt +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/LoginSolver.jvm.kt @@ -145,7 +145,7 @@ actual abstract class LoginSolver { actual companion object { actual val Default: LoginSolver = - @OptIn(MiraiExperimentalAPI::class) + DefaultLoginSolver({ readLine() ?: throw NoStandardInputForCaptchaException(null) }) } } diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt index 7ab6259d7..27af9e5f1 100644 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt @@ -36,7 +36,6 @@ fun File.loadAsDeviceInfo(context: Context = ContextImpl()): DeviceInfo { private val JSON = Json(JsonConfiguration.Stable) @Serializable -@OptIn(ExperimentalUnsignedTypes::class, MiraiInternalAPI::class) actual open class SystemDeviceInfo actual constructor() : DeviceInfo() { actual constructor(context: Context) : this() { this.context = context diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/internal/DeferredReusableInput.jvm.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/internal/DeferredReusableInput.jvm.kt index ab41a7cea..8373e3543 100644 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/internal/DeferredReusableInput.jvm.kt +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/internal/DeferredReusableInput.jvm.kt @@ -15,7 +15,7 @@ internal actual class DeferredReusableInput actual constructor( ) : ReusableInput { - @OptIn(MiraiExperimentalAPI::class) + actual suspend fun init(strategy: FileCacheStrategy) = withContext(Dispatchers.IO) { if (delegate != null) { return@withContext diff --git a/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/event/EventTests.kt b/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/event/EventTests.kt index 54d7cebbb..9fc2ca4b1 100644 --- a/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/event/EventTests.kt +++ b/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/event/EventTests.kt @@ -219,7 +219,6 @@ class EventTests { */ fun resetEventListeners() { for (p in Listener.EventPriority.values()) { - @OptIn(MiraiInternalAPI::class) GlobalEventListeners[p].clear() } } diff --git a/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/event/JvmMethodEventsTest.kt b/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/event/JvmMethodEventsTest.kt index 6a15c11e8..8f27c503c 100644 --- a/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/event/JvmMethodEventsTest.kt +++ b/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/event/JvmMethodEventsTest.kt @@ -7,7 +7,7 @@ * https://github.com/mamoe/mirai/blob/master/LICENSE */ -@file:Suppress("RedundantSuspendModifier", "unused") +@file:Suppress("RedundantSuspendModifier", "unused", "UNUSED_PARAMETER") package net.mamoe.mirai.event @@ -28,32 +28,38 @@ internal class JvmMethodEventsTest { fun getCalled() = called.get() + @Suppress("unused") @EventHandler suspend fun TestEvent.`suspend receiver param Unit`(event: TestEvent) { called.getAndIncrement() } + @Suppress("unused") @EventHandler suspend fun TestEvent.`suspend receiver Unit`() { called.getAndIncrement() } + @Suppress("unused") @EventHandler suspend fun `suspend param Unit`(event: TestEvent) { called.getAndIncrement() } @EventHandler + @Suppress("unused") fun TestEvent.`receiver param Unit`(event: TestEvent) { called.getAndIncrement() } @EventHandler + @Suppress("unused") suspend fun TestEvent.`suspend receiver param LS`(event: TestEvent): ListeningStatus { called.getAndIncrement() return ListeningStatus.STOPPED } + @Suppress("unused") @EventHandler suspend fun TestEvent.`suspend receiver LS`(): ListeningStatus { called.getAndIncrement() @@ -61,12 +67,14 @@ internal class JvmMethodEventsTest { } @EventHandler + @Suppress("unused") suspend fun `suspend param LS`(event: TestEvent): ListeningStatus { called.getAndIncrement() return ListeningStatus.STOPPED } @EventHandler + @Suppress("unused") fun TestEvent.`receiver param LS`(event: TestEvent): ListeningStatus { called.getAndIncrement() return ListeningStatus.STOPPED @@ -91,13 +99,15 @@ internal class JvmMethodEventsTest { fun getCalled() = called.get() - @EventHandler(Listener.EventPriority.HIGHEST) + @Suppress("unused") + @EventHandler(EventPriority.HIGHEST) private suspend fun TestEvent.`suspend receiver param Unit`(event: TestEvent) { intercept() called.getAndIncrement() } @EventHandler(EventPriority.MONITOR) + @Suppress("unused") private fun TestEvent.`receiver param LS`(event: TestEvent): ListeningStatus { called.getAndIncrement() return ListeningStatus.STOPPED diff --git a/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/utils/LockFreeLinkedListTest.kt b/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/utils/LockFreeLinkedListTest.kt index 285a77316..c385d64ca 100644 --- a/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/utils/LockFreeLinkedListTest.kt +++ b/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/utils/LockFreeLinkedListTest.kt @@ -20,7 +20,6 @@ import kotlin.test.assertFalse import kotlin.test.assertTrue @Suppress("UnusedEquals") -@OptIn(MiraiInternalAPI::class) @MiraiExperimentalAPI internal class LockFreeLinkedListTest { @Test @@ -136,7 +135,6 @@ internal class LockFreeLinkedListTest { list.size shouldBeEqualTo 0 } - @OptIn(ExperimentalUnsignedTypes::class) @Test fun withInlineClassElements() { val list = LockFreeLinkedList() @@ -264,7 +262,7 @@ internal class LockFreeLinkedListTest { */ } -@OptIn(ExperimentalCoroutinesApi::class, MiraiInternalAPI::class) +@OptIn(ExperimentalCoroutinesApi::class) @MiraiExperimentalAPI internal suspend inline fun > E.concurrentDo( numberOfCoroutines: Int,