Add NetworkHandler.isOk to avoid state == OK

This commit is contained in:
Him188 2021-04-17 00:03:56 +08:00
parent 4446479e80
commit 8786f12d5d
2 changed files with 4 additions and 2 deletions

View File

@ -73,7 +73,7 @@ internal abstract class AbstractBot constructor(
// overrides // overrides
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
final override val isOnline: Boolean get() = network.state == NetworkHandler.State.OK final override val isOnline: Boolean get() = network.isOk()
final override val eventChannel: EventChannel<BotEvent> = final override val eventChannel: EventChannel<BotEvent> =
GlobalEventChannel.filterIsInstance<BotEvent>().filter { it.bot === this@AbstractBot } GlobalEventChannel.filterIsInstance<BotEvent>().filter { it.bot === this@AbstractBot }
@ -144,7 +144,7 @@ internal abstract class AbstractBot constructor(
} }
if (event.reconnect) { if (event.reconnect) {
if (network.state != NetworkHandler.State.OK) { if (!network.isOk()) {
// normally closed // normally closed
return@subscribeAlways return@subscribeAlways
} }

View File

@ -47,6 +47,8 @@ internal class NetworkHandlerContextImpl(
internal interface NetworkHandler { internal interface NetworkHandler {
val context: NetworkHandlerContext val context: NetworkHandlerContext
fun isOk() = state == State.OK
/** /**
* State of this handler. * State of this handler.
*/ */