diff --git a/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt b/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt index 306a72a..30a1614 100644 --- a/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt +++ b/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt @@ -273,6 +273,7 @@ suspend fun main() { WSType.Client -> ROneBotFactory.createClient(configManager.wsAddress, accessToken, fancyBot) WSType.Server -> ROneBotFactory.createServer(configManager.wsPort, accessToken, fancyBot) } + ROneBotFactory.interceptor = CommandInterceptor() instance.addListeningGroups(*configManager.listeningGroups.toLongArray()) initDatabase() initFilesDir() diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/StatusCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/StatusCommand.kt index 2a1e306..63349f5 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/StatusCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/StatusCommand.kt @@ -10,6 +10,7 @@ package cn.rtast.fancybot.commands import cn.rtast.fancybot.START_UP_TIME import cn.rtast.fancybot.annotations.CommandDescription import cn.rtast.fancybot.enums.CommandAction +import cn.rtast.fancybot.util.CommandInterceptor import cn.rtast.fancybot.util.file.insertActionRecord import cn.rtast.rob.entity.GroupMessage import cn.rtast.rob.util.BaseCommand @@ -43,6 +44,8 @@ class StatusCommand : BaseCommand() { .addText("操作系统: $osName / 系统架构: $osArch") .addNewLine() .addText("Java版本: $javaVersion / Kotlin版本: $kotlinVersion") + .addNewLine() + .addText("指令共执行: ${CommandInterceptor.file.readText()} 次") .build() message.reply(msg) insertActionRecord(CommandAction.Status, message.sender.userId) diff --git a/src/main/kotlin/cn/rtast/fancybot/util/CommandInterceptor.kt b/src/main/kotlin/cn/rtast/fancybot/util/CommandInterceptor.kt new file mode 100644 index 0000000..2342686 --- /dev/null +++ b/src/main/kotlin/cn/rtast/fancybot/util/CommandInterceptor.kt @@ -0,0 +1,30 @@ +/* + * Copyright © 2024 RTAkland + * Author: RTAkland + * Date: 2024/11/7 + */ + + +package cn.rtast.fancybot.util + +import cn.rtast.fancybot.ROOT_PATH +import cn.rtast.rob.ROneBotFactory +import cn.rtast.rob.entity.GroupMessage +import cn.rtast.rob.entity.PrivateMessage +import cn.rtast.rob.interceptor.ExecutionInterceptor +import java.io.File + +class CommandInterceptor : ExecutionInterceptor { + + companion object { + val file = File(ROOT_PATH, "/caches/command_execution_count").apply { createNewFile() } + } + + override suspend fun afterGroupExecute(message: GroupMessage) { + file.writeText(ROneBotFactory.totalCommandExecutionTimes.toString()) + } + + override suspend fun afterPrivateExecute(message: PrivateMessage) { + file.writeText(ROneBotFactory.totalCommandExecutionTimes.toString()) + } +} \ No newline at end of file