From e4e1e684e3db6166965a9d8e22de431dc5fcd11b Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 17 May 2020 12:50:59 +0800 Subject: [PATCH] Cleanup --- .../net/mamoe/mirai/console/command/Command.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/Command.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/Command.kt index 794561ef4..f9b568763 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/Command.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/Command.kt @@ -51,19 +51,21 @@ interface Command { */ abstract class CompositeCommand @JvmOverloads constructor( override val owner: CommandOwner, - override vararg val names: String, - override val description: String, + vararg names: String, + override val description: String = "", override val permission: CommandPermission = CommandPermission.Default, override val prefixOptional: Boolean = false, overrideContext: CommandParserContext = EmptyCommandParserContext ) : Command { + override val names: Array = + names.map(String::trim).filterNot(String::isEmpty).map(String::toLowerCase).toTypedArray() val context: CommandParserContext = CommandParserContext.Builtins + overrideContext override val usage: String by lazy { TODO() } /** 指定子指令要求的权限 */ @Retention(AnnotationRetention.RUNTIME) @Target(AnnotationTarget.FUNCTION) - annotation class Permission(val permission: KClass) + annotation class Permission(val permission: KClass) /** 标记一个函数为子指令 */ @Retention(AnnotationRetention.RUNTIME) @@ -146,7 +148,7 @@ abstract class CompositeCommand @JvmOverloads constructor( argsWithSubCommandNameNotRemoved: Array ) { if (!onCommand(sender, parseArgs(sender, argsWithSubCommandNameNotRemoved, names.size))) { - // TODO: 2020/5/16 SEND USAGE + sender.sendMessage(usage) } } @@ -218,7 +220,7 @@ internal fun String.bakeSubName(): Array = split(' ').filterNot { it.isB internal fun Any.flattenCommandComponents(): ArrayList { val list = ArrayList() - when (this::class.java) { + when (this::class.java) { // faster than is String::class.java -> (this as String).splitToSequence(' ').filterNot { it.isBlank() }.forEach { list.add(it) } PlainText::class.java -> (this as PlainText).content.splitToSequence(' ').filterNot { it.isBlank() } .forEach { list.add(it) }