feat: support query single command description
This commit is contained in:
1 file changed
+31
-11
@@ -22,6 +22,7 @@ class HelpCommand : BaseCommand() {
|
||||
override val commandNames = listOf("/help", "/帮助")
|
||||
|
||||
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||
if (args.isEmpty()) {
|
||||
val node = NodeMessageChain.Builder()
|
||||
val msg = MessageChain.Builder()
|
||||
commands.sortedBy { it::class.simpleName }.forEach {
|
||||
@@ -35,5 +36,24 @@ class HelpCommand : BaseCommand() {
|
||||
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<CommandDescription>()?.description ?: "暂无描述"
|
||||
val msg = MessageChain.Builder()
|
||||
.addText("命令名称: ${matchedCommand::class.simpleName}")
|
||||
.addNewLine()
|
||||
.addText("指令别名: ${matchedCommand.commandNames.joinToString(",")}")
|
||||
.addNewLine()
|
||||
.addText("指令描述: $description")
|
||||
.build()
|
||||
message.reply(msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user