Files
FancyBot/src/main/kotlin/cn/rtast/fancybot/commands/HelpCommand.kt
T

39 lines
1.4 KiB
Kotlin
Raw Normal View History

2024-09-03 16:15:26 +08:00
/*
* Copyright © 2024 RTAkland
* Author: RTAkland
* Date: 2024/9/3
*/
package cn.rtast.fancybot.commands
import cn.rtast.fancybot.annotations.CommandDescription
2024-09-03 16:15:26 +08:00
import cn.rtast.fancybot.commands
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
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", "/帮助")
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
2024-09-26 14:01:26 +08:00
val node = NodeMessageChain.Builder()
2024-09-03 16:15:26 +08:00
val msg = MessageChain.Builder()
commands.sortedBy { it::class.simpleName }.forEach {
2024-09-26 05:44:47 +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(",")
msg.addText("[$commandName] [$description] 命令: $commandNames")
.addNewLine()
}
2024-09-26 14:01:26 +08:00
msg.addText("共计${commands.size}条命令")
node.addMessageChain(msg.build(), message.sender.userId)
message.reply(node.build())
2024-09-03 16:15:26 +08:00
}
}