diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandDescriptor.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandDescriptor.kt index 28c5164d9..e61c2c798 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandDescriptor.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandDescriptor.kt @@ -13,13 +13,21 @@ class CommandDescriptor( */ val fullName: String, /** - * 指令参数解析器环境. + * 用法说明 */ - val context: CommandParserContext, + val usage: String, /** * 指令参数列表, 有顺序. */ val params: List>, + /** + * 指令参数解析器环境. + */ + val context: CommandParserContext = CommandParserContext.Builtins, + /** + * 指令别名 + */ + val aliases: Array = arrayOf(), /** * 指令权限 * @@ -50,6 +58,12 @@ class CommandDescriptorBuilder( @PublishedApi internal var params: MutableList> = mutableListOf() + @PublishedApi + internal var usage: String = "" + + @PublishedApi + internal var aliases: MutableList = mutableListOf() + /** 增加指令参数解析器列表 */ @JvmSynthetic inline fun context(block: CommandParserContextBuilder.() -> Unit) { @@ -73,6 +87,14 @@ class CommandDescriptorBuilder( this.permission = AnonymousCommandPermission(block) } + fun usage(message: String): CommandDescriptorBuilder = apply { + usage = message + } + + fun alias(vararg name: String): CommandDescriptorBuilder = apply { + this.aliases.addAll(name) + } + fun param(vararg params: CommandParam<*>): CommandDescriptorBuilder = apply { this.params.addAll(params) } @@ -120,7 +142,8 @@ class CommandDescriptorBuilder( this.params.add(CommandParam(null, type.kotlin)) } - fun build(): CommandDescriptor = CommandDescriptor(fullName, context, params, permission) + fun build(): CommandDescriptor = + CommandDescriptor(fullName, context, params, usage, aliases.toTypedArray(), permission) } @Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")