Quellcode durchsuchen

Deprecate `EmptyMessageChain` in favor of `emptyMessageChain()`

Him188 vor 3 Jahren
Ursprung
Commit
b40b681f81

+ 1 - 1
mirai-console/backend/mirai-console/src/command/CommandManager.kt

@@ -146,7 +146,7 @@ public interface CommandManager {
     public suspend fun executeCommand(
     public suspend fun executeCommand(
         sender: CommandSender,
         sender: CommandSender,
         command: Command,
         command: Command,
-        arguments: Message = EmptyMessageChain,
+        arguments: Message = emptyMessageChain(),
         checkPermission: Boolean = true,
         checkPermission: Boolean = true,
     ): CommandExecuteResult {
     ): CommandExecuteResult {
         // TODO: 2020/10/18  net.mamoe.mirai.console.command.CommandManager.execute
         // TODO: 2020/10/18  net.mamoe.mirai.console.command.CommandManager.execute

+ 3 - 3
mirai-console/backend/mirai-console/src/command/resolve/BuiltInCommandCallResolver.kt

@@ -19,7 +19,7 @@ import net.mamoe.mirai.console.extensions.CommandCallResolverProvider
 import net.mamoe.mirai.console.internal.data.classifierAsKClass
 import net.mamoe.mirai.console.internal.data.classifierAsKClass
 import net.mamoe.mirai.console.util.ConsoleExperimentalApi
 import net.mamoe.mirai.console.util.ConsoleExperimentalApi
 import net.mamoe.mirai.console.util.safeCast
 import net.mamoe.mirai.console.util.safeCast
-import net.mamoe.mirai.message.data.EmptyMessageChain
+import net.mamoe.mirai.message.data.emptyMessageChain
 import net.mamoe.mirai.message.data.toMessageChain
 import net.mamoe.mirai.message.data.toMessageChain
 
 
 /**
 /**
@@ -149,7 +149,7 @@ public object BuiltInCommandCallResolver : CommandCallResolver {
                 // add default empty vararg argument
                 // add default empty vararg argument
                 val remainingVararg = remainingParameters.find { it.isVararg }
                 val remainingVararg = remainingParameters.find { it.isVararg }
                 if (remainingVararg != null) {
                 if (remainingVararg != null) {
-                    zipped.add(remainingVararg to DefaultCommandValueArgument(EmptyMessageChain))
+                    zipped.add(remainingVararg to DefaultCommandValueArgument(emptyMessageChain()))
                     remainingParameters.remove(remainingVararg)
                     remainingParameters.remove(remainingVararg)
                 }
                 }
             }
             }
@@ -195,7 +195,7 @@ public object BuiltInCommandCallResolver : CommandCallResolver {
             .also { list ->
             .also { list ->
 
 
                 val candidates = list
                 val candidates = list
-                    .asSequence().filterIsInstance<ResolveData>()
+                    .asSequence()
                     .flatMap { phase ->
                     .flatMap { phase ->
                         phase.argumentAcceptances.filter { it.acceptance is ArgumentAcceptance.Direct }
                         phase.argumentAcceptances.filter { it.acceptance is ArgumentAcceptance.Direct }
                             .map { phase to it }
                             .map { phase to it }

+ 1 - 0
mirai-core-api/compatibility-validation/android/api/android.api

@@ -4954,6 +4954,7 @@ public final class net/mamoe/mirai/message/data/MessageUtils {
 	public static final fun contentsList (Lnet/mamoe/mirai/message/data/MessageChain;)Ljava/util/List;
 	public static final fun contentsList (Lnet/mamoe/mirai/message/data/MessageChain;)Ljava/util/List;
 	public static final synthetic fun contentsSequence (Lnet/mamoe/mirai/message/data/MessageChain;)Lkotlin/sequences/Sequence;
 	public static final synthetic fun contentsSequence (Lnet/mamoe/mirai/message/data/MessageChain;)Lkotlin/sequences/Sequence;
 	public static final fun copySource (Lnet/mamoe/mirai/message/data/MessageSource;Lkotlin/jvm/functions/Function1;)Lnet/mamoe/mirai/message/data/OfflineMessageSource;
 	public static final fun copySource (Lnet/mamoe/mirai/message/data/MessageSource;Lkotlin/jvm/functions/Function1;)Lnet/mamoe/mirai/message/data/OfflineMessageSource;
+	public static final fun emptyMessageChain ()Lnet/mamoe/mirai/message/data/MessageChain;
 	public static final synthetic fun getBot (Lnet/mamoe/mirai/message/data/MessageChain;)Lnet/mamoe/mirai/Bot;
 	public static final synthetic fun getBot (Lnet/mamoe/mirai/message/data/MessageChain;)Lnet/mamoe/mirai/Bot;
 	public static final fun getBot (Lnet/mamoe/mirai/message/data/MessageSource;)Lnet/mamoe/mirai/Bot;
 	public static final fun getBot (Lnet/mamoe/mirai/message/data/MessageSource;)Lnet/mamoe/mirai/Bot;
 	public static final fun getBotOrNull (Lnet/mamoe/mirai/message/data/MessageSource;)Lnet/mamoe/mirai/Bot;
 	public static final fun getBotOrNull (Lnet/mamoe/mirai/message/data/MessageSource;)Lnet/mamoe/mirai/Bot;

+ 1 - 0
mirai-core-api/compatibility-validation/jvm/api/jvm.api

@@ -4954,6 +4954,7 @@ public final class net/mamoe/mirai/message/data/MessageUtils {
 	public static final fun contentsList (Lnet/mamoe/mirai/message/data/MessageChain;)Ljava/util/List;
 	public static final fun contentsList (Lnet/mamoe/mirai/message/data/MessageChain;)Ljava/util/List;
 	public static final synthetic fun contentsSequence (Lnet/mamoe/mirai/message/data/MessageChain;)Lkotlin/sequences/Sequence;
 	public static final synthetic fun contentsSequence (Lnet/mamoe/mirai/message/data/MessageChain;)Lkotlin/sequences/Sequence;
 	public static final fun copySource (Lnet/mamoe/mirai/message/data/MessageSource;Lkotlin/jvm/functions/Function1;)Lnet/mamoe/mirai/message/data/OfflineMessageSource;
 	public static final fun copySource (Lnet/mamoe/mirai/message/data/MessageSource;Lkotlin/jvm/functions/Function1;)Lnet/mamoe/mirai/message/data/OfflineMessageSource;
+	public static final fun emptyMessageChain ()Lnet/mamoe/mirai/message/data/MessageChain;
 	public static final synthetic fun getBot (Lnet/mamoe/mirai/message/data/MessageChain;)Lnet/mamoe/mirai/Bot;
 	public static final synthetic fun getBot (Lnet/mamoe/mirai/message/data/MessageChain;)Lnet/mamoe/mirai/Bot;
 	public static final fun getBot (Lnet/mamoe/mirai/message/data/MessageSource;)Lnet/mamoe/mirai/Bot;
 	public static final fun getBot (Lnet/mamoe/mirai/message/data/MessageSource;)Lnet/mamoe/mirai/Bot;
 	public static final fun getBotOrNull (Lnet/mamoe/mirai/message/data/MessageSource;)Lnet/mamoe/mirai/Bot;
 	public static final fun getBotOrNull (Lnet/mamoe/mirai/message/data/MessageSource;)Lnet/mamoe/mirai/Bot;

+ 15 - 1
mirai-core-api/src/commonMain/kotlin/message/data/MessageChain.kt

@@ -347,9 +347,23 @@ public sealed interface MessageChain :
 }
 }
 
 
 /**
 /**
- * 不含任何元素的 [MessageChain].
+ * 返回一个不含任何元素的 [MessageChain].
+ *
+ * @since 2.11
+ */
+// Java: MessageUtils.emptyMessageChain()
+@Suppress("DEPRECATION")
+public fun emptyMessageChain(): MessageChain = EmptyMessageChain
+
+/**
+ * 不含任何元素的 [MessageChain]. 已弃用, 请使用 [emptyMessageChain]
  */
  */
 //@Serializable(MessageChain.Serializer::class)
 //@Serializable(MessageChain.Serializer::class)
+@Deprecated(
+    "Please use emptyMessageChain()",
+    replaceWith = ReplaceWith("emptyMessageChain()", "net.mamoe.mirai.message.data.emptyMessageChain")
+)
+@DeprecatedSinceMirai(warningSince = "2.11")
 public object EmptyMessageChain : MessageChain, List<SingleMessage> by emptyList() {
 public object EmptyMessageChain : MessageChain, List<SingleMessage> by emptyList() {
     override val size: Int get() = 0
     override val size: Int get() = 0
 
 

+ 5 - 5
mirai-core-api/src/commonMain/kotlin/message/data/impl.kt

@@ -1,10 +1,10 @@
 /*
 /*
- * Copyright 2019-2021 Mamoe Technologies and contributors.
+ * Copyright 2019-2022 Mamoe Technologies and contributors.
  *
  *
- *  此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
- *  Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
+ * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  *
  *
- *  https://github.com/mamoe/mirai/blob/master/LICENSE
+ * https://github.com/mamoe/mirai/blob/dev/LICENSE
  */
  */
 
 
 @file:Suppress("EXPERIMENTAL_API_USAGE")
 @file:Suppress("EXPERIMENTAL_API_USAGE")
@@ -163,7 +163,7 @@ internal fun <M : SingleMessage> MessageChain.getImpl(key: MessageKey<M>): M? {
  * @return [EmptyMessageChain] if [delegate] is empty, otherwise [MessageChainImpl]
  * @return [EmptyMessageChain] if [delegate] is empty, otherwise [MessageChainImpl]
  */
  */
 internal fun createMessageChainImplOptimized(delegate: List<SingleMessage>): MessageChain {
 internal fun createMessageChainImplOptimized(delegate: List<SingleMessage>): MessageChain {
-    return if (delegate.isEmpty()) EmptyMessageChain
+    return if (delegate.isEmpty()) emptyMessageChain()
     else MessageChainImpl(delegate)
     else MessageChainImpl(delegate)
 }
 }
 
 

+ 5 - 5
mirai-core-api/src/commonTest/kotlin/message.data/MessageUtilsTest.kt

@@ -1,10 +1,10 @@
 /*
 /*
- * Copyright 2019-2021 Mamoe Technologies and contributors.
+ * Copyright 2019-2022 Mamoe Technologies and contributors.
  *
  *
- *  此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
- *  Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
+ * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  *
  *
- *  https://github.com/mamoe/mirai/blob/master/LICENSE
+ * https://github.com/mamoe/mirai/blob/dev/LICENSE
  */
  */
 package  net.mamoe.mirai.message.data
 package  net.mamoe.mirai.message.data
 
 
@@ -18,7 +18,7 @@ import kotlin.test.assertTrue
 internal class MessageUtilsTest {
 internal class MessageUtilsTest {
     @Test
     @Test
     fun testIsContentEmpty() {
     fun testIsContentEmpty() {
-        assertTrue { EmptyMessageChain.isContentEmpty() }
+        assertTrue { emptyMessageChain().isContentEmpty() }
         assertTrue { buildMessageChain { }.isContentEmpty() }
         assertTrue { buildMessageChain { }.isContentEmpty() }
         assertTrue { PlainText("").isContentEmpty() }
         assertTrue { PlainText("").isContentEmpty() }
         assertTrue { (PlainText("") + PlainText("")).isContentEmpty() }
         assertTrue { (PlainText("") + PlainText("")).isContentEmpty() }