From 8786f12d5d3c7723c7a5eb481819e225ba0b3e85 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 17 Apr 2021 00:03:56 +0800 Subject: [PATCH] Add NetworkHandler.isOk to avoid `state == OK` --- mirai-core/src/commonMain/kotlin/AbstractBot.kt | 4 ++-- .../src/commonMain/kotlin/network/handler/NetworkHandler.kt | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/AbstractBot.kt b/mirai-core/src/commonMain/kotlin/AbstractBot.kt index 38aa77a28..3298eee55 100644 --- a/mirai-core/src/commonMain/kotlin/AbstractBot.kt +++ b/mirai-core/src/commonMain/kotlin/AbstractBot.kt @@ -73,7 +73,7 @@ internal abstract class AbstractBot constructor( // 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 = GlobalEventChannel.filterIsInstance().filter { it.bot === this@AbstractBot } @@ -144,7 +144,7 @@ internal abstract class AbstractBot constructor( } if (event.reconnect) { - if (network.state != NetworkHandler.State.OK) { + if (!network.isOk()) { // normally closed return@subscribeAlways } diff --git a/mirai-core/src/commonMain/kotlin/network/handler/NetworkHandler.kt b/mirai-core/src/commonMain/kotlin/network/handler/NetworkHandler.kt index 9fc1bbeb1..996927c33 100644 --- a/mirai-core/src/commonMain/kotlin/network/handler/NetworkHandler.kt +++ b/mirai-core/src/commonMain/kotlin/network/handler/NetworkHandler.kt @@ -47,6 +47,8 @@ internal class NetworkHandlerContextImpl( internal interface NetworkHandler { val context: NetworkHandlerContext + fun isOk() = state == State.OK + /** * State of this handler. */