Ver Fonte

exceptions can be muted in group

00ll00 há 5 anos atrás
pai
commit
876a4a4718

+ 11 - 5
src/main/kotlin/bot_luo_core/cli/CmdHandler.kt

@@ -21,6 +21,7 @@ import net.mamoe.mirai.message.data.isContentEmpty
 import net.mamoe.mirai.message.data.toPlainText
 import java.lang.reflect.InvocationTargetException
 import kotlin.jvm.Throws
+import kotlin.reflect.full.allSuperclasses
 import kotlin.reflect.full.createInstance
 
 object CmdHandler {
@@ -64,12 +65,17 @@ object CmdHandler {
             withAccessing(context.user, context.group) {
                 execute(context)
             }
-        } catch (e: CliException) {
-            if (!e.output.isContentEmpty()) {
-                context.sendOutputWithLog(At(context.user.id) + e.output)
-            }
         } catch (e: Exception) {
-            context.sendOutputWithLog("发生异常:${e::class.simpleName}".toPlainText())
+            when {
+                e::class.simpleName in context.groupF.mutedExceptions ||
+                        e::class.allSuperclasses.any { it.simpleName in context.groupF.mutedExceptions } -> {}
+                e is CheckerFatal && e.checker.simpleName in context.groupF.mutedCheckers -> {}
+                e is CliException && !e.output.isContentEmpty() -> {
+                    context.sendOutputWithLog(At(context.user.id) + e.output)
+                }
+                else -> context.sendOutputWithLog("发生异常:${e::class.simpleName}".toPlainText())
+            }
+            return
         }
         when (context.uploadOutputFile) {
             0 -> {

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

@@ -33,6 +33,14 @@ class Group internal constructor(
         get() = PmsGroups.getPmsGroup(getObj("pmsGroup")?: "NONE")
         set(value) = setObj("pmsGroup", value.name)
 
+    var mutedExceptions: ArrayList<String>
+        get() = getObj("mutedExceptions")?: ArrayList()
+        set(value) = setObj("mutedExceptions", value)
+
+    var mutedCheckers: ArrayList<String>
+        get() = getObj("mutedCheckers")?: ArrayList()
+        set(value) = setObj("mutedCheckers", value)
+
     inline fun withServeBot(pms: MemberPermission = MemberPermission.MEMBER, action: (contact: Group)->Unit): Boolean {
         if (virtual) return false
         val contact = if (bot == null) BotLuo.getContactableBots(this).map { it.getGroup(id) }.filter { it != null && it.botPermission >= pms }.randomOrNull()