mirror of
https://github.com/LamGC/ScalaBot.git
synced 2025-04-30 06:37:29 +00:00
refactor(launch): 增强关闭阶段的鲁棒性.
增加异常捕获, 防止由于部分 bot 发生异常而无法关闭其余机器人.
This commit is contained in:
parent
4210efef3b
commit
9cdf10ccc2
@ -146,9 +146,16 @@ internal class Launcher : AutoCloseable {
|
|||||||
@Synchronized
|
@Synchronized
|
||||||
override fun close() {
|
override fun close() {
|
||||||
botSessionMap.forEach {
|
botSessionMap.forEach {
|
||||||
|
try {
|
||||||
|
if (!it.value.isRunning) {
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
log.info { "正在关闭机器人 `${it.key.botUsername}` ..." }
|
log.info { "正在关闭机器人 `${it.key.botUsername}` ..." }
|
||||||
it.value.stop()
|
it.value.stop()
|
||||||
log.info { "已关闭机器人 `${it.key.botUsername}`." }
|
log.info { "已关闭机器人 `${it.key.botUsername}`." }
|
||||||
|
} catch (e: Exception) {
|
||||||
|
log.error(e) { "机器人 `${it.key.botUsername}` 关闭时发生异常." }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user