diff --git a/backend/mirai-console/src/command/descriptor/CommandParameter.kt b/backend/mirai-console/src/command/descriptor/CommandParameter.kt index 77960e867..e6d30d783 100644 --- a/backend/mirai-console/src/command/descriptor/CommandParameter.kt +++ b/backend/mirai-console/src/command/descriptor/CommandParameter.kt @@ -18,6 +18,7 @@ import net.mamoe.mirai.console.internal.data.classifierAsKClass import net.mamoe.mirai.console.internal.data.classifierAsKClassOrNull import net.mamoe.mirai.console.internal.data.typeOf0 import net.mamoe.mirai.console.util.ConsoleExperimentalApi +import net.mamoe.mirai.message.data.content import kotlin.reflect.KClass import kotlin.reflect.KType import kotlin.reflect.full.isSubclassOf @@ -144,7 +145,7 @@ public sealed class AbstractCommandValueParameter : CommandValueParameter, return acceptingImpl(this.type, argument, commandArgumentContext) } - private fun acceptingImpl( + protected open fun acceptingImpl( expectingType: KType, argument: CommandValueArgument, commandArgumentContext: CommandArgumentContext?, @@ -184,6 +185,12 @@ public sealed class AbstractCommandValueParameter : CommandValueParameter, override fun toString(): String = "<$expectingValue>" + override fun acceptingImpl(expectingType: KType, argument: CommandValueArgument, commandArgumentContext: CommandArgumentContext?): ArgumentAcceptance { + return if (argument.type.isSubtypeOf(expectingType) && argument.value.content == expectingValue) { + ArgumentAcceptance.Direct + } else ArgumentAcceptance.Impossible + } + private companion object { @OptIn(ExperimentalStdlibApi::class) val STRING_TYPE = typeOf()