mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-18 10:22:26 +08:00
Don't relogin bot when bot logging in
This commit is contained in:
parent
7446453e8e
commit
dffade2a92
@ -72,6 +72,8 @@ internal abstract class AbstractBot<N : BotNetworkHandler> 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<N : BotNetworkHandler> 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<N : BotNetworkHandler> constructor(
|
||||
while (true) {
|
||||
_network = createNetworkHandler(this.coroutineContext)
|
||||
try {
|
||||
_isConnecting = true
|
||||
@OptIn(ThisApiMustBeUsedInWithConnectionLockBlock::class)
|
||||
relogin(null)
|
||||
return
|
||||
@ -212,6 +219,8 @@ internal abstract class AbstractBot<N : BotNetworkHandler> constructor(
|
||||
} catch (e: Exception) {
|
||||
network.logger.error(e)
|
||||
_network.closeAndJoin(e)
|
||||
} finally {
|
||||
_isConnecting = false
|
||||
}
|
||||
logger.warning { "Login failed. Retrying in 3s..." }
|
||||
delay(3000)
|
||||
|
Loading…
Reference in New Issue
Block a user