feat: add annotation to add command description

This commit is contained in:
2024-09-26 05:20:10 +08:00
parent 0a28d05bfe
commit 8dc311fb90
41 files changed
+135 -33

No files matched your search

@@ -7,27 +7,31 @@
package cn.rtast.fancybot.commands
import cn.rtast.fancybot.annotations.CommandDescription
import cn.rtast.fancybot.commands
import cn.rtast.rob.entity.GroupMessage
import cn.rtast.rob.util.BaseCommand
import cn.rtast.rob.util.ob.MessageChain
import cn.rtast.rob.util.ob.OneBotListener
@CommandDescription("AAAA")
class HelpCommand : BaseCommand() {
override val commandNames = listOf("/help", "/帮助")
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
val allCommands = commands.sortedBy { it::class.simpleName }.joinToString("\n") {
"[${
it.javaClass.name.split(".")
.last().replace("Command", "")
}] 命令:${it.commandNames.joinToString(",")}"
}
val msg = MessageChain.Builder()
.addAt(message.sender.userId)
.addNewLine()
.addText(allCommands)
.build()
listener.sendGroupMessage(message.groupId, msg)
commands.sortedBy { it::class.simpleName }.forEach {
val description =
if (!it.javaClass.isAnnotationPresent(CommandDescription::class.java)) {
"暂无描述"
} else {
it.javaClass.getAnnotation(CommandDescription::class.java)?.description!!
}
val commandName = it::class.simpleName?.replace("Command", "")!!
val commandNames = it.commandNames.joinToString(",")
msg.addText("[$commandName] [$description] 命令: $commandNames")
.addNewLine()
}
message.reply(msg.build())
}
}