From 5da481dd1b1b707a9be23e46075d6051e30379e4 Mon Sep 17 00:00:00 2001 From: Him188 Date: Wed, 3 Feb 2021 12:39:40 +0800 Subject: [PATCH] PermitteeIdValueArgumentParser: Parse numerical values as ExactUser for convenience --- .../descriptor/CommandArgumentParserBuiltins.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/mirai-console/src/command/descriptor/CommandArgumentParserBuiltins.kt b/backend/mirai-console/src/command/descriptor/CommandArgumentParserBuiltins.kt index bda25be58..947a4cdef 100644 --- a/backend/mirai-console/src/command/descriptor/CommandArgumentParserBuiltins.kt +++ b/backend/mirai-console/src/command/descriptor/CommandArgumentParserBuiltins.kt @@ -347,8 +347,15 @@ public object PermissionIdValueArgumentParser : InternalCommandValueArgumentPars public object PermitteeIdValueArgumentParser : InternalCommandValueArgumentParserExtensions() { override fun parse(raw: String, sender: CommandSender): PermitteeId { return if (raw == "~") sender.permitteeId - else kotlin.runCatching { AbstractPermitteeId.parseFromString(raw) }.getOrElse { - illegalArgument("无法解析 $raw 为被许可人 ID.") + else { + kotlin.runCatching { AbstractPermitteeId.parseFromString(raw) }.getOrElse { + val long = raw.toLongOrNull() + if (long != null) { + return AbstractPermitteeId.ExactUser(long)// for convenience + } + + illegalArgument("无法解析 $raw 为被许可人 ID.") + } } }