2024-09-03 16:15:26 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2024 RTAkland
|
|
|
|
|
* Author: RTAkland
|
|
|
|
|
* Date: 2024/9/3
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package cn.rtast.fancybot.commands
|
|
|
|
|
|
2024-09-26 05:20:10 +08:00
|
|
|
import cn.rtast.fancybot.annotations.CommandDescription
|
2024-09-03 16:15:26 +08:00
|
|
|
import cn.rtast.fancybot.commands
|
2024-09-28 16:31:55 +08:00
|
|
|
import cn.rtast.fancybot.configManager
|
2024-09-03 16:15:26 +08:00
|
|
|
import cn.rtast.rob.entity.GroupMessage
|
|
|
|
|
import cn.rtast.rob.util.BaseCommand
|
|
|
|
|
import cn.rtast.rob.util.ob.MessageChain
|
2024-09-26 14:01:26 +08:00
|
|
|
import cn.rtast.rob.util.ob.NodeMessageChain
|
2024-09-19 11:06:40 +08:00
|
|
|
import cn.rtast.rob.util.ob.OneBotListener
|
2024-09-26 05:44:47 +08:00
|
|
|
import kotlin.reflect.full.findAnnotation
|
|
|
|
|
import kotlin.reflect.full.hasAnnotation
|
2024-09-03 16:15:26 +08:00
|
|
|
|
2024-09-26 05:21:42 +08:00
|
|
|
@CommandDescription("帮助")
|
2024-09-03 16:15:26 +08:00
|
|
|
class HelpCommand : BaseCommand() {
|
|
|
|
|
override val commandNames = listOf("/help", "/帮助")
|
|
|
|
|
|
2024-09-19 11:06:40 +08:00
|
|
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
2024-09-26 17:51:01 +08:00
|
|
|
if (args.isEmpty()) {
|
|
|
|
|
val node = NodeMessageChain.Builder()
|
|
|
|
|
val msg = MessageChain.Builder()
|
2024-10-07 20:12:04 +08:00
|
|
|
commands.sortedBy { it::class.simpleName }.toMutableList().forEach {
|
2024-09-26 17:51:01 +08:00
|
|
|
val description = if (!it::class.hasAnnotation<CommandDescription>()) "暂无描述"
|
|
|
|
|
else it::class.findAnnotation<CommandDescription>()?.description!!
|
|
|
|
|
val commandName = it::class.simpleName?.replace("Command", "")!!
|
|
|
|
|
val commandNames = it.commandNames.joinToString(",")
|
2024-10-07 20:12:04 +08:00
|
|
|
msg.addText("[$commandName] [$description] 命令: $commandNames").addNewLine()
|
2024-09-26 17:51:01 +08:00
|
|
|
}
|
|
|
|
|
msg.addText("共计${commands.size}条命令")
|
2024-10-30 18:14:26 +08:00
|
|
|
node.addMessageChain(
|
|
|
|
|
MessageChain.Builder().addText("你可以使用`/help <指令>`来获取这个指令的帮助信息").build(),
|
|
|
|
|
configManager.selfId
|
|
|
|
|
)
|
2024-09-28 16:31:55 +08:00
|
|
|
node.addMessageChain(msg.build(), configManager.selfId)
|
2024-09-26 17:51:01 +08:00
|
|
|
message.reply(node.build())
|
|
|
|
|
} else {
|
|
|
|
|
val commandName = args.first().replace("/", "")
|
|
|
|
|
val matchedCommand = commands.find {
|
2024-09-26 18:13:09 +08:00
|
|
|
it.commandNames.map { map -> map.replace("/", "").lowercase() }.contains(commandName)
|
2024-09-26 17:51:01 +08:00
|
|
|
}
|
|
|
|
|
if (matchedCommand == null) {
|
|
|
|
|
message.reply("未查询到该命令")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
val description = matchedCommand::class.findAnnotation<CommandDescription>()?.description ?: "暂无描述"
|
|
|
|
|
val msg = MessageChain.Builder()
|
2024-09-26 21:58:17 +08:00
|
|
|
.addText("类名: ${matchedCommand::class.simpleName}")
|
2024-09-26 05:20:10 +08:00
|
|
|
.addNewLine()
|
2024-09-26 21:58:17 +08:00
|
|
|
.addText("指令: ${matchedCommand.commandNames.joinToString(",")}")
|
2024-09-26 17:51:01 +08:00
|
|
|
.addNewLine()
|
2024-09-26 21:58:17 +08:00
|
|
|
.addText("描述: $description")
|
2024-09-26 17:51:01 +08:00
|
|
|
.build()
|
|
|
|
|
message.reply(msg)
|
2024-09-26 05:20:10 +08:00
|
|
|
}
|
2024-09-03 16:15:26 +08:00
|
|
|
}
|
|
|
|
|
}
|