From dffade2a92f120967497047e4bb13d205cc2cd0b Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Thu, 24 Dec 2020 00:14:17 +0800 Subject: [PATCH] Don't relogin bot when bot logging in --- mirai-core/src/commonMain/kotlin/AbstractBot.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mirai-core/src/commonMain/kotlin/AbstractBot.kt b/mirai-core/src/commonMain/kotlin/AbstractBot.kt index c3916de69..8c8593858 100644 --- a/mirai-core/src/commonMain/kotlin/AbstractBot.kt +++ b/mirai-core/src/commonMain/kotlin/AbstractBot.kt @@ -72,6 +72,8 @@ internal abstract class AbstractBot constructor( @Suppress("PropertyName") internal lateinit var _network: N + internal var _isConnecting: Boolean = false + override val isOnline: Boolean get() = _network.areYouOk() val otherClientsLock = Mutex() // lock sync @@ -99,6 +101,10 @@ internal abstract class AbstractBot constructor( // bot 还未登录就被 close return@subscribeAlways } + if (_isConnecting) { + // bot 还在登入 + return@subscribeAlways + } /* if (network.areYouOk() && event !is BotOfflineEvent.Force && event !is BotOfflineEvent.MsfOffline) { // network 运行正常 @@ -197,6 +203,7 @@ internal abstract class AbstractBot constructor( while (true) { _network = createNetworkHandler(this.coroutineContext) try { + _isConnecting = true @OptIn(ThisApiMustBeUsedInWithConnectionLockBlock::class) relogin(null) return @@ -212,6 +219,8 @@ internal abstract class AbstractBot constructor( } catch (e: Exception) { network.logger.error(e) _network.closeAndJoin(e) + } finally { + _isConnecting = false } logger.warning { "Login failed. Retrying in 3s..." } delay(3000)