00ll00 5 лет назад
Родитель
Сommit
57ccdbd1ed

+ 22 - 0
src/main/kotlin/bot_luo_core/cli/checkers/addon/GlobalCDChecker.kt

@@ -0,0 +1,22 @@
+package bot_luo_core.cli.checkers.addon
+
+import bot_luo_core.cli.Checker
+import bot_luo_core.cli.CmdContext
+import bot_luo_core.cli.CmdExecutable
+import bot_luo_core.data.Cmds
+import bot_luo_core.util.Time
+import net.mamoe.mirai.message.data.toPlainText
+
+class GlobalCDChecker: Checker {
+
+    override val name = "命令冷却检定器"
+
+    override fun check(cmd: CmdExecutable, context: CmdContext) { with(context) {
+        val cd = Cmds.getObj<Long>("${cmd.id}_CD") ?: 0
+        val wait = cd + Cmds[cmd].lastTime - time
+        if (cd > 0 && wait > 0) throw CheckerFatal(
+            "等${Time.formatSpanE(wait)}吧,命令全局冷却中".toPlainText(),
+            "命令全局冷却中"
+        )
+    } }
+}

+ 1 - 1
src/main/kotlin/bot_luo_core/cli/commands/DebugCmd.kt

@@ -21,7 +21,7 @@ class DebugCmd(context: CmdContext) : Cmd(context) {
     @Suppress("UNCHECKED_CAST")
     @Method(name = "", alias = ["show"], pmsLevel = CmdPermissionLevel.DEBUG)
     fun show (): CmdReceipt {
-        val table = TableBuilder(4)
+        val table = TableBuilder(2)
         table.th("调试信息 ——").br()
         table.tr("ST:").td( BotLuo.startAt relativeTo context.time)
         table.tr("MEM:").td(formatMem(Runtime.getRuntime().totalMemory()))

+ 1 - 1
src/main/kotlin/bot_luo_core/util/Text.kt

@@ -37,7 +37,7 @@ object Text {
     }
 
     fun String.firstNotWhitespace(max: Int = this.length): Char? {
-        for (i in 0 until maxOf(max, length)) {
+        for (i in 0 until minOf(max, length)) {
             if (!Character.isWhitespace(this[i])) return this[i]
         }
         return null