mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-03 18:13:48 +08:00
Add platform details
This commit is contained in:
parent
770b137a13
commit
6dca4419a4
@ -1,3 +1,5 @@
|
|||||||
package net.mamoe.mirai
|
package net.mamoe.mirai
|
||||||
|
|
||||||
actual object MiraiEnvironment
|
actual object MiraiEnvironment {
|
||||||
|
actual val platform: Platform get() = Platform.ANDROID
|
||||||
|
}
|
@ -74,7 +74,7 @@ class Bot(val account: BotAccount, val logger: MiraiLogger) {
|
|||||||
configuration: BotNetworkConfiguration,
|
configuration: BotNetworkConfiguration,
|
||||||
cause: Throwable? = null
|
cause: Throwable? = null
|
||||||
): LoginResult {
|
): LoginResult {
|
||||||
logger.warning("Reinitializing BotNetworkHandler")
|
logger.info("Initializing BotNetworkHandler")
|
||||||
try {
|
try {
|
||||||
network.close(cause)
|
network.close(cause)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
package net.mamoe.mirai
|
package net.mamoe.mirai
|
||||||
|
|
||||||
expect object MiraiEnvironment
|
expect object MiraiEnvironment {
|
||||||
|
val platform: Platform
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class Platform {
|
||||||
|
ANDROID,
|
||||||
|
JVM
|
||||||
|
}
|
@ -3,9 +3,7 @@
|
|||||||
package net.mamoe.mirai.event
|
package net.mamoe.mirai.event
|
||||||
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import net.mamoe.mirai.contact.Contact
|
|
||||||
import net.mamoe.mirai.event.internal.broadcastInternal
|
import net.mamoe.mirai.event.internal.broadcastInternal
|
||||||
import net.mamoe.mirai.network.BotNetworkHandler
|
|
||||||
import net.mamoe.mirai.utils.DefaultLogger
|
import net.mamoe.mirai.utils.DefaultLogger
|
||||||
import net.mamoe.mirai.utils.MiraiLogger
|
import net.mamoe.mirai.utils.MiraiLogger
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
@ -31,7 +29,7 @@ abstract class Event {
|
|||||||
} else throw UnsupportedOperationException()
|
} else throw UnsupportedOperationException()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取消事件. 事件需实现 [Cancellable] 才可以被取消, 否则调用这个方法将会得到 [UnsupportedOperationException]
|
* 取消事件. 事件需实现 [Cancellable] 才可以被取消
|
||||||
*
|
*
|
||||||
* @throws UnsupportedOperationException 如果事件没有实现 [Cancellable]
|
* @throws UnsupportedOperationException 如果事件没有实现 [Cancellable]
|
||||||
*/
|
*/
|
||||||
@ -48,7 +46,7 @@ abstract class Event {
|
|||||||
|
|
||||||
internal object EventLogger : MiraiLogger by DefaultLogger("Event")
|
internal object EventLogger : MiraiLogger by DefaultLogger("Event")
|
||||||
|
|
||||||
val EventDebuggingFlag: Boolean by lazy {
|
private val EventDebuggingFlag: Boolean by lazy {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,20 +81,8 @@ suspend fun <E : Event> E.broadcast(context: CoroutineContext = EmptyCoroutineCo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 事件协程调度器.
|
|
||||||
*
|
|
||||||
* JVM: 共享 [Dispatchers.Default]
|
|
||||||
*/
|
|
||||||
internal expect val EventDispatcher: CoroutineDispatcher
|
internal expect val EventDispatcher: CoroutineDispatcher
|
||||||
|
|
||||||
/**
|
|
||||||
* 事件协程作用域.
|
|
||||||
* 所有的事件 [broadcast] 过程均在此作用域下运行.
|
|
||||||
*
|
|
||||||
* 然而, 若在事件处理过程中使用到 [Contact.sendMessage] 等会 [发送数据包][BotNetworkHandler.sendPacket] 的方法,
|
|
||||||
* 发送过程将会通过 [withContext] 将协程切换到 [BotNetworkHandler] 作用域下执行.
|
|
||||||
*/
|
|
||||||
object EventScope : CoroutineScope {
|
object EventScope : CoroutineScope {
|
||||||
override val coroutineContext: CoroutineContext =
|
override val coroutineContext: CoroutineContext =
|
||||||
EventDispatcher + CoroutineExceptionHandler { _, e ->
|
EventDispatcher + CoroutineExceptionHandler { _, e ->
|
||||||
|
@ -329,7 +329,7 @@ internal class TIMBotNetworkHandler internal constructor(override val bot: Bot)
|
|||||||
else -> {
|
else -> {
|
||||||
error("No decrypter found")
|
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
|
suspend fun onPacketReceived(packet: Any) {//complex function, but it doesn't matter
|
||||||
when (packet) {
|
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
|
override fun toString(): String = factory.let { it::class.simpleName } ?: this.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// endregion
|
||||||
|
|
||||||
object IgnoredPacket : Packet
|
object IgnoredPacket : Packet
|
||||||
|
|
||||||
sealed class EventPacket {
|
sealed class EventPacket {
|
||||||
@ -195,7 +197,7 @@ sealed class EventPacket {
|
|||||||
) : Packet
|
) : Packet
|
||||||
|
|
||||||
@CorrespondingEvent(GroupMessageEvent::class)
|
@CorrespondingEvent(GroupMessageEvent::class)
|
||||||
class GroupMessage : Packet {
|
class GroupMessage : Packet { // TODO: 2019/11/6 改为 data class
|
||||||
var groupNumber: UInt = 0u
|
var groupNumber: UInt = 0u
|
||||||
internal set
|
internal set
|
||||||
var qq: UInt = 0u
|
var qq: UInt = 0u
|
||||||
@ -231,7 +233,6 @@ object UnknownPacket : Packet {
|
|||||||
*/
|
*/
|
||||||
object NoPacket : Packet
|
object NoPacket : Packet
|
||||||
|
|
||||||
// endregion
|
|
||||||
|
|
||||||
// region Internal utils
|
// region Internal utils
|
||||||
|
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai
|
package net.mamoe.mirai
|
||||||
|
|
||||||
actual typealias MiraiEnvironment = MiraiEnvironmentJvm
|
actual object MiraiEnvironment {
|
||||||
|
actual val platform: Platform get() = Platform.JVM
|
||||||
object MiraiEnvironmentJvm
|
}
|
Loading…
Reference in New Issue
Block a user