feat: add command execution times counter

This commit is contained in:
2024-11-07 17:07:05 +08:00
parent 5320836d26
commit 42c215420a
3 files changed
+34

No files matched your search

@@ -273,6 +273,7 @@ suspend fun main() {
WSType.Client -> ROneBotFactory.createClient(configManager.wsAddress, accessToken, fancyBot) WSType.Client -> ROneBotFactory.createClient(configManager.wsAddress, accessToken, fancyBot)
WSType.Server -> ROneBotFactory.createServer(configManager.wsPort, accessToken, fancyBot) WSType.Server -> ROneBotFactory.createServer(configManager.wsPort, accessToken, fancyBot)
} }
ROneBotFactory.interceptor = CommandInterceptor()
instance.addListeningGroups(*configManager.listeningGroups.toLongArray()) instance.addListeningGroups(*configManager.listeningGroups.toLongArray())
initDatabase() initDatabase()
initFilesDir() initFilesDir()
@@ -10,6 +10,7 @@ package cn.rtast.fancybot.commands
import cn.rtast.fancybot.START_UP_TIME import cn.rtast.fancybot.START_UP_TIME
import cn.rtast.fancybot.annotations.CommandDescription import cn.rtast.fancybot.annotations.CommandDescription
import cn.rtast.fancybot.enums.CommandAction import cn.rtast.fancybot.enums.CommandAction
import cn.rtast.fancybot.util.CommandInterceptor
import cn.rtast.fancybot.util.file.insertActionRecord import cn.rtast.fancybot.util.file.insertActionRecord
import cn.rtast.rob.entity.GroupMessage import cn.rtast.rob.entity.GroupMessage
import cn.rtast.rob.util.BaseCommand import cn.rtast.rob.util.BaseCommand
@@ -43,6 +44,8 @@ class StatusCommand : BaseCommand() {
.addText("操作系统: $osName / 系统架构: $osArch") .addText("操作系统: $osName / 系统架构: $osArch")
.addNewLine() .addNewLine()
.addText("Java版本: $javaVersion / Kotlin版本: $kotlinVersion") .addText("Java版本: $javaVersion / Kotlin版本: $kotlinVersion")
.addNewLine()
.addText("指令共执行: ${CommandInterceptor.file.readText()}")
.build() .build()
message.reply(msg) message.reply(msg)
insertActionRecord(CommandAction.Status, message.sender.userId) insertActionRecord(CommandAction.Status, message.sender.userId)
@@ -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())
}
}