diff --git a/backend/mirai-console/src/command/CommandExecuteResult.kt b/backend/mirai-console/src/command/CommandExecuteResult.kt index 72acb223b..241dcf090 100644 --- a/backend/mirai-console/src/command/CommandExecuteResult.kt +++ b/backend/mirai-console/src/command/CommandExecuteResult.kt @@ -17,8 +17,6 @@ import net.mamoe.mirai.console.command.parse.CommandCall import net.mamoe.mirai.console.command.parse.CommandValueArgument import net.mamoe.mirai.console.command.resolve.ResolvedCommandCall import net.mamoe.mirai.console.util.ConsoleExperimentalApi -import net.mamoe.mirai.message.data.Message -import net.mamoe.mirai.message.data.MessageChain import kotlin.contracts.contract /** @@ -46,12 +44,6 @@ public sealed class CommandExecuteResult { /** 解析的 [ResolvedCommandCall] (如果匹配到) */ public abstract val resolvedCall: ResolvedCommandCall? - /** 尝试执行的指令名 (如果匹配到) */ - public abstract val commandName: String? - - /** 基础分割后的实际参数列表, 元素类型可能为 [Message] 或 [String] */ - public abstract val args: MessageChain? - // abstract val to allow smart casting /** 指令执行成功 */ @@ -62,10 +54,6 @@ public sealed class CommandExecuteResult { public override val call: CommandCall, /** 解析的 [ResolvedCommandCall] (如果匹配到) */ public override val resolvedCall: ResolvedCommandCall, - /** 尝试执行的指令名 */ - public override val commandName: String, - /** 基础分割后的实际参数列表, 元素类型可能为 [Message] 或 [String] */ - public override val args: MessageChain, ) : CommandExecuteResult() { /** 指令执行时发生的错误, 总是 `null` */ public override val exception: Nothing? get() = null @@ -87,10 +75,6 @@ public sealed class CommandExecuteResult { public override val call: CommandCall, /** 解析的 [ResolvedCommandCall] (如果匹配到) */ public override val resolvedCall: ResolvedCommandCall, - /** 尝试执行的指令名 */ - public override val commandName: String, - /** 基础分割后的实际参数列表, 元素类型可能为 [Message] 或 [String] */ - public override val args: MessageChain, ) : Failure() { /** 指令最终执行状态, 总是 [CommandExecuteStatus.EXECUTION_EXCEPTION] */ public override val status: CommandExecuteStatus get() = CommandExecuteStatus.ILLEGAL_ARGUMENT @@ -106,20 +90,13 @@ public sealed class CommandExecuteResult { public override val call: CommandCall, /** 解析的 [ResolvedCommandCall] (如果匹配到) */ public override val resolvedCall: ResolvedCommandCall, - /** 尝试执行的指令名 */ - public override val commandName: String, - /** 基础分割后的实际参数列表, 元素类型可能为 [Message] 或 [String] */ - public override val args: MessageChain, ) : Failure() { /** 指令最终执行状态, 总是 [CommandExecuteStatus.EXECUTION_EXCEPTION] */ public override val status: CommandExecuteStatus get() = CommandExecuteStatus.EXECUTION_EXCEPTION } /** 没有匹配的指令 */ - public class UnresolvedCommand( - /** 尝试执行的指令名 */ - public override val commandName: String, - ) : Failure() { + public class UnresolvedCommand : Failure() { /** 指令执行时发生的错误, 总是 `null` */ public override val exception: Nothing? get() = null @@ -132,9 +109,6 @@ public sealed class CommandExecuteResult { /** 解析的 [ResolvedCommandCall] (如果匹配到) */ public override val resolvedCall: ResolvedCommandCall? get() = null - /** 基础分割后的实际参数列表, 元素类型可能为 [Message] 或 [String] */ - public override val args: Nothing? get() = null - /** 指令最终执行状态, 总是 [CommandExecuteStatus.UNRESOLVED_COMMAND] */ public override val status: CommandExecuteStatus get() = CommandExecuteStatus.UNRESOLVED_COMMAND } @@ -147,12 +121,7 @@ public sealed class CommandExecuteResult { public override val call: CommandCall, /** 解析的 [ResolvedCommandCall] (如果匹配到) */ public override val resolvedCall: ResolvedCommandCall, - /** 尝试执行的指令名 */ - public override val commandName: String, ) : Failure() { - /** 基础分割后的实际参数列表, 元素类型可能为 [Message] 或 [String] */ - public override val args: Nothing? get() = null - /** 指令执行时发生的错误, 总是 `null` */ public override val exception: Nothing? get() = null @@ -162,8 +131,6 @@ public sealed class CommandExecuteResult { /** 没有匹配的指令 */ public class UnmatchedSignature( - /** 尝试执行的指令名 */ - public override val commandName: String, /** 尝试执行的指令 */ public override val command: Command, /** 尝试执行的指令 */ @@ -180,9 +147,6 @@ public sealed class CommandExecuteResult { /** 解析的 [ResolvedCommandCall] (如果匹配到) */ public override val resolvedCall: ResolvedCommandCall? get() = null - /** 基础分割后的实际参数列表, 元素类型可能为 [Message] 或 [String] */ - public override val args: Nothing? get() = null - /** 指令最终执行状态, 总是 [CommandExecuteStatus.UNMATCHED_SIGNATURE] */ public override val status: CommandExecuteStatus get() = CommandExecuteStatus.UNMATCHED_SIGNATURE } diff --git a/backend/mirai-console/src/command/resolve/BuiltInCommandCallResolver.kt b/backend/mirai-console/src/command/resolve/BuiltInCommandCallResolver.kt index c45a10da8..e591c7012 100644 --- a/backend/mirai-console/src/command/resolve/BuiltInCommandCallResolver.kt +++ b/backend/mirai-console/src/command/resolve/BuiltInCommandCallResolver.kt @@ -79,7 +79,7 @@ public object BuiltInCommandCallResolver : CommandCallResolver { val failureReasons = unmatchedCommandSignatures.toMutableList() val rA = FailureReason.ResolutionAmbiguity(resolutionAmbiguities) failureReasons.addAll(resolutionAmbiguities.map { UnmatchedCommandSignature(it, rA) }) - return CommandExecuteResult.UnmatchedSignature(call.calleeName, command, unmatchedCommandSignatures) + return CommandExecuteResult.UnmatchedSignature(command, unmatchedCommandSignatures) } } diff --git a/backend/mirai-console/src/internal/command/CommandManagerImpl.kt b/backend/mirai-console/src/internal/command/CommandManagerImpl.kt index 1c978c3f0..bc5120219 100644 --- a/backend/mirai-console/src/internal/command/CommandManagerImpl.kt +++ b/backend/mirai-console/src/internal/command/CommandManagerImpl.kt @@ -27,7 +27,6 @@ import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope import net.mamoe.mirai.event.Listener import net.mamoe.mirai.event.subscribeAlways import net.mamoe.mirai.message.MessageEvent -import net.mamoe.mirai.message.data.EmptyMessageChain import net.mamoe.mirai.message.data.Message import net.mamoe.mirai.message.data.asMessageChain import net.mamoe.mirai.message.data.content @@ -178,7 +177,7 @@ internal suspend fun executeCommandImpl( caller: CommandSender, checkPermission: Boolean, ): CommandExecuteResult { - val call = message.asMessageChain().parseCommandCall(caller) ?: return CommandExecuteResult.UnresolvedCommand("") + val call = message.asMessageChain().parseCommandCall(caller) ?: return CommandExecuteResult.UnresolvedCommand() val resolved = call.resolve().fold( onSuccess = { it }, onFailure = { return it } @@ -187,16 +186,16 @@ internal suspend fun executeCommandImpl( val command = resolved.callee if (checkPermission && !command.permission.testPermission(caller)) { - return CommandExecuteResult.PermissionDenied(command, call, resolved, call.calleeName) + return CommandExecuteResult.PermissionDenied(command, call, resolved) } return try { resolved.calleeSignature.call(resolved) - CommandExecuteResult.Success(resolved.callee, call, resolved, call.calleeName, EmptyMessageChain) + CommandExecuteResult.Success(resolved.callee, call, resolved) } catch (e: CommandArgumentParserException) { - CommandExecuteResult.IllegalArgument(e, resolved.callee, call, resolved, call.calleeName, EmptyMessageChain) + CommandExecuteResult.IllegalArgument(e, resolved.callee, call, resolved) } catch (e: Throwable) { - CommandExecuteResult.ExecutionFailed(e, resolved.callee, call, resolved, call.calleeName, EmptyMessageChain) + CommandExecuteResult.ExecutionFailed(e, resolved.callee, call, resolved) } } diff --git a/frontend/mirai-console-terminal/src/ConsoleThread.kt b/frontend/mirai-console-terminal/src/ConsoleThread.kt index 575b28be9..c82476e7f 100644 --- a/frontend/mirai-console-terminal/src/ConsoleThread.kt +++ b/frontend/mirai-console-terminal/src/ConsoleThread.kt @@ -70,7 +70,7 @@ internal fun startupConsoleThread() { consoleLogger.error(result.exception) } is UnresolvedCommand -> { - consoleLogger.warning { "未知指令: ${result.commandName}, 输入 ? 获取帮助" } + consoleLogger.warning { "未知指令: ${next}, 输入 ? 获取帮助" } } is PermissionDenied -> { consoleLogger.warning { "权限不足." }