From 192594896e6a99fcd4ec1948558632c2a2c127cb Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 17 Jan 2020 11:51:31 +0800 Subject: [PATCH] Cleanup --- .../src/commonMain/kotlin/net.mamoe.mirai/Bot.kt | 3 +++ .../commonMain/kotlin/net.mamoe.mirai/contact/QQ.kt | 2 +- .../kotlin/net.mamoe.mirai/utils/cryptor/Proto.kt | 11 +++-------- 3 files changed, 7 insertions(+), 9 deletions(-) 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 6c147d261..df3f87b19 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt @@ -126,6 +126,9 @@ abstract class Bot : CoroutineScope { // endregion + /** + * 关闭这个 [Bot], 停止一切相关活动. 不可重新登录. + */ abstract fun dispose(throwable: Throwable?) // region extensions diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/QQ.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/QQ.kt index 918a787e7..c7dfcfe23 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/QQ.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/QQ.kt @@ -11,7 +11,7 @@ import net.mamoe.mirai.data.Profile /** * QQ 对象. * 注意: 一个 [QQ] 实例并不是独立的, 它属于一个 [Bot]. - * 它不能被直接构造. 任何时候都应从 [Bot.qq], [Bot.ContactSystem.getQQ], [BotSession.qq] 或事件中获取. + * 它不能被直接构造. 任何时候都应从 [Bot.getQQ] 或事件中获取. * * 对于同一个 [Bot] 任何一个人的 [QQ] 实例都是单一的. * diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/cryptor/Proto.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/cryptor/Proto.kt index 98a5926c7..afaf7279f 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/cryptor/Proto.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/cryptor/Proto.kt @@ -184,6 +184,7 @@ fun Any?.contentToString(prefix: String = ""): String = when (this) { expect fun Any.contentToStringReflectively(prefix: String = ""): String +@Suppress("UNCHECKED_CAST") fun ByteReadPacket.readProtoMap(length: Long = this.remaining): ProtoMap { val map = ProtoMap(mutableMapOf()) @@ -206,14 +207,8 @@ fun ByteReadPacket.readProtoMap(length: Long = this.remaining): ProtoMap { } if (map.containsKey(id)) { - if (map[id] is MutableList<*>) { - @Suppress("UNCHECKED_CAST") - (map[id] as MutableList) += readValue() - } else { - map[id] = mutableListOf(map[id]!!) - @Suppress("UNCHECKED_CAST") - (map[id] as MutableList) += readValue() - } + if (map[id] !is MutableList<*>) map[id] = mutableListOf(map[id]!!) + (map[id] as MutableList) += readValue() } else { map[id] = readValue() }