00ll00 5 سال پیش
والد
کامیت
6685300ce0

+ 1 - 1
src/main/kotlin/bot_luo_core/bot/MultiBotHandler.kt

@@ -125,7 +125,7 @@ object MultiBotHandler {
             if (this.isIntercepted) Logger.log(this, Level.INFO) else Logger.log(this, Level.DEBUG)
         }
         GlobalEventChannel.subscribeAlways<MessagePreSendEvent> {
-            this.cancel()
+            this.cancel()   //TODO 解除张口结舌之术
         }
     }
 

+ 1 - 1
src/main/kotlin/bot_luo_core/data/CmdDataObj.kt

@@ -4,7 +4,7 @@ import bot_luo_core.cli.CmdExecutable
 import kotlinx.atomicfu.AtomicInt
 import kotlinx.atomicfu.atomic
 
-abstract class CmdDataObj(filePath: String): DataObj(filePath) {
+abstract class CmdDataObj(filePath: String): DataObj(filePath, 3000, true) {
 
     private val cmdData: HashMap<String, CmdData> =  getObj("cmdData")?: HashMap()
     private val cmdHandling = HashMap<CmdExecutable, AtomicInt>()

+ 16 - 12
src/main/kotlin/bot_luo_core/data/DataObj.kt

@@ -20,27 +20,25 @@ abstract class DataObj(
     /**
      * JSON数据文件路径
      */
-    private val filePath: String
-): Mutex by Mutex() {
-
-    /**
-     * 使用[getObj]和[setObj]进行访问
-     */
-    val jsonObj: JSONObject
-
+    private val filePath: String,
     /**
      * 自动保存间隔时间(ms)
      *
      * 在访问空闲超过间隔后自动保存
      */
-    abstract val autoSaveInterval: Long
-
+    private val autoSaveInterval: Long,
     /**
      * 是否自动卸载
      *
      * 为`true`时将把读取数据算作访问,且在自动保存后调用[unload]方法
      */
-    abstract val saveAndUnload: Boolean
+    private val saveAndUnload: Boolean
+): Mutex by Mutex() {
+
+    /**
+     * 使用[getObj]和[setObj]进行访问
+     */
+    val jsonObj: JSONObject
 
     private var saveJob: Job? = null
     private val context = Dispatchers.IO
@@ -107,7 +105,7 @@ abstract class DataObj(
             JSON.parseObject(file.readText().ifBlank { "{}" })
         else
             JSONObject(HashMap())
-        launchSaveJob()
+        if (saveAndUnload) launchSaveJob()
     }
 
     /**
@@ -174,6 +172,12 @@ abstract class DataObj(
 
     companion object {
         val saveJobs = ArrayList<Job>()
+
+//        fun saveAll() {
+//            saveJobs.forEach {
+//                it.start()
+//            }
+//        }
     }
 
 }

+ 0 - 2
src/main/kotlin/bot_luo_core/data/Group.kt

@@ -20,8 +20,6 @@ class Group internal constructor(
     override val contactType = BotContactType.Group
     override val defaultData: CmdData
         get() = CmdData(0,0,0,0,false)//群组命令默认关闭
-    override val autoSaveInterval = 30000L
-    override val saveAndUnload = true
 
     val virtual: Boolean = id==0L
 

+ 0 - 2
src/main/kotlin/bot_luo_core/data/User.kt

@@ -29,8 +29,6 @@ class User internal constructor (
 ) : CmdDataObj("data/users/$id.json"), BotContact {
     override val contactType = BotContactType.Single
     override val defaultData: CmdData get() = CmdData(0,0,0,0,true)//用户命令默认开启
-    override val autoSaveInterval = 30000L
-    override val saveAndUnload = true
 
     val virtual: Boolean = id==0L