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 58c7cd35d..b4cadf0ce 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 @@ -9,6 +9,8 @@ package net.mamoe.mirai.console.command.descriptor +import net.mamoe.mirai.console.command.parse.RawCommandArgument +import net.mamoe.mirai.message.data.MessageContent import kotlin.reflect.KType import kotlin.reflect.typeOf @@ -16,23 +18,23 @@ import kotlin.reflect.typeOf public interface TypeVariant { public val outType: KType - public fun mapValue(valueParameter: String): OutType + public fun mapValue(valueParameter: MessageContent): OutType public companion object { @OptIn(ExperimentalStdlibApi::class) @JvmSynthetic - public inline operator fun invoke(crossinline block: (valueParameter: String) -> OutType): TypeVariant { + public inline operator fun invoke(crossinline block: (valueParameter: RawCommandArgument) -> OutType): TypeVariant { return object : TypeVariant { override val outType: KType = typeOf() - override fun mapValue(valueParameter: String): OutType = block(valueParameter) + override fun mapValue(valueParameter: MessageContent): OutType = block(valueParameter) } } } } @ExperimentalCommandDescriptors -public object StringTypeVariant : TypeVariant { +public object StringTypeVariant : TypeVariant { @OptIn(ExperimentalStdlibApi::class) override val outType: KType = typeOf() - override fun mapValue(valueParameter: String): String = valueParameter + override fun mapValue(valueParameter: RawCommandArgument): RawCommandArgument = valueParameter } 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 9d46cf11c..99c1e5e20 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 @@ -13,18 +13,25 @@ import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors import net.mamoe.mirai.console.command.descriptor.NoValueArgumentMappingException import net.mamoe.mirai.console.command.descriptor.StringTypeVariant import net.mamoe.mirai.console.command.descriptor.TypeVariant +import net.mamoe.mirai.message.data.MessageContent import kotlin.reflect.full.isSubtypeOf import kotlin.reflect.typeOf + +/** + * For developing use, to be inlined in the future. + */ +public typealias RawCommandArgument = MessageContent + @ExperimentalCommandDescriptors public interface CommandValueArgument { - public val value: String + public val value: RawCommandArgument public val typeVariants: List> } @ExperimentalCommandDescriptors public data class InvariantCommandValueArgument( - public override val value: String, + public override val value: RawCommandArgument, ) : CommandValueArgument { override val typeVariants: List> = listOf(StringTypeVariant) }