diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandManager.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandManager.kt index 17b992d79..73970d2d6 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandManager.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandManager.kt @@ -211,6 +211,7 @@ public suspend fun Command.execute( ): CommandExecuteResult { // TODO: 2020/10/18 net.mamoe.mirai.console.command.CommandManager.execute val chain = buildMessageChain { + append(CommandManager.commandPrefix) append(this@execute.primaryName) append(' ') append(arguments) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/TypeVariant.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/TypeVariant.kt index 81a47fc65..86761807d 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/TypeVariant.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/TypeVariant.kt @@ -12,7 +12,10 @@ package net.mamoe.mirai.console.command.descriptor import net.mamoe.mirai.console.command.parse.CommandCall import net.mamoe.mirai.console.command.parse.CommandCallParser import net.mamoe.mirai.console.command.parse.RawCommandArgument +import net.mamoe.mirai.message.data.MessageChain import net.mamoe.mirai.message.data.MessageContent +import net.mamoe.mirai.message.data.asMessageChain +import net.mamoe.mirai.message.data.content import kotlin.reflect.KType import kotlin.reflect.typeOf @@ -45,6 +48,20 @@ public interface TypeVariant { @ExperimentalCommandDescriptors public object MessageContentTypeVariant : TypeVariant { @OptIn(ExperimentalStdlibApi::class) - override val outType: KType = typeOf() + override val outType: KType = typeOf() override fun mapValue(valueParameter: MessageContent): MessageContent = valueParameter } + +@ExperimentalCommandDescriptors +public object MessageChainTypeVariant : TypeVariant { + @OptIn(ExperimentalStdlibApi::class) + override val outType: KType = typeOf() + override fun mapValue(valueParameter: MessageContent): MessageChain = valueParameter.asMessageChain() +} + +@ExperimentalCommandDescriptors +public object ContentStringTypeVariant : TypeVariant { + @OptIn(ExperimentalStdlibApi::class) + override val outType: KType = typeOf() + override fun mapValue(valueParameter: MessageContent): String = valueParameter.content +} diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/CommandValueArgument.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/CommandValueArgument.kt index f9dfe4588..3f1f0e1a7 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/CommandValueArgument.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/CommandValueArgument.kt @@ -9,10 +9,8 @@ package net.mamoe.mirai.console.command.parse -import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors -import net.mamoe.mirai.console.command.descriptor.MessageContentTypeVariant -import net.mamoe.mirai.console.command.descriptor.NoValueArgumentMappingException -import net.mamoe.mirai.console.command.descriptor.TypeVariant +import net.mamoe.mirai.console.command.descriptor.* +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.message.data.MessageContent import kotlin.reflect.KType import kotlin.reflect.full.isSubtypeOf @@ -31,7 +29,7 @@ public typealias RawCommandArgument = MessageContent public interface CommandArgument /** - * @see InvariantCommandValueArgument + * @see DefaultCommandValueArgument */ @ExperimentalCommandDescriptors public interface CommandValueArgument : CommandArgument { @@ -43,13 +41,18 @@ public interface CommandValueArgument : CommandArgument { /** * The [CommandValueArgument] that doesn't vary in type (remaining [MessageContent]). */ +@ConsoleExperimentalApi @ExperimentalCommandDescriptors -public data class InvariantCommandValueArgument( +public data class DefaultCommandValueArgument( public override val value: RawCommandArgument, ) : CommandValueArgument { @OptIn(ExperimentalStdlibApi::class) override val type: KType = typeOf() - override val typeVariants: List> = listOf(MessageContentTypeVariant) + override val typeVariants: List> = listOf( + MessageContentTypeVariant, + MessageChainTypeVariant, + ContentStringTypeVariant, + ) } @ExperimentalCommandDescriptors diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/SpaceSeparatedCommandCallParser.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/SpaceSeparatedCommandCallParser.kt index d5812ff66..8cb917344 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/SpaceSeparatedCommandCallParser.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/SpaceSeparatedCommandCallParser.kt @@ -18,7 +18,7 @@ public object SpaceSeparatedCommandCallParser : CommandCallParser { return CommandCallImpl( caller = caller, calleeName = flatten.first().content, - valueArguments = flatten.drop(1).map(::InvariantCommandValueArgument) + valueArguments = flatten.drop(1).map(::DefaultCommandValueArgument) ) }