Don't relogin bot when bot logging in

This commit is contained in:
Karlatemp 2020-12-24 00:14:17 +08:00
parent 7446453e8e
commit dffade2a92
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8

View File

@ -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)