Fix CommandCallResolver on unresolved command

This commit is contained in:
Him188 2020-11-19 08:47:36 +08:00
parent 29070309f1
commit 9d1294603d
2 changed files with 5 additions and 5 deletions

View File

@ -28,7 +28,7 @@ import net.mamoe.mirai.message.data.asMessageChain
@ExperimentalCommandDescriptors
public object BuiltInCommandCallResolver : CommandCallResolver {
override fun resolve(call: CommandCall): CommandResolveResult {
val callee = CommandManager.matchCommand(call.calleeName) ?: return CommandResolveResult(null)
val callee = CommandManager.matchCommand(call.calleeName) ?: return CommandResolveResult(CommandExecuteResult.UnresolvedCommand(call))
val valueArguments = call.valueArguments
val context = callee.safeCast<CommandArgumentContextAware>()?.context

View File

@ -32,11 +32,11 @@ public class CommandResolveResult private constructor(
public val failure: CommandExecuteResult.Failure?
get() = value.safeCast()
public constructor(call: ResolvedCommandCall?) : this(call as Any?)
public constructor(call: ResolvedCommandCall) : this(call as Any?)
public constructor(failure: CommandExecuteResult.Failure) : this(failure as Any)
}
@OptIn(ExperimentalCommandDescriptors::class)
@ExperimentalCommandDescriptors
public inline fun <R> CommandResolveResult.fold(
onSuccess: (ResolvedCommandCall?) -> R,
onFailure: (CommandExecuteResult.Failure) -> R,
@ -50,9 +50,9 @@ public inline fun <R> CommandResolveResult.fold(
}
@OptIn(ExperimentalCommandDescriptors::class)
@ExperimentalCommandDescriptors
public inline fun CommandResolveResult.getOrElse(
onFailure: (CommandExecuteResult.Failure) -> ResolvedCommandCall,
onFailure: (CommandExecuteResult.Failure) -> ResolvedCommandCall?,
): ResolvedCommandCall {
contract {
callsInPlace(onFailure, InvocationKind.AT_MOST_ONCE)