Fix string constant arguments

This commit is contained in:
Him188 2020-10-30 11:35:50 +08:00
parent 71c744c429
commit b6794a8826

View File

@ -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<T> : CommandValueParameter<T>,
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<T> : CommandValueParameter<T>,
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<String>()