mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-21 10:14:42 +08:00
Deprecate EmptyMessageChain
in favor of emptyMessageChain()
This commit is contained in:
parent
c118180b54
commit
b40b681f81
@ -146,7 +146,7 @@ public interface CommandManager {
|
||||
public suspend fun executeCommand(
|
||||
sender: CommandSender,
|
||||
command: Command,
|
||||
arguments: Message = EmptyMessageChain,
|
||||
arguments: Message = emptyMessageChain(),
|
||||
checkPermission: Boolean = true,
|
||||
): CommandExecuteResult {
|
||||
// TODO: 2020/10/18 net.mamoe.mirai.console.command.CommandManager.execute
|
||||
|
@ -19,7 +19,7 @@ import net.mamoe.mirai.console.extensions.CommandCallResolverProvider
|
||||
import net.mamoe.mirai.console.internal.data.classifierAsKClass
|
||||
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
||||
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
|
||||
|
||||
/**
|
||||
@ -149,7 +149,7 @@ public object BuiltInCommandCallResolver : CommandCallResolver {
|
||||
// add default empty vararg argument
|
||||
val remainingVararg = remainingParameters.find { it.isVararg }
|
||||
if (remainingVararg != null) {
|
||||
zipped.add(remainingVararg to DefaultCommandValueArgument(EmptyMessageChain))
|
||||
zipped.add(remainingVararg to DefaultCommandValueArgument(emptyMessageChain()))
|
||||
remainingParameters.remove(remainingVararg)
|
||||
}
|
||||
}
|
||||
@ -195,7 +195,7 @@ public object BuiltInCommandCallResolver : CommandCallResolver {
|
||||
.also { list ->
|
||||
|
||||
val candidates = list
|
||||
.asSequence().filterIsInstance<ResolveData>()
|
||||
.asSequence()
|
||||
.flatMap { phase ->
|
||||
phase.argumentAcceptances.filter { it.acceptance is ArgumentAcceptance.Direct }
|
||||
.map { phase to it }
|
||||
|
@ -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 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 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 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;
|
||||
|
@ -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 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 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 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;
|
||||
|
@ -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)
|
||||
@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() {
|
||||
override val size: Int get() = 0
|
||||
|
||||
|
@ -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")
|
||||
@ -163,7 +163,7 @@ internal fun <M : SingleMessage> MessageChain.getImpl(key: MessageKey<M>): M? {
|
||||
* @return [EmptyMessageChain] if [delegate] is empty, otherwise [MessageChainImpl]
|
||||
*/
|
||||
internal fun createMessageChainImplOptimized(delegate: List<SingleMessage>): MessageChain {
|
||||
return if (delegate.isEmpty()) EmptyMessageChain
|
||||
return if (delegate.isEmpty()) emptyMessageChain()
|
||||
else MessageChainImpl(delegate)
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
@ -18,7 +18,7 @@ import kotlin.test.assertTrue
|
||||
internal class MessageUtilsTest {
|
||||
@Test
|
||||
fun testIsContentEmpty() {
|
||||
assertTrue { EmptyMessageChain.isContentEmpty() }
|
||||
assertTrue { emptyMessageChain().isContentEmpty() }
|
||||
assertTrue { buildMessageChain { }.isContentEmpty() }
|
||||
assertTrue { PlainText("").isContentEmpty() }
|
||||
assertTrue { (PlainText("") + PlainText("")).isContentEmpty() }
|
||||
|
Loading…
Reference in New Issue
Block a user