From ff2f0b5ae3904d09cee88669fb93bbbdbd9206b4 Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 10 Jan 2020 22:48:45 +0800 Subject: [PATCH] Deprecate `bot.qqAccount` and `bot.account.id` for literal account support --- .../commonMain/kotlin/net.mamoe.mirai/Bot.kt | 6 ++++++ .../kotlin/net.mamoe.mirai/BotAccount.kt | 17 ++++++++++++++++- .../kotlin/net.mamoe.mirai/BotHelper.kt | 4 +++- .../message/internal/MessageDataInternal.kt | 8 ++++---- 4 files changed, 29 insertions(+), 6 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 7efdf7392..0da7a4d41 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt @@ -35,8 +35,14 @@ abstract class Bot : CoroutineScope { /** * 账号信息 */ + @MiraiInternalAPI abstract val account: BotAccount + /** + * QQ 号码. 实际类型为 uint + */ + abstract val uin: Long + /** * 日志记录器 */ diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotAccount.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotAccount.kt index 64c05652c..0546d81f6 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotAccount.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotAccount.kt @@ -3,11 +3,26 @@ package net.mamoe.mirai import kotlinx.io.core.toByteArray +import net.mamoe.mirai.utils.MiraiExperimentalAPI +import net.mamoe.mirai.utils.MiraiInternalAPI import net.mamoe.mirai.utils.md5 +import kotlin.annotation.AnnotationTarget.* data class BotAccount( + /** + * **注意**: 在 Android 协议, 总是使用 `QQAndroidClient.uin`, 而不要使用 [BotAccount.id]. 将来 [BotAccount.id] 可能会变为 [String] + */ + @MiraiExperimentalAPI val id: Long, val passwordMd5: ByteArray // md5 ){ constructor(id: Long, passwordPlainText: String) : this(id, md5(passwordPlainText.toByteArray())) -} \ No newline at end of file +} + +/** + * 标记直接访问 [BotAccount.id], 而不是访问 [Bot.uin] + */ +@Retention(AnnotationRetention.SOURCE) +@Target(CLASS, TYPEALIAS, FUNCTION, PROPERTY, FIELD, CONSTRUCTOR) +@Experimental +annotation class RawAccountIdUse \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotHelper.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotHelper.kt index a537c21c3..c5dca664e 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotHelper.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotHelper.kt @@ -23,4 +23,6 @@ suspend inline fun Bot.alsoLogin(): Bot = also { login() } /** * 取得机器人的 QQ 号 */ -inline val Bot.qqAccount: Long get() = this.account.id \ No newline at end of file +@Deprecated(message = "Use this.uin instead", replaceWith = ReplaceWith("this.uin"), level = DeprecationLevel.WARNING) +inline val Bot.qqAccount: Long + get() = this.uin \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/internal/MessageDataInternal.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/internal/MessageDataInternal.kt index abd83aa9d..aca589b1c 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/internal/MessageDataInternal.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/internal/MessageDataInternal.kt @@ -129,11 +129,11 @@ internal fun IoBuffer.parseMessageImage0x03(): Image { // return if (tlv.containsKey(0x0Au)) { return Image( ImageId0x03( - String(tlv[0x02u]!!).adjustImageId(), + String(tlv[0x02]!!).adjustImageId(), // tlv[0x0Au], - uniqueId = tlv[0x04u]!!.read { readUInt() }, - height = tlv[0x16u]!!.toUInt().toInt(), - width = tlv[0x15u]!!.toUInt().toInt() + uniqueId = tlv[0x04]!!.read { readUInt() }, + height = tlv[0x16]!!.toUInt().toInt(), + width = tlv[0x15]!!.toUInt().toInt() )//.also { debugPrintln("ImageId: $it") } ) //} else {