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