Commit 6dca4419 authored by Him188's avatar Him188

Add platform details

parent 770b137a
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
......@@ -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) {
......
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
......@@ -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 : Event> 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 ->
......
......@@ -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) {
......
......@@ -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
......
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment