From 9cdf10ccc26138d6c9b6b5a47921c24ce03ba8f1 Mon Sep 17 00:00:00 2001 From: LamGC Date: Sun, 10 Apr 2022 16:27:20 +0800 Subject: [PATCH] =?UTF-8?q?refactor(launch):=20=E5=A2=9E=E5=BC=BA=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E9=98=B6=E6=AE=B5=E7=9A=84=E9=B2=81=E6=A3=92=E6=80=A7?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加异常捕获, 防止由于部分 bot 发生异常而无法关闭其余机器人. --- scalabot-app/src/main/kotlin/AppMain.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scalabot-app/src/main/kotlin/AppMain.kt b/scalabot-app/src/main/kotlin/AppMain.kt index fdbb954..8033e42 100644 --- a/scalabot-app/src/main/kotlin/AppMain.kt +++ b/scalabot-app/src/main/kotlin/AppMain.kt @@ -146,9 +146,16 @@ internal class Launcher : AutoCloseable { @Synchronized override fun close() { botSessionMap.forEach { - log.info { "正在关闭机器人 `${it.key.botUsername}` ..." } - it.value.stop() - log.info { "已关闭机器人 `${it.key.botUsername}`." } + try { + if (!it.value.isRunning) { + return@forEach + } + log.info { "正在关闭机器人 `${it.key.botUsername}` ..." } + it.value.stop() + log.info { "已关闭机器人 `${it.key.botUsername}`." } + } catch (e: Exception) { + log.error(e) { "机器人 `${it.key.botUsername}` 关闭时发生异常." } + } } }