mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Remove CommandExecuteResult.commandName and CommandExecuteResult.args
This commit is contained in:
parent
64790d0114
commit
72ec0aa6c9
@ -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.parse.CommandValueArgument
|
||||||
import net.mamoe.mirai.console.command.resolve.ResolvedCommandCall
|
import net.mamoe.mirai.console.command.resolve.ResolvedCommandCall
|
||||||
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
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
|
import kotlin.contracts.contract
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,12 +44,6 @@ public sealed class CommandExecuteResult {
|
|||||||
/** 解析的 [ResolvedCommandCall] (如果匹配到) */
|
/** 解析的 [ResolvedCommandCall] (如果匹配到) */
|
||||||
public abstract val resolvedCall: ResolvedCommandCall?
|
public abstract val resolvedCall: ResolvedCommandCall?
|
||||||
|
|
||||||
/** 尝试执行的指令名 (如果匹配到) */
|
|
||||||
public abstract val commandName: String?
|
|
||||||
|
|
||||||
/** 基础分割后的实际参数列表, 元素类型可能为 [Message] 或 [String] */
|
|
||||||
public abstract val args: MessageChain?
|
|
||||||
|
|
||||||
// abstract val to allow smart casting
|
// abstract val to allow smart casting
|
||||||
|
|
||||||
/** 指令执行成功 */
|
/** 指令执行成功 */
|
||||||
@ -62,10 +54,6 @@ public sealed class CommandExecuteResult {
|
|||||||
public override val call: CommandCall,
|
public override val call: CommandCall,
|
||||||
/** 解析的 [ResolvedCommandCall] (如果匹配到) */
|
/** 解析的 [ResolvedCommandCall] (如果匹配到) */
|
||||||
public override val resolvedCall: ResolvedCommandCall,
|
public override val resolvedCall: ResolvedCommandCall,
|
||||||
/** 尝试执行的指令名 */
|
|
||||||
public override val commandName: String,
|
|
||||||
/** 基础分割后的实际参数列表, 元素类型可能为 [Message] 或 [String] */
|
|
||||||
public override val args: MessageChain,
|
|
||||||
) : CommandExecuteResult() {
|
) : CommandExecuteResult() {
|
||||||
/** 指令执行时发生的错误, 总是 `null` */
|
/** 指令执行时发生的错误, 总是 `null` */
|
||||||
public override val exception: Nothing? get() = null
|
public override val exception: Nothing? get() = null
|
||||||
@ -87,10 +75,6 @@ public sealed class CommandExecuteResult {
|
|||||||
public override val call: CommandCall,
|
public override val call: CommandCall,
|
||||||
/** 解析的 [ResolvedCommandCall] (如果匹配到) */
|
/** 解析的 [ResolvedCommandCall] (如果匹配到) */
|
||||||
public override val resolvedCall: ResolvedCommandCall,
|
public override val resolvedCall: ResolvedCommandCall,
|
||||||
/** 尝试执行的指令名 */
|
|
||||||
public override val commandName: String,
|
|
||||||
/** 基础分割后的实际参数列表, 元素类型可能为 [Message] 或 [String] */
|
|
||||||
public override val args: MessageChain,
|
|
||||||
) : Failure() {
|
) : Failure() {
|
||||||
/** 指令最终执行状态, 总是 [CommandExecuteStatus.EXECUTION_EXCEPTION] */
|
/** 指令最终执行状态, 总是 [CommandExecuteStatus.EXECUTION_EXCEPTION] */
|
||||||
public override val status: CommandExecuteStatus get() = CommandExecuteStatus.ILLEGAL_ARGUMENT
|
public override val status: CommandExecuteStatus get() = CommandExecuteStatus.ILLEGAL_ARGUMENT
|
||||||
@ -106,20 +90,13 @@ public sealed class CommandExecuteResult {
|
|||||||
public override val call: CommandCall,
|
public override val call: CommandCall,
|
||||||
/** 解析的 [ResolvedCommandCall] (如果匹配到) */
|
/** 解析的 [ResolvedCommandCall] (如果匹配到) */
|
||||||
public override val resolvedCall: ResolvedCommandCall,
|
public override val resolvedCall: ResolvedCommandCall,
|
||||||
/** 尝试执行的指令名 */
|
|
||||||
public override val commandName: String,
|
|
||||||
/** 基础分割后的实际参数列表, 元素类型可能为 [Message] 或 [String] */
|
|
||||||
public override val args: MessageChain,
|
|
||||||
) : Failure() {
|
) : Failure() {
|
||||||
/** 指令最终执行状态, 总是 [CommandExecuteStatus.EXECUTION_EXCEPTION] */
|
/** 指令最终执行状态, 总是 [CommandExecuteStatus.EXECUTION_EXCEPTION] */
|
||||||
public override val status: CommandExecuteStatus get() = CommandExecuteStatus.EXECUTION_EXCEPTION
|
public override val status: CommandExecuteStatus get() = CommandExecuteStatus.EXECUTION_EXCEPTION
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 没有匹配的指令 */
|
/** 没有匹配的指令 */
|
||||||
public class UnresolvedCommand(
|
public class UnresolvedCommand : Failure() {
|
||||||
/** 尝试执行的指令名 */
|
|
||||||
public override val commandName: String,
|
|
||||||
) : Failure() {
|
|
||||||
/** 指令执行时发生的错误, 总是 `null` */
|
/** 指令执行时发生的错误, 总是 `null` */
|
||||||
public override val exception: Nothing? get() = null
|
public override val exception: Nothing? get() = null
|
||||||
|
|
||||||
@ -132,9 +109,6 @@ public sealed class CommandExecuteResult {
|
|||||||
/** 解析的 [ResolvedCommandCall] (如果匹配到) */
|
/** 解析的 [ResolvedCommandCall] (如果匹配到) */
|
||||||
public override val resolvedCall: ResolvedCommandCall? get() = null
|
public override val resolvedCall: ResolvedCommandCall? get() = null
|
||||||
|
|
||||||
/** 基础分割后的实际参数列表, 元素类型可能为 [Message] 或 [String] */
|
|
||||||
public override val args: Nothing? get() = null
|
|
||||||
|
|
||||||
/** 指令最终执行状态, 总是 [CommandExecuteStatus.UNRESOLVED_COMMAND] */
|
/** 指令最终执行状态, 总是 [CommandExecuteStatus.UNRESOLVED_COMMAND] */
|
||||||
public override val status: CommandExecuteStatus get() = 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,
|
public override val call: CommandCall,
|
||||||
/** 解析的 [ResolvedCommandCall] (如果匹配到) */
|
/** 解析的 [ResolvedCommandCall] (如果匹配到) */
|
||||||
public override val resolvedCall: ResolvedCommandCall,
|
public override val resolvedCall: ResolvedCommandCall,
|
||||||
/** 尝试执行的指令名 */
|
|
||||||
public override val commandName: String,
|
|
||||||
) : Failure() {
|
) : Failure() {
|
||||||
/** 基础分割后的实际参数列表, 元素类型可能为 [Message] 或 [String] */
|
|
||||||
public override val args: Nothing? get() = null
|
|
||||||
|
|
||||||
/** 指令执行时发生的错误, 总是 `null` */
|
/** 指令执行时发生的错误, 总是 `null` */
|
||||||
public override val exception: Nothing? get() = null
|
public override val exception: Nothing? get() = null
|
||||||
|
|
||||||
@ -162,8 +131,6 @@ public sealed class CommandExecuteResult {
|
|||||||
|
|
||||||
/** 没有匹配的指令 */
|
/** 没有匹配的指令 */
|
||||||
public class UnmatchedSignature(
|
public class UnmatchedSignature(
|
||||||
/** 尝试执行的指令名 */
|
|
||||||
public override val commandName: String,
|
|
||||||
/** 尝试执行的指令 */
|
/** 尝试执行的指令 */
|
||||||
public override val command: Command,
|
public override val command: Command,
|
||||||
/** 尝试执行的指令 */
|
/** 尝试执行的指令 */
|
||||||
@ -180,9 +147,6 @@ public sealed class CommandExecuteResult {
|
|||||||
/** 解析的 [ResolvedCommandCall] (如果匹配到) */
|
/** 解析的 [ResolvedCommandCall] (如果匹配到) */
|
||||||
public override val resolvedCall: ResolvedCommandCall? get() = null
|
public override val resolvedCall: ResolvedCommandCall? get() = null
|
||||||
|
|
||||||
/** 基础分割后的实际参数列表, 元素类型可能为 [Message] 或 [String] */
|
|
||||||
public override val args: Nothing? get() = null
|
|
||||||
|
|
||||||
/** 指令最终执行状态, 总是 [CommandExecuteStatus.UNMATCHED_SIGNATURE] */
|
/** 指令最终执行状态, 总是 [CommandExecuteStatus.UNMATCHED_SIGNATURE] */
|
||||||
public override val status: CommandExecuteStatus get() = CommandExecuteStatus.UNMATCHED_SIGNATURE
|
public override val status: CommandExecuteStatus get() = CommandExecuteStatus.UNMATCHED_SIGNATURE
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ public object BuiltInCommandCallResolver : CommandCallResolver {
|
|||||||
val failureReasons = unmatchedCommandSignatures.toMutableList()
|
val failureReasons = unmatchedCommandSignatures.toMutableList()
|
||||||
val rA = FailureReason.ResolutionAmbiguity(resolutionAmbiguities)
|
val rA = FailureReason.ResolutionAmbiguity(resolutionAmbiguities)
|
||||||
failureReasons.addAll(resolutionAmbiguities.map { UnmatchedCommandSignature(it, rA) })
|
failureReasons.addAll(resolutionAmbiguities.map { UnmatchedCommandSignature(it, rA) })
|
||||||
return CommandExecuteResult.UnmatchedSignature(call.calleeName, command, unmatchedCommandSignatures)
|
return CommandExecuteResult.UnmatchedSignature(command, unmatchedCommandSignatures)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope
|
|||||||
import net.mamoe.mirai.event.Listener
|
import net.mamoe.mirai.event.Listener
|
||||||
import net.mamoe.mirai.event.subscribeAlways
|
import net.mamoe.mirai.event.subscribeAlways
|
||||||
import net.mamoe.mirai.message.MessageEvent
|
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.Message
|
||||||
import net.mamoe.mirai.message.data.asMessageChain
|
import net.mamoe.mirai.message.data.asMessageChain
|
||||||
import net.mamoe.mirai.message.data.content
|
import net.mamoe.mirai.message.data.content
|
||||||
@ -178,7 +177,7 @@ internal suspend fun executeCommandImpl(
|
|||||||
caller: CommandSender,
|
caller: CommandSender,
|
||||||
checkPermission: Boolean,
|
checkPermission: Boolean,
|
||||||
): CommandExecuteResult {
|
): CommandExecuteResult {
|
||||||
val call = message.asMessageChain().parseCommandCall(caller) ?: return CommandExecuteResult.UnresolvedCommand("")
|
val call = message.asMessageChain().parseCommandCall(caller) ?: return CommandExecuteResult.UnresolvedCommand()
|
||||||
val resolved = call.resolve().fold(
|
val resolved = call.resolve().fold(
|
||||||
onSuccess = { it },
|
onSuccess = { it },
|
||||||
onFailure = { return it }
|
onFailure = { return it }
|
||||||
@ -187,16 +186,16 @@ internal suspend fun executeCommandImpl(
|
|||||||
val command = resolved.callee
|
val command = resolved.callee
|
||||||
|
|
||||||
if (checkPermission && !command.permission.testPermission(caller)) {
|
if (checkPermission && !command.permission.testPermission(caller)) {
|
||||||
return CommandExecuteResult.PermissionDenied(command, call, resolved, call.calleeName)
|
return CommandExecuteResult.PermissionDenied(command, call, resolved)
|
||||||
}
|
}
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
resolved.calleeSignature.call(resolved)
|
resolved.calleeSignature.call(resolved)
|
||||||
CommandExecuteResult.Success(resolved.callee, call, resolved, call.calleeName, EmptyMessageChain)
|
CommandExecuteResult.Success(resolved.callee, call, resolved)
|
||||||
} catch (e: CommandArgumentParserException) {
|
} catch (e: CommandArgumentParserException) {
|
||||||
CommandExecuteResult.IllegalArgument(e, resolved.callee, call, resolved, call.calleeName, EmptyMessageChain)
|
CommandExecuteResult.IllegalArgument(e, resolved.callee, call, resolved)
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
CommandExecuteResult.ExecutionFailed(e, resolved.callee, call, resolved, call.calleeName, EmptyMessageChain)
|
CommandExecuteResult.ExecutionFailed(e, resolved.callee, call, resolved)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ internal fun startupConsoleThread() {
|
|||||||
consoleLogger.error(result.exception)
|
consoleLogger.error(result.exception)
|
||||||
}
|
}
|
||||||
is UnresolvedCommand -> {
|
is UnresolvedCommand -> {
|
||||||
consoleLogger.warning { "未知指令: ${result.commandName}, 输入 ? 获取帮助" }
|
consoleLogger.warning { "未知指令: ${next}, 输入 ? 获取帮助" }
|
||||||
}
|
}
|
||||||
is PermissionDenied -> {
|
is PermissionDenied -> {
|
||||||
consoleLogger.warning { "权限不足." }
|
consoleLogger.warning { "权限不足." }
|
||||||
|
Loading…
Reference in New Issue
Block a user