diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/HelpCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/HelpCommand.kt index 588f5da..5a55fd2 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/HelpCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/HelpCommand.kt @@ -22,18 +22,38 @@ class HelpCommand : BaseCommand() { override val commandNames = listOf("/help", "/帮助") override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List) { - val node = NodeMessageChain.Builder() - val msg = MessageChain.Builder() - commands.sortedBy { it::class.simpleName }.forEach { - val description = if (!it::class.hasAnnotation()) "暂无描述" - else it::class.findAnnotation()?.description!! - val commandName = it::class.simpleName?.replace("Command", "")!! - val commandNames = it.commandNames.joinToString(",") - msg.addText("[$commandName] [$description] 命令: $commandNames") + if (args.isEmpty()) { + val node = NodeMessageChain.Builder() + val msg = MessageChain.Builder() + commands.sortedBy { it::class.simpleName }.forEach { + val description = if (!it::class.hasAnnotation()) "暂无描述" + else it::class.findAnnotation()?.description!! + val commandName = it::class.simpleName?.replace("Command", "")!! + val commandNames = it.commandNames.joinToString(",") + msg.addText("[$commandName] [$description] 命令: $commandNames") + .addNewLine() + } + msg.addText("共计${commands.size}条命令") + node.addMessageChain(msg.build(), message.sender.userId) + message.reply(node.build()) + } else { + val commandName = args.first().replace("/", "") + val matchedCommand = commands.find { + it.commandNames.map { map -> map.replace("/", "") }.contains(commandName) + } + if (matchedCommand == null) { + message.reply("未查询到该命令") + return + } + val description = matchedCommand::class.findAnnotation()?.description ?: "暂无描述" + val msg = MessageChain.Builder() + .addText("命令名称: ${matchedCommand::class.simpleName}") .addNewLine() + .addText("指令别名: ${matchedCommand.commandNames.joinToString(",")}") + .addNewLine() + .addText("指令描述: $description") + .build() + message.reply(msg) } - msg.addText("共计${commands.size}条命令") - node.addMessageChain(msg.build(), message.sender.userId) - message.reply(node.build()) } } \ No newline at end of file