Deprecate bot.qqAccount and bot.account.id for literal account support

This commit is contained in:
Him188 2020-01-10 22:48:45 +08:00
parent 748581b14f
commit ff2f0b5ae3
4 changed files with 29 additions and 6 deletions

View File

@ -35,8 +35,14 @@ abstract class Bot : CoroutineScope {
/**
* 账号信息
*/
@MiraiInternalAPI
abstract val account: BotAccount
/**
* QQ 号码. 实际类型为 uint
*/
abstract val uin: Long
/**
* 日志记录器
*/

View File

@ -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()))
}
}
/**
* 标记直接访问 [BotAccount.id], 而不是访问 [Bot.uin]
*/
@Retention(AnnotationRetention.SOURCE)
@Target(CLASS, TYPEALIAS, FUNCTION, PROPERTY, FIELD, CONSTRUCTOR)
@Experimental
annotation class RawAccountIdUse

View File

@ -23,4 +23,6 @@ suspend inline fun Bot.alsoLogin(): Bot = also { login() }
/**
* 取得机器人的 QQ
*/
inline val Bot.qqAccount: Long get() = this.account.id
@Deprecated(message = "Use this.uin instead", replaceWith = ReplaceWith("this.uin"), level = DeprecationLevel.WARNING)
inline val Bot.qqAccount: Long
get() = this.uin

View File

@ -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 {