Commit 37735489 authored by Him188's avatar Him188

Replace use of `Bot.uin` with `Bot.id`

parent d5868ed7
...@@ -7,10 +7,11 @@ ...@@ -7,10 +7,11 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE * https://github.com/mamoe/mirai/blob/master/LICENSE
*/ */
@file:Suppress("DEPRECATION_ERROR")
package net.mamoe.mirai.qqandroid package net.mamoe.mirai.qqandroid
import net.mamoe.mirai.Bot import net.mamoe.mirai.Bot
import net.mamoe.mirai.BotAccount
import net.mamoe.mirai.BotFactory import net.mamoe.mirai.BotFactory
import net.mamoe.mirai.utils.BotConfiguration import net.mamoe.mirai.utils.BotConfiguration
import net.mamoe.mirai.utils.Context import net.mamoe.mirai.utils.Context
......
...@@ -16,22 +16,11 @@ import io.ktor.utils.io.core.readBytes ...@@ -16,22 +16,11 @@ import io.ktor.utils.io.core.readBytes
import kotlinx.coroutines.io.* import kotlinx.coroutines.io.*
import kotlinx.io.core.* import kotlinx.io.core.*
import kotlinx.io.pool.useInstance import kotlinx.io.pool.useInstance
import net.mamoe.mirai.BotAccount
import net.mamoe.mirai.qqandroid.utils.ByteArrayPool import net.mamoe.mirai.qqandroid.utils.ByteArrayPool
import net.mamoe.mirai.qqandroid.utils.toReadPacket import net.mamoe.mirai.qqandroid.utils.toReadPacket
import net.mamoe.mirai.utils.BotConfiguration
import net.mamoe.mirai.utils.Context
import net.mamoe.mirai.utils.MiraiInternalAPI import net.mamoe.mirai.utils.MiraiInternalAPI
import java.nio.ByteBuffer import java.nio.ByteBuffer
@OptIn(MiraiInternalAPI::class)
internal actual class QQAndroidBot
actual constructor(
context: Context,
account: BotAccount,
configuration: BotConfiguration
) : QQAndroidBotBase(context, account, configuration)
@OptIn(MiraiInternalAPI::class) @OptIn(MiraiInternalAPI::class)
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
internal actual fun ByteReadChannel.toKotlinByteReadChannel(): kotlinx.coroutines.io.ByteReadChannel { internal actual fun ByteReadChannel.toKotlinByteReadChannel(): kotlinx.coroutines.io.ByteReadChannel {
......
...@@ -7,29 +7,27 @@ ...@@ -7,29 +7,27 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE * https://github.com/mamoe/mirai/blob/master/LICENSE
*/ */
@file:Suppress("EXPERIMENTAL_API_USAGE") @file:Suppress("EXPERIMENTAL_API_USAGE", "DEPRECATION_ERROR")
package net.mamoe.mirai package net.mamoe.mirai.qqandroid
import kotlinx.io.core.toByteArray import kotlinx.io.core.toByteArray
import net.mamoe.mirai.qqandroid.utils.MiraiPlatformUtils
import net.mamoe.mirai.utils.MiraiExperimentalAPI import net.mamoe.mirai.utils.MiraiExperimentalAPI
import net.mamoe.mirai.utils.MiraiInternalAPI import net.mamoe.mirai.utils.MiraiInternalAPI
import net.mamoe.mirai.utils.internal.md5 import kotlin.jvm.JvmSynthetic
import kotlin.annotation.AnnotationTarget.*
internal data class BotAccount(
@MiraiInternalAPI @JvmSynthetic
data class BotAccount( internal val id: Long,
/** @JvmSynthetic
* **注意**: 在 Android 协议, 总是使用 `QQAndroidClient.uin` 或 [Bot.uin], 而不要使用 [BotAccount.id]. 将来 [BotAccount.id] 可能会变为 [String]
*/
@RawAccountIdUse
val id: Long,
@MiraiExperimentalAPI @MiraiExperimentalAPI
@MiraiInternalAPI @MiraiInternalAPI
val passwordMd5: ByteArray // md5 val passwordMd5: ByteArray // md5
) { ) {
constructor(id: Long, passwordPlainText: String) : this(id, passwordPlainText.toByteArray().md5()) constructor(id: Long, passwordPlainText: String) : this(id, MiraiPlatformUtils.md5(passwordPlainText.toByteArray()))
@OptIn(MiraiInternalAPI::class)
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (other == null || this::class != other::class) return false if (other == null || this::class != other::class) return false
...@@ -42,18 +40,10 @@ data class BotAccount( ...@@ -42,18 +40,10 @@ data class BotAccount(
return true return true
} }
@OptIn(MiraiInternalAPI::class)
override fun hashCode(): Int { override fun hashCode(): Int {
var result = id.hashCode() var result = id.hashCode()
result = 31 * result + passwordMd5.contentHashCode() result = 31 * result + passwordMd5.contentHashCode()
return result return result
} }
} }
\ No newline at end of file
/**
* 标记直接访问 [BotAccount.id], 而不是访问 [Bot.uin]. 这可能会不兼容未来的 API 修改.
*/
@MiraiInternalAPI
@Retention(AnnotationRetention.SOURCE)
@Target(CLASS, TYPEALIAS, FUNCTION, PROPERTY, FIELD, CONSTRUCTOR)
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
annotation class RawAccountIdUse
\ No newline at end of file
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
* *
* https://github.com/mamoe/mirai/blob/master/LICENSE * https://github.com/mamoe/mirai/blob/master/LICENSE
*/ */
@file:Suppress(
"FunctionName", "INAPPLICABLE_JVM_NAME", "DEPRECATION_ERROR", "DeprecatedCallableAddReplaceWith",
"OverridingDeprecatedMember"
)
package net.mamoe.mirai.qqandroid package net.mamoe.mirai.qqandroid
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE * https://github.com/mamoe/mirai/blob/master/LICENSE
*/ */
@file:Suppress("EXPERIMENTAL_API_USAGE") @file:Suppress("EXPERIMENTAL_API_USAGE", "DEPRECATION_ERROR")
package net.mamoe.mirai.qqandroid package net.mamoe.mirai.qqandroid
...@@ -24,7 +24,6 @@ import kotlinx.serialization.UnstableDefault ...@@ -24,7 +24,6 @@ import kotlinx.serialization.UnstableDefault
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration import kotlinx.serialization.json.JsonConfiguration
import kotlinx.serialization.json.int import kotlinx.serialization.json.int
import net.mamoe.mirai.BotAccount
import net.mamoe.mirai.BotImpl import net.mamoe.mirai.BotImpl
import net.mamoe.mirai.LowLevelAPI import net.mamoe.mirai.LowLevelAPI
import net.mamoe.mirai.contact.* import net.mamoe.mirai.contact.*
...@@ -52,22 +51,23 @@ import net.mamoe.mirai.qqandroid.utils.toReadPacket ...@@ -52,22 +51,23 @@ import net.mamoe.mirai.qqandroid.utils.toReadPacket
import net.mamoe.mirai.utils.* import net.mamoe.mirai.utils.*
import kotlin.collections.asSequence import kotlin.collections.asSequence
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmSynthetic
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
import kotlin.random.Random import kotlin.random.Random
@OptIn(MiraiInternalAPI::class) @OptIn(MiraiInternalAPI::class)
internal expect class QQAndroidBot constructor( internal class QQAndroidBot constructor(
context: Context, context: Context,
account: BotAccount, account: BotAccount,
configuration: BotConfiguration configuration: BotConfiguration
) : QQAndroidBotBase ) : QQAndroidBotBase(context, account, configuration)
@OptIn(MiraiInternalAPI::class, MiraiExperimentalAPI::class) @OptIn(MiraiInternalAPI::class, MiraiExperimentalAPI::class)
internal abstract class QQAndroidBotBase constructor( internal abstract class QQAndroidBotBase constructor(
context: Context, context: Context,
account: BotAccount, private val account: BotAccount,
configuration: BotConfiguration configuration: BotConfiguration
) : BotImpl<QQAndroidBotNetworkHandler>(context, account, configuration) { ) : BotImpl<QQAndroidBotNetworkHandler>(context, configuration) {
val client: QQAndroidClient = val client: QQAndroidClient =
QQAndroidClient( QQAndroidClient(
context, context,
...@@ -76,7 +76,9 @@ internal abstract class QQAndroidBotBase constructor( ...@@ -76,7 +76,9 @@ internal abstract class QQAndroidBotBase constructor(
device = configuration.deviceInfo?.invoke(context) ?: SystemDeviceInfo(context) device = configuration.deviceInfo?.invoke(context) ?: SystemDeviceInfo(context)
) )
internal var firstLoginSucceed: Boolean = false internal var firstLoginSucceed: Boolean = false
override val uin: Long get() = client.uin
override val id: Long
get() = account.id
companion object { companion object {
@OptIn(UnstableDefault::class) @OptIn(UnstableDefault::class)
...@@ -88,7 +90,7 @@ internal abstract class QQAndroidBotBase constructor( ...@@ -88,7 +90,7 @@ internal abstract class QQAndroidBotBase constructor(
override val selfQQ: QQ by lazy { override val selfQQ: QQ by lazy {
@OptIn(LowLevelAPI::class) @OptIn(LowLevelAPI::class)
_lowLevelNewQQ(object : FriendInfo { _lowLevelNewQQ(object : FriendInfo {
override val uin: Long get() = this@QQAndroidBotBase.uin override val uin: Long get() = this@QQAndroidBotBase.id
override val nick: String get() = this@QQAndroidBotBase.nick override val nick: String get() = this@QQAndroidBotBase.nick
}) })
} }
...@@ -167,7 +169,7 @@ internal abstract class QQAndroidBotBase constructor( ...@@ -167,7 +169,7 @@ internal abstract class QQAndroidBotBase constructor(
@ExperimentalMessageSource @ExperimentalMessageSource
override suspend fun recall(source: MessageSource) { override suspend fun recall(source: MessageSource) {
if (source.senderId != uin && source.groupId != 0L) { if (source.senderId != id && source.groupId != 0L) {
getGroup(source.groupId).checkBotPermissionOperator() getGroup(source.groupId).checkBotPermissionOperator()
} }
...@@ -370,9 +372,10 @@ internal abstract class QQAndroidBotBase constructor( ...@@ -370,9 +372,10 @@ internal abstract class QQAndroidBotBase constructor(
return json.parse(GroupActiveData.serializer(), rep) return json.parse(GroupActiveData.serializer(), rep)
} }
@JvmSynthetic
@LowLevelAPI @LowLevelAPI
@MiraiExperimentalAPI @MiraiExperimentalAPI
internal suspend fun _lowLevelSendLongGroupMessage(groupCode: Long, message: MessageChain): MessageReceipt<Group> { internal suspend fun lowLevelSendLongGroupMessage(groupCode: Long, message: MessageChain): MessageReceipt<Group> {
val group = getGroup(groupCode) val group = getGroup(groupCode)
val time = currentTimeSeconds val time = currentTimeSeconds
...@@ -432,8 +435,8 @@ internal abstract class QQAndroidBotBase constructor( ...@@ -432,8 +435,8 @@ internal abstract class QQAndroidBotBase constructor(
return group.sendMessage( return group.sendMessage(
RichMessage.longMessage( RichMessage.longMessage(
brief = message.joinToString(limit = 27){ brief = message.joinToString(limit = 27) {
when(it){ when (it) {
is PlainText -> it.stringValue is PlainText -> it.stringValue
is At -> it.display is At -> it.display
is AtAll -> it.display is AtAll -> it.display
......
...@@ -82,7 +82,7 @@ internal class GroupImpl( ...@@ -82,7 +82,7 @@ internal class GroupImpl(
override val muteTimestamp: Int override val muteTimestamp: Int
get() = botMuteRemaining get() = botMuteRemaining
override val uin: Long override val uin: Long
get() = bot.uin get() = bot.id
override val nick: String override val nick: String
get() = bot.nick get() = bot.nick
}) })
...@@ -101,7 +101,7 @@ internal class GroupImpl( ...@@ -101,7 +101,7 @@ internal class GroupImpl(
} }
override val members: ContactList<Member> = ContactList(members.mapNotNull { override val members: ContactList<Member> = ContactList(members.mapNotNull {
if (it.uin == bot.uin) { if (it.uin == bot.id) {
botPermission = it.permission botPermission = it.permission
if (it.permission == MemberPermission.OWNER) { if (it.permission == MemberPermission.OWNER) {
owner = botAsMember owner = botAsMember
...@@ -298,7 +298,7 @@ internal class GroupImpl( ...@@ -298,7 +298,7 @@ internal class GroupImpl(
) )
} }
if (length >= 800) { if (length >= 800) {
return bot._lowLevelSendLongGroupMessage(this.id, event.message) return bot.lowLevelSendLongGroupMessage(this.id, event.message)
} }
msg = event.message msg = event.message
...@@ -334,7 +334,7 @@ internal class GroupImpl( ...@@ -334,7 +334,7 @@ internal class GroupImpl(
bot.network.run { bot.network.run {
val response: ImgStore.GroupPicUp.Response = ImgStore.GroupPicUp( val response: ImgStore.GroupPicUp.Response = ImgStore.GroupPicUp(
bot.client, bot.client,
uin = bot.uin, uin = bot.id,
groupCode = id, groupCode = id,
md5 = image.md5, md5 = image.md5,
size = image.inputSize, size = image.inputSize,
......
...@@ -105,7 +105,7 @@ internal class QQImpl( ...@@ -105,7 +105,7 @@ internal class QQImpl(
bot.network.run { bot.network.run {
val response = LongConn.OffPicUp( val response = LongConn.OffPicUp(
bot.client, Cmd0x352.TryUpImgReq( bot.client, Cmd0x352.TryUpImgReq(
srcUin = bot.uin.toInt(), srcUin = bot.id.toInt(),
dstUin = id.toInt(), dstUin = id.toInt(),
fileId = 0, fileId = 0,
fileMd5 = image.md5, fileMd5 = image.md5,
...@@ -133,7 +133,7 @@ internal class QQImpl( ...@@ -133,7 +133,7 @@ internal class QQImpl(
is LongConn.OffPicUp.Response.RequireUpload -> { is LongConn.OffPicUp.Response.RequireUpload -> {
MiraiPlatformUtils.Http.postImage( MiraiPlatformUtils.Http.postImage(
"0x6ff0070", "0x6ff0070",
bot.uin, bot.id,
null, null,
imageInput = image.input, imageInput = image.input,
inputSize = image.inputSize, inputSize = image.inputSize,
......
...@@ -7,15 +7,15 @@ ...@@ -7,15 +7,15 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE * https://github.com/mamoe/mirai/blob/master/LICENSE
*/ */
@file:Suppress("NOTHING_TO_INLINE", "EXPERIMENTAL_API_USAGE") @file:Suppress("NOTHING_TO_INLINE", "EXPERIMENTAL_API_USAGE", "DEPRECATION_ERROR")
package net.mamoe.mirai.qqandroid.network package net.mamoe.mirai.qqandroid.network
import kotlinx.atomicfu.AtomicInt import kotlinx.atomicfu.AtomicInt
import kotlinx.atomicfu.atomic import kotlinx.atomicfu.atomic
import kotlinx.io.core.* import kotlinx.io.core.*
import net.mamoe.mirai.RawAccountIdUse
import net.mamoe.mirai.data.OnlineStatus import net.mamoe.mirai.data.OnlineStatus
import net.mamoe.mirai.qqandroid.BotAccount
import net.mamoe.mirai.qqandroid.QQAndroidBot import net.mamoe.mirai.qqandroid.QQAndroidBot
import net.mamoe.mirai.qqandroid.network.protocol.packet.EMPTY_BYTE_ARRAY import net.mamoe.mirai.qqandroid.network.protocol.packet.EMPTY_BYTE_ARRAY
import net.mamoe.mirai.qqandroid.network.protocol.packet.PacketLogger import net.mamoe.mirai.qqandroid.network.protocol.packet.PacketLogger
...@@ -58,7 +58,7 @@ internal fun getRandomByteArray(length: Int): ByteArray = ByteArray(length) { Ra ...@@ -58,7 +58,7 @@ internal fun getRandomByteArray(length: Int): ByteArray = ByteArray(length) { Ra
@PublishedApi @PublishedApi
internal open class QQAndroidClient( internal open class QQAndroidClient(
context: Context, context: Context,
val id: Long, val account: BotAccount,
val ecdh: ECDH = ECDH(), val ecdh: ECDH = ECDH(),
val device: DeviceInfo = SystemDeviceInfo(context), val device: DeviceInfo = SystemDeviceInfo(context),
bot: QQAndroidBot bot: QQAndroidBot
...@@ -89,7 +89,7 @@ internal open class QQAndroidClient( ...@@ -89,7 +89,7 @@ internal open class QQAndroidClient(
} }
override fun toString(): String { // extremely slow override fun toString(): String { // extremely slow
return "QQAndroidClient(id=$id, ecdh=$ecdh, device=$device, tgtgtKey=${tgtgtKey.toUHexString()}, randomKey=${randomKey.toUHexString()}, miscBitMap=$miscBitMap, mainSigMap=$mainSigMap, subSigMap=$subSigMap, openAppId=$openAppId, apkVersionName=${apkVersionName.toUHexString()}, loginState=$loginState, appClientVersion=$appClientVersion, networkType=$networkType, apkSignatureMd5=${apkSignatureMd5.toUHexString()}, protocolVersion=$protocolVersion, apkId=${apkId.toUHexString()}, t150=${t150?.value?.toUHexString()}, rollbackSig=${rollbackSig?.toUHexString()}, ipFromT149=${ipFromT149?.toUHexString()}, timeDifference=$timeDifference, uin=$uin, t530=${t530?.toUHexString()}, t528=${t528?.toUHexString()}, ksid='$ksid', pwdFlag=$pwdFlag, loginExtraData=$loginExtraData, wFastLoginInfo=$wFastLoginInfo, reserveUinInfo=$reserveUinInfo, wLoginSigInfo=$wLoginSigInfo, tlv113=${tlv113?.toUHexString()}, qrPushSig=${qrPushSig.toUHexString()}, mainDisplayName='$mainDisplayName')" return "QQAndroidClient(account=$account, ecdh=$ecdh, device=$device, tgtgtKey=${tgtgtKey.toUHexString()}, randomKey=${randomKey.toUHexString()}, miscBitMap=$miscBitMap, mainSigMap=$mainSigMap, subSigMap=$subSigMap, openAppId=$openAppId, apkVersionName=${apkVersionName.toUHexString()}, loginState=$loginState, appClientVersion=$appClientVersion, networkType=$networkType, apkSignatureMd5=${apkSignatureMd5.toUHexString()}, protocolVersion=$protocolVersion, apkId=${apkId.toUHexString()}, t150=${t150?.value?.toUHexString()}, rollbackSig=${rollbackSig?.toUHexString()}, ipFromT149=${ipFromT149?.toUHexString()}, timeDifference=$timeDifference, uin=$uin, t530=${t530?.toUHexString()}, t528=${t528?.toUHexString()}, ksid='$ksid', pwdFlag=$pwdFlag, loginExtraData=$loginExtraData, wFastLoginInfo=$wFastLoginInfo, reserveUinInfo=$reserveUinInfo, wLoginSigInfo=$wLoginSigInfo, tlv113=${tlv113?.toUHexString()}, qrPushSig=${qrPushSig.toUHexString()}, mainDisplayName='$mainDisplayName')"
} }
var onlineStatus: OnlineStatus = OnlineStatus.ONLINE var onlineStatus: OnlineStatus = OnlineStatus.ONLINE
...@@ -174,9 +174,8 @@ internal open class QQAndroidClient( ...@@ -174,9 +174,8 @@ internal open class QQAndroidClient(
*/ */
val uin: Long get() = _uin val uin: Long get() = _uin
@OptIn(RawAccountIdUse::class) @Suppress("PropertyName")
@Suppress("PropertyName", "DEPRECATION_ERROR") internal var _uin: Long = account.id
internal var _uin: Long = bot.account.id
var t530: ByteArray? = null var t530: ByteArray? = null
var t528: ByteArray? = null var t528: ByteArray? = null
......
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
package net.mamoe.mirai.qqandroid.network.protocol.packet.chat package net.mamoe.mirai.qqandroid.network.protocol.packet.chat
import kotlinx.io.core.ByteReadPacket import kotlinx.io.core.ByteReadPacket
import net.mamoe.mirai.qqandroid.network.Packet
import net.mamoe.mirai.qqandroid.QQAndroidBot import net.mamoe.mirai.qqandroid.QQAndroidBot
import net.mamoe.mirai.qqandroid.io.serialization.readProtoBuf import net.mamoe.mirai.qqandroid.io.serialization.readProtoBuf
import net.mamoe.mirai.qqandroid.io.serialization.toByteArray import net.mamoe.mirai.qqandroid.io.serialization.toByteArray
import net.mamoe.mirai.qqandroid.io.serialization.writeProtoBuf import net.mamoe.mirai.qqandroid.io.serialization.writeProtoBuf
import net.mamoe.mirai.qqandroid.network.Packet
import net.mamoe.mirai.qqandroid.network.QQAndroidClient import net.mamoe.mirai.qqandroid.network.QQAndroidClient
import net.mamoe.mirai.qqandroid.network.protocol.data.proto.MsgRevokeUserDef import net.mamoe.mirai.qqandroid.network.protocol.data.proto.MsgRevokeUserDef
import net.mamoe.mirai.qqandroid.network.protocol.data.proto.MsgSvc import net.mamoe.mirai.qqandroid.network.protocol.data.proto.MsgSvc
...@@ -87,7 +87,7 @@ internal class PbMessageSvc { ...@@ -87,7 +87,7 @@ internal class PbMessageSvc {
subCmd = 1, subCmd = 1,
msgInfo = listOf( msgInfo = listOf(
MsgSvc.PbC2CMsgWithDrawReq.MsgInfo( MsgSvc.PbC2CMsgWithDrawReq.MsgInfo(
fromUin = client.bot.uin, fromUin = client.bot.id,
toUin = toUin, toUin = toUin,
msgSeq = messageSequenceId, msgSeq = messageSequenceId,
msgUid = messageUid, msgUid = messageUid,
......
...@@ -154,7 +154,7 @@ internal class MessageSvc { ...@@ -154,7 +154,7 @@ internal class MessageSvc {
when (msg.msgHead.msgType) { when (msg.msgHead.msgType) {
33 -> { 33 -> {
val group = bot.getGroupByUinOrNull(msg.msgHead.fromUin) val group = bot.getGroupByUinOrNull(msg.msgHead.fromUin)
if (msg.msgHead.authUin == bot.uin) { if (msg.msgHead.authUin == bot.id) {
if (group != null) { if (group != null) {
return@mapNotNull null return@mapNotNull null
} }
...@@ -217,7 +217,7 @@ internal class MessageSvc { ...@@ -217,7 +217,7 @@ internal class MessageSvc {
val friend = bot.getFriendOrNull(msg.msgHead.fromUin) ?: return@mapNotNull null val friend = bot.getFriendOrNull(msg.msgHead.fromUin) ?: return@mapNotNull null
friend.checkIsQQImpl() friend.checkIsQQImpl()
if (msg.msgHead.fromUin == bot.uin || !bot.firstLoginSucceed) { if (msg.msgHead.fromUin == bot.id || !bot.firstLoginSucceed) {
return@mapNotNull null return@mapNotNull null
} }
......
...@@ -42,10 +42,10 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.IncomingPacketFactory ...@@ -42,10 +42,10 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.IncomingPacketFactory
import net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacket import net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacket
import net.mamoe.mirai.qqandroid.network.protocol.packet.buildResponseUniPacket import net.mamoe.mirai.qqandroid.network.protocol.packet.buildResponseUniPacket
import net.mamoe.mirai.qqandroid.utils.io.readString import net.mamoe.mirai.qqandroid.utils.io.readString
import net.mamoe.mirai.utils.MiraiInternalAPI
import net.mamoe.mirai.utils.debug
import net.mamoe.mirai.qqandroid.utils.read import net.mamoe.mirai.qqandroid.utils.read
import net.mamoe.mirai.qqandroid.utils.toUHexString import net.mamoe.mirai.qqandroid.utils.toUHexString
import net.mamoe.mirai.utils.MiraiInternalAPI
import net.mamoe.mirai.utils.debug
internal class OnlinePush { internal class OnlinePush {
/** /**
...@@ -70,7 +70,7 @@ internal class OnlinePush { ...@@ -70,7 +70,7 @@ internal class OnlinePush {
val extraInfo: ImMsgBody.ExtraInfo? = val extraInfo: ImMsgBody.ExtraInfo? =
pbPushMsg.msg.msgBody.richText.elems.firstOrNull { it.extraInfo != null }?.extraInfo pbPushMsg.msg.msgBody.richText.elems.firstOrNull { it.extraInfo != null }?.extraInfo
if (pbPushMsg.msg.msgHead.fromUin == bot.uin) { if (pbPushMsg.msg.msgHead.fromUin == bot.id) {
return SendGroupMessageReceipt( return SendGroupMessageReceipt(
pbPushMsg.msg.msgBody.richText.attr!!.random, pbPushMsg.msg.msgBody.richText.attr!!.random,
pbPushMsg.msg.msgHead.msgSeq pbPushMsg.msg.msgHead.msgSeq
...@@ -122,7 +122,7 @@ internal class OnlinePush { ...@@ -122,7 +122,7 @@ internal class OnlinePush {
.toInt() == 1 .toInt() == 1
) MemberPermission.ADMINISTRATOR else MemberPermission.MEMBER ) MemberPermission.ADMINISTRATOR else MemberPermission.MEMBER
return if (target == bot.uin) { return if (target == bot.id) {
BotGroupPermissionChangeEvent( BotGroupPermissionChangeEvent(
group, group,
group.botPermission.also { group.botPermission = newPermission }, group.botPermission.also { group.botPermission = newPermission },
...@@ -211,7 +211,7 @@ internal class OnlinePush { ...@@ -211,7 +211,7 @@ internal class OnlinePush {
when (val internalType = this.readByte().toInt().also { this.discardExact(1) }) { when (val internalType = this.readByte().toInt().also { this.discardExact(1) }) {
0x0c -> { // mute 0x0c -> { // mute
val operatorUin = this.readUInt().toLong() val operatorUin = this.readUInt().toLong()
if (operatorUin == bot.uin) { if (operatorUin == bot.id) {
return@flatMap sequenceOf() return@flatMap sequenceOf()
} }
val operator = group.getOrNull(operatorUin) ?: return@flatMap sequenceOf() val operator = group.getOrNull(operatorUin) ?: return@flatMap sequenceOf()
...@@ -245,7 +245,7 @@ internal class OnlinePush { ...@@ -245,7 +245,7 @@ internal class OnlinePush {
) )
} }
} else { } else {
if (target == bot.uin) { if (target == bot.id) {
if (group._botMuteTimestamp == time) { if (group._botMuteTimestamp == time) {
return@flatMap sequenceOf() return@flatMap sequenceOf()
} }
...@@ -362,7 +362,7 @@ internal class OnlinePush { ...@@ -362,7 +362,7 @@ internal class OnlinePush {
group.getOrNull(recallReminder.uin) ?: return@flatMap sequenceOf() group.getOrNull(recallReminder.uin) ?: return@flatMap sequenceOf()
return@flatMap recallReminder.recalledMsgList.asSequence() return@flatMap recallReminder.recalledMsgList.asSequence()
.mapNotNull { meta -> .mapNotNull { meta ->
if (meta.authorUin == bot.uin) { if (meta.authorUin == bot.id) {
null null
} else MessageRecallEvent.GroupRecall( } else MessageRecallEvent.GroupRecall(
bot, bot,
......
...@@ -7,12 +7,11 @@ ...@@ -7,12 +7,11 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE * https://github.com/mamoe/mirai/blob/master/LICENSE
*/ */
@file:Suppress("FunctionName") @file:Suppress("FunctionName", "OverridingDeprecatedMember")
package net.mamoe.mirai.qqandroid package net.mamoe.mirai.qqandroid
import net.mamoe.mirai.Bot import net.mamoe.mirai.Bot
import net.mamoe.mirai.BotAccount
import net.mamoe.mirai.BotFactory import net.mamoe.mirai.BotFactory
import net.mamoe.mirai.qqandroid.QQAndroid.Bot import net.mamoe.mirai.qqandroid.QQAndroid.Bot
import net.mamoe.mirai.utils.BotConfiguration import net.mamoe.mirai.utils.BotConfiguration
......
...@@ -16,13 +16,11 @@ import io.ktor.utils.io.core.readBytes ...@@ -16,13 +16,11 @@ import io.ktor.utils.io.core.readBytes
import kotlinx.coroutines.io.* import kotlinx.coroutines.io.*
import kotlinx.io.core.* import kotlinx.io.core.*
import kotlinx.io.pool.useInstance import kotlinx.io.pool.useInstance
import net.mamoe.mirai.BotAccount
import net.mamoe.mirai.qqandroid.utils.ByteArrayPool import net.mamoe.mirai.qqandroid.utils.ByteArrayPool
import net.mamoe.mirai.qqandroid.utils.toReadPacket
import net.mamoe.mirai.utils.BotConfiguration import net.mamoe.mirai.utils.BotConfiguration
import net.mamoe.mirai.utils.Context
import net.mamoe.mirai.utils.ContextImpl import net.mamoe.mirai.utils.ContextImpl
import net.mamoe.mirai.utils.MiraiInternalAPI import net.mamoe.mirai.utils.MiraiInternalAPI
import net.mamoe.mirai.qqandroid.utils.toReadPacket
import java.nio.ByteBuffer import java.nio.ByteBuffer
@OptIn(MiraiInternalAPI::class) @OptIn(MiraiInternalAPI::class)
...@@ -30,13 +28,6 @@ import java.nio.ByteBuffer ...@@ -30,13 +28,6 @@ import java.nio.ByteBuffer
internal fun QQAndroidBot(account: BotAccount, configuration: BotConfiguration): QQAndroidBot = internal fun QQAndroidBot(account: BotAccount, configuration: BotConfiguration): QQAndroidBot =
QQAndroidBot(ContextImpl(), account, configuration) QQAndroidBot(ContextImpl(), account, configuration)
@OptIn(MiraiInternalAPI::class)
internal actual class QQAndroidBot actual constructor(
context: Context,
account: BotAccount,
configuration: BotConfiguration
) : QQAndroidBotBase(context, account, configuration)
@OptIn(MiraiInternalAPI::class) @OptIn(MiraiInternalAPI::class)
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
internal actual fun ByteReadChannel.toKotlinByteReadChannel(): kotlinx.coroutines.io.ByteReadChannel { internal actual fun ByteReadChannel.toKotlinByteReadChannel(): kotlinx.coroutines.io.ByteReadChannel {
......
...@@ -57,10 +57,15 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA ...@@ -57,10 +57,15 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
*/ */
actual abstract val context: Context actual abstract val context: Context
@PlannedRemoval("1.0.0")
@Deprecated("use id instead", replaceWith = ReplaceWith("id"))
actual abstract val uin: Long
/** /**
* QQ 号码. 实际类型为 uint * QQ 号码. 实际类型为 uint
*/ */
actual abstract val uin: Long @SinceMirai("0.32.0")
actual abstract val id: Long
/** /**
* 昵称 * 昵称
...@@ -87,9 +92,9 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA ...@@ -87,9 +92,9 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
* 获取一个好友对象. 若没有这个好友, 则会抛出异常 [NoSuchElementException] * 获取一个好友对象. 若没有这个好友, 则会抛出异常 [NoSuchElementException]
*/ */
actual fun getFriend(id: Long): QQ { actual fun getFriend(id: Long): QQ {
if (id == uin) return selfQQ if (id == this.id) return selfQQ
return friends.delegate.getOrNull(id) return friends.delegate.getOrNull(id)
?: throw NoSuchElementException("No such friend $id for bot ${this.uin}") ?: throw NoSuchElementException("No such friend $id for bot ${this.id}")
} }
/** /**
...@@ -104,7 +109,7 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA ...@@ -104,7 +109,7 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
*/ */
actual fun getGroup(id: Long): Group { actual fun getGroup(id: Long): Group {
return groups.delegate.getOrNull(id) return groups.delegate.getOrNull(id)
?: throw NoSuchElementException("No such group $id for bot ${this.uin}") ?: throw NoSuchElementException("No such group $id for bot ${this.id}")
} }
// endregion // endregion
...@@ -197,5 +202,5 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA ...@@ -197,5 +202,5 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
actual abstract fun close(cause: Throwable?) actual abstract fun close(cause: Throwable?)
@OptIn(LowLevelAPI::class, MiraiExperimentalAPI::class) @OptIn(LowLevelAPI::class, MiraiExperimentalAPI::class)
actual final override fun toString(): String = "Bot(${uin})" actual final override fun toString(): String = "Bot($id)"
} }
\ No newline at end of file
...@@ -77,10 +77,15 @@ expect abstract class Bot() : CoroutineScope, LowLevelBotAPIAccessor { ...@@ -77,10 +77,15 @@ expect abstract class Bot() : CoroutineScope, LowLevelBotAPIAccessor {
*/ */
abstract val context: Context abstract val context: Context
@PlannedRemoval("1.0.0")
@Deprecated("use id instead", replaceWith = ReplaceWith("id"))
abstract val uin: Long
/** /**
* QQ 号码. 实际类型为 uint * QQ 号码. 实际类型为 uint
*/ */
abstract val uin: Long @SinceMirai("0.32.0")
abstract val id: Long
/** /**
* 昵称 * 昵称
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE * https://github.com/mamoe/mirai/blob/master/LICENSE
*/ */
@file:Suppress("FunctionName") @file:Suppress("FunctionName", "INAPPLICABLE_JVM_NAME", "DEPRECATION_ERROR", "DeprecatedCallableAddReplaceWith")
package net.mamoe.mirai package net.mamoe.mirai
...@@ -22,7 +22,6 @@ import kotlin.jvm.JvmName ...@@ -22,7 +22,6 @@ import kotlin.jvm.JvmName
* - `mirai-core-timpc`: `TIMPC` * - `mirai-core-timpc`: `TIMPC`
* - `mirai-core-qqandroid`: `QQAndroid` * - `mirai-core-qqandroid`: `QQAndroid`
*/ */
@Suppress("INAPPLICABLE_JVM_NAME")
interface BotFactory { interface BotFactory {
/** /**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例 * 使用指定的 [配置][configuration] 构造 [Bot] 实例
...@@ -55,8 +54,7 @@ inline fun BotFactory.Bot( ...@@ -55,8 +54,7 @@ inline fun BotFactory.Bot(
qq: Long, qq: Long,
password: String, password: String,
configuration: (BotConfiguration.() -> Unit) configuration: (BotConfiguration.() -> Unit)
): Bot = ): Bot = this.Bot(context, qq, password, BotConfiguration().apply(configuration))
this.Bot(context, qq, password, BotConfiguration().apply(configuration))
/** /**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例 * 使用指定的 [配置][configuration] 构造 [Bot] 实例
...@@ -64,7 +62,6 @@ inline fun BotFactory.Bot( ...@@ -64,7 +62,6 @@ inline fun BotFactory.Bot(
inline fun BotFactory.Bot( inline fun BotFactory.Bot(
context: Context, context: Context,
qq: Long, qq: Long,
passwordMd5: ByteArray, password: ByteArray,
configuration: (BotConfiguration.() -> Unit) configuration: (BotConfiguration.() -> Unit)
): Bot = ): Bot = this.Bot(context, qq, password, BotConfiguration().apply(configuration))
this.Bot(context, qq, passwordMd5, BotConfiguration().apply(configuration)) \ No newline at end of file
\ No newline at end of file
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE * https://github.com/mamoe/mirai/blob/master/LICENSE
*/ */
@file:Suppress("EXPERIMENTAL_API_USAGE", "DEPRECATION_ERROR") @file:Suppress("EXPERIMENTAL_API_USAGE", "DEPRECATION_ERROR", "OverridingDeprecatedMember")
package net.mamoe.mirai package net.mamoe.mirai
...@@ -32,27 +32,23 @@ import kotlin.coroutines.CoroutineContext ...@@ -32,27 +32,23 @@ import kotlin.coroutines.CoroutineContext
@MiraiInternalAPI @MiraiInternalAPI
abstract class BotImpl<N : BotNetworkHandler> constructor( abstract class BotImpl<N : BotNetworkHandler> constructor(
context: Context, context: Context,
account: BotAccount,
val configuration: BotConfiguration val configuration: BotConfiguration
) : Bot(), CoroutineScope { ) : Bot(), CoroutineScope {
private val botJob = SupervisorJob(configuration.parentCoroutineContext[Job])
final override val coroutineContext: CoroutineContext = final override val coroutineContext: CoroutineContext =
configuration.parentCoroutineContext + botJob + (configuration.parentCoroutineContext[CoroutineExceptionHandler] configuration.parentCoroutineContext + SupervisorJob(configuration.parentCoroutineContext[Job]) +
?: CoroutineExceptionHandler { _, e -> (configuration.parentCoroutineContext[CoroutineExceptionHandler]
logger.error( ?: CoroutineExceptionHandler { _, e ->
"An exception was thrown under a coroutine of Bot", logger.error(
e "An exception was thrown under a coroutine of Bot",
) e
}) )
override val context: Context by context.unsafeWeakRef() })
@OptIn(LowLevelAPI::class) override val context: Context by context.unsafeWeakRef()
@Suppress("CanBePrimaryConstructorProperty", "OverridingDeprecatedMember") // for logger
final override val account: BotAccount = account
@OptIn(RawAccountIdUse::class) @Deprecated("use id instead", replaceWith = ReplaceWith("id"))
override val uin: Long override val uin: Long
get() = this.account.id get() = this.id
final override val logger: MiraiLogger by lazy { configuration.botLoggerSupplier(this) } final override val logger: MiraiLogger by lazy { configuration.botLoggerSupplier(this) }
...@@ -71,7 +67,7 @@ abstract class BotImpl<N : BotNetworkHandler> constructor( ...@@ -71,7 +67,7 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
fun getInstance(qq: Long): Bot { fun getInstance(qq: Long): Bot {
instances.forEach { instances.forEach {
it.get()?.let { bot -> it.get()?.let { bot ->
if (bot.uin == qq) { if (bot.id == qq) {
return bot return bot
} }
} }
...@@ -188,20 +184,20 @@ abstract class BotImpl<N : BotNetworkHandler> constructor( ...@@ -188,20 +184,20 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
groups.delegate.clear() // job is cancelled, so child jobs are to be cancelled groups.delegate.clear() // job is cancelled, so child jobs are to be cancelled
friends.delegate.clear() friends.delegate.clear()
instances.removeIf { it.get()?.uin == this.uin } instances.removeIf { it.get()?.id == this.id }
} }
} }
@OptIn(MiraiInternalAPI::class) @OptIn(MiraiInternalAPI::class)
override fun close(cause: Throwable?) { override fun close(cause: Throwable?) {
if (!this.botJob.isActive) { if (!this.isActive) {
// already cancelled // already cancelled
return return
} }
if (cause == null) { if (cause == null) {
this.botJob.cancel() this.cancel()
} else { } else {
this.botJob.cancel(CancellationException("bot cancelled", cause)) this.cancel(CancellationException("bot cancelled", cause))
} }
} }
} }
...@@ -131,7 +131,7 @@ sealed class MessageRecallEvent : BotEvent { ...@@ -131,7 +131,7 @@ sealed class MessageRecallEvent : BotEvent {
val operator: Long val operator: Long
) : MessageRecallEvent(), Packet { ) : MessageRecallEvent(), Packet {
override val authorId: Long override val authorId: Long
get() = bot.uin get() = bot.id
} }
data class GroupRecall( data class GroupRecall(
...@@ -150,9 +150,9 @@ sealed class MessageRecallEvent : BotEvent { ...@@ -150,9 +150,9 @@ sealed class MessageRecallEvent : BotEvent {
@OptIn(MiraiExperimentalAPI::class) @OptIn(MiraiExperimentalAPI::class)
val MessageRecallEvent.GroupRecall.author: Member val MessageRecallEvent.GroupRecall.author: Member
get() = if (authorId == bot.uin) group.botAsMember else group[authorId] get() = if (authorId == bot.id) group.botAsMember else group[authorId]
val MessageRecallEvent.FriendRecall.isByBot: Boolean get() = this.operator == bot.uin val MessageRecallEvent.FriendRecall.isByBot: Boolean get() = this.operator == bot.id
val MessageRecallEvent.isByBot: Boolean val MessageRecallEvent.isByBot: Boolean
get() = when (this) { get() = when (this) {
......
...@@ -15,7 +15,6 @@ import net.mamoe.mirai.contact.QQ ...@@ -15,7 +15,6 @@ import net.mamoe.mirai.contact.QQ
import net.mamoe.mirai.data.* import net.mamoe.mirai.data.*
import net.mamoe.mirai.message.data.MessageSource import net.mamoe.mirai.message.data.MessageSource
import net.mamoe.mirai.utils.MiraiExperimentalAPI import net.mamoe.mirai.utils.MiraiExperimentalAPI
import net.mamoe.mirai.utils.MiraiInternalAPI
import net.mamoe.mirai.utils.SinceMirai import net.mamoe.mirai.utils.SinceMirai
import net.mamoe.mirai.utils.WeakRef import net.mamoe.mirai.utils.WeakRef
...@@ -37,15 +36,6 @@ annotation class LowLevelAPI ...@@ -37,15 +36,6 @@ annotation class LowLevelAPI
@Suppress("FunctionName", "unused") @Suppress("FunctionName", "unused")
@LowLevelAPI @LowLevelAPI
interface LowLevelBotAPIAccessor { interface LowLevelBotAPIAccessor {
/**
* 账号信息
*/
@Deprecated("将来会做修改", level = DeprecationLevel.ERROR)
@MiraiExperimentalAPI
@LowLevelAPI
@MiraiInternalAPI
val account: BotAccount
/** /**
* 构造一个 [_lowLevelNewQQ] 对象. 它持有对 [Bot] 的弱引用([WeakRef]). * 构造一个 [_lowLevelNewQQ] 对象. 它持有对 [Bot] 的弱引用([WeakRef]).
* *
......
...@@ -25,12 +25,12 @@ open class BotConfiguration { ...@@ -25,12 +25,12 @@ open class BotConfiguration {
/** /**
* 日志记录器 * 日志记录器
*/ */
var botLoggerSupplier: ((Bot) -> MiraiLogger) = { DefaultLogger("Bot(${it.uin})") } var botLoggerSupplier: ((Bot) -> MiraiLogger) = { DefaultLogger("Bot(${it.id})") }
/** /**
* 网络层日志构造器 * 网络层日志构造器
*/ */
var networkLoggerSupplier: ((BotNetworkHandler) -> MiraiLogger) = { DefaultLogger("Network(${it.bot.uin})") } var networkLoggerSupplier: ((BotNetworkHandler) -> MiraiLogger) = { DefaultLogger("Network(${it.bot.id})") }
/** /**
* 设备信息覆盖. 默认使用随机的设备信息. * 设备信息覆盖. 默认使用随机的设备信息.
......
...@@ -67,10 +67,15 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA ...@@ -67,10 +67,15 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
*/ */
actual abstract val context: Context actual abstract val context: Context
@PlannedRemoval("1.0.0")
@Deprecated("use id instead", replaceWith = ReplaceWith("id"))
actual abstract val uin: Long
/** /**
* QQ 号码. 实际类型为 uint * QQ 号码. 实际类型为 uint
*/ */
actual abstract val uin: Long @SinceMirai("0.32.0")
actual abstract val id: Long
/** /**
* 昵称 * 昵称
...@@ -97,9 +102,9 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA ...@@ -97,9 +102,9 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
* 获取一个好友对象. 若没有这个好友, 则会抛出异常 [NoSuchElementException] * 获取一个好友对象. 若没有这个好友, 则会抛出异常 [NoSuchElementException]
*/ */
actual fun getFriend(id: Long): QQ { actual fun getFriend(id: Long): QQ {
if (id == uin) return selfQQ if (id == this.id) return selfQQ
return friends.delegate.getOrNull(id) return friends.delegate.getOrNull(id)
?: throw NoSuchElementException("No such friend $id for bot ${this.uin}") ?: throw NoSuchElementException("No such friend $id for bot ${this.id}")
} }
/** /**
...@@ -114,7 +119,7 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA ...@@ -114,7 +119,7 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
*/ */
actual fun getGroup(id: Long): Group { actual fun getGroup(id: Long): Group {
return groups.delegate.getOrNull(id) return groups.delegate.getOrNull(id)
?: throw NoSuchElementException("No such group $id for bot ${this.uin}") ?: throw NoSuchElementException("No such group $id for bot ${this.id}")
} }
// endregion // endregion
...@@ -207,5 +212,5 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA ...@@ -207,5 +212,5 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
actual abstract fun close(cause: Throwable?) actual abstract fun close(cause: Throwable?)
@OptIn(LowLevelAPI::class, MiraiExperimentalAPI::class) @OptIn(LowLevelAPI::class, MiraiExperimentalAPI::class)
actual final override fun toString(): String = "Bot(${uin})" actual final override fun toString(): String = "Bot($id)"
} }
\ 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