diff --git a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/MiraiEnvironment.kt b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/MiraiEnvironment.kt index ffc9c1147..d69de63b4 100644 --- a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/MiraiEnvironment.kt +++ b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/MiraiEnvironment.kt @@ -1,3 +1,5 @@ package net.mamoe.mirai -actual object MiraiEnvironment \ No newline at end of file +actual object MiraiEnvironment { + actual val platform: Platform get() = Platform.ANDROID +} \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt index 84005160f..91e702f8d 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt @@ -74,7 +74,7 @@ class Bot(val account: BotAccount, val logger: MiraiLogger) { configuration: BotNetworkConfiguration, cause: Throwable? = null ): LoginResult { - logger.warning("Reinitializing BotNetworkHandler") + logger.info("Initializing BotNetworkHandler") try { network.close(cause) } catch (e: Exception) { diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/MiraiEnvironment.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/MiraiEnvironment.kt index 48de9a22e..d691f0728 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/MiraiEnvironment.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/MiraiEnvironment.kt @@ -1,3 +1,10 @@ package net.mamoe.mirai -expect object MiraiEnvironment \ No newline at end of file +expect object MiraiEnvironment { + val platform: Platform +} + +enum class Platform { + ANDROID, + JVM +} \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Event.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Event.kt index b71b54e85..2dd85f7ba 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Event.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Event.kt @@ -3,9 +3,7 @@ package net.mamoe.mirai.event import kotlinx.coroutines.* -import net.mamoe.mirai.contact.Contact import net.mamoe.mirai.event.internal.broadcastInternal -import net.mamoe.mirai.network.BotNetworkHandler import net.mamoe.mirai.utils.DefaultLogger import net.mamoe.mirai.utils.MiraiLogger import kotlin.coroutines.CoroutineContext @@ -31,7 +29,7 @@ abstract class Event { } else throw UnsupportedOperationException() /** - * 取消事件. 事件需实现 [Cancellable] 才可以被取消, 否则调用这个方法将会得到 [UnsupportedOperationException] + * 取消事件. 事件需实现 [Cancellable] 才可以被取消 * * @throws UnsupportedOperationException 如果事件没有实现 [Cancellable] */ @@ -48,7 +46,7 @@ abstract class Event { internal object EventLogger : MiraiLogger by DefaultLogger("Event") -val EventDebuggingFlag: Boolean by lazy { +private val EventDebuggingFlag: Boolean by lazy { false } @@ -83,20 +81,8 @@ suspend fun E.broadcast(context: CoroutineContext = EmptyCoroutineCo } } -/** - * 事件协程调度器. - * - * JVM: 共享 [Dispatchers.Default] - */ internal expect val EventDispatcher: CoroutineDispatcher -/** - * 事件协程作用域. - * 所有的事件 [broadcast] 过程均在此作用域下运行. - * - * 然而, 若在事件处理过程中使用到 [Contact.sendMessage] 等会 [发送数据包][BotNetworkHandler.sendPacket] 的方法, - * 发送过程将会通过 [withContext] 将协程切换到 [BotNetworkHandler] 作用域下执行. - */ object EventScope : CoroutineScope { override val coroutineContext: CoroutineContext = EventDispatcher + CoroutineExceptionHandler { _, e -> diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt index f98a7ae78..de90ea5fb 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt @@ -329,7 +329,7 @@ internal class TIMBotNetworkHandler internal constructor(override val bot: Bot) else -> { error("No decrypter found") } - } as D + } as? D ?: error("Internal error: could not cast decrypter found for factory to class Decrypter") suspend fun onPacketReceived(packet: Any) {//complex function, but it doesn't matter when (packet) { diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/Packet.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/Packet.kt index 9d12da1d3..902cf6f0b 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/Packet.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/Packet.kt @@ -158,6 +158,8 @@ enum class KnownPacketId(override inline val value: UShort, override inline val override fun toString(): String = factory.let { it::class.simpleName } ?: this.name } +// endregion + object IgnoredPacket : Packet sealed class EventPacket { @@ -195,7 +197,7 @@ sealed class EventPacket { ) : Packet @CorrespondingEvent(GroupMessageEvent::class) - class GroupMessage : Packet { + class GroupMessage : Packet { // TODO: 2019/11/6 改为 data class var groupNumber: UInt = 0u internal set var qq: UInt = 0u @@ -231,7 +233,6 @@ object UnknownPacket : Packet { */ object NoPacket : Packet -// endregion // region Internal utils diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/MiraiEnvironmentJvm.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/MiraiEnvironmentJvm.kt index 39e3e4681..48a351e49 100644 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/MiraiEnvironmentJvm.kt +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/MiraiEnvironmentJvm.kt @@ -2,6 +2,6 @@ package net.mamoe.mirai -actual typealias MiraiEnvironment = MiraiEnvironmentJvm - -object MiraiEnvironmentJvm \ No newline at end of file +actual object MiraiEnvironment { + actual val platform: Platform get() = Platform.JVM +} \ No newline at end of file