mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-09 01:30:17 +08:00
Fix massive group list loading
This commit is contained in:
parent
4633803c55
commit
faf8002de9
@ -206,7 +206,7 @@ internal abstract class QQAndroidBotBase constructor(
|
||||
TroopManagement.GetGroupInfo(
|
||||
client = bot.client,
|
||||
groupCode = groupCode
|
||||
).sendAndExpect<GroupInfoImpl>(retry = 2)
|
||||
).sendAndExpect<GroupInfoImpl>(retry = 3)
|
||||
}
|
||||
|
||||
@OptIn(LowLevelAPI::class)
|
||||
@ -224,7 +224,7 @@ internal abstract class QQAndroidBotBase constructor(
|
||||
targetGroupUin = groupUin,
|
||||
targetGroupCode = groupCode,
|
||||
nextUin = nextUin
|
||||
).sendAndExpect<FriendList.GetTroopMemberList.Response>(timeoutMillis = 3000)
|
||||
).sendAndExpect<FriendList.GetTroopMemberList.Response>(retry = 3)
|
||||
sequence += data.members.asSequence().map { troopMemberInfo ->
|
||||
MemberInfoImpl(troopMemberInfo, ownerId)
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
||||
_pendingEnabled.value = true
|
||||
}
|
||||
|
||||
coroutineScope {
|
||||
supervisorScope {
|
||||
launch {
|
||||
lateinit var loadFriends: suspend () -> Unit
|
||||
// 不要用 fun, 不要 join declaration, 不要用 val, 编译失败警告
|
||||
@ -262,9 +262,11 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
||||
try {
|
||||
logger.info("开始加载群组列表与群成员列表")
|
||||
val troopListData = FriendList.GetTroopListSimplify(bot.client)
|
||||
.sendAndExpect<FriendList.GetTroopListSimplify.Response>(retry = 2)
|
||||
.sendAndExpect<FriendList.GetTroopListSimplify.Response>(retry = 3)
|
||||
|
||||
troopListData.groups.forEach { troopNum ->
|
||||
troopListData.groups.chunked(100).forEach { chunk ->
|
||||
coroutineScope {
|
||||
chunk.forEach { troopNum ->
|
||||
// 别用 fun, 别 val, 编译失败警告
|
||||
lateinit var loadGroup: suspend () -> Unit
|
||||
|
||||
@ -314,6 +316,8 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
||||
loadGroup()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.info { "群组列表与群成员加载完成, 共 ${troopListData.groups.size}个" }
|
||||
} catch (e: Exception) {
|
||||
logger.error { "加载组信息失败|一般这是由于加载过于频繁导致/将以热加载方式加载群列表" }
|
||||
@ -322,7 +326,8 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
||||
}
|
||||
}
|
||||
|
||||
withTimeoutOrNull(5000) {
|
||||
supervisorScope {
|
||||
withTimeoutOrNull(30000) {
|
||||
lateinit var listener: Listener<PacketReceivedEvent>
|
||||
listener = this.subscribeAlways {
|
||||
if (it.packet is MessageSvc.PbGetMsg.GetMsgSuccess) {
|
||||
@ -330,9 +335,9 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
||||
}
|
||||
}
|
||||
|
||||
MessageSvc.PbGetMsg(bot.client, MsgSvc.SyncFlag.START, currentTimeSeconds).sendWithoutExpect()
|
||||
MessageSvc.PbGetMsg(bot.client, MsgSvc.SyncFlag.START, currentTimeSeconds).sendAndExpect<Packet>()
|
||||
} ?: error("timeout syncing friend message history")
|
||||
|
||||
}
|
||||
bot.firstLoginSucceed = true
|
||||
|
||||
_pendingEnabled.value = false
|
||||
|
@ -33,7 +33,7 @@ import net.mamoe.mirai.data.GroupInfo as MiraiGroupInfo
|
||||
@OptIn(LowLevelAPI::class)
|
||||
internal class GroupInfoImpl(
|
||||
internal val delegate: Oidb0x88d.GroupInfo
|
||||
) : MiraiGroupInfo, Packet {
|
||||
) : MiraiGroupInfo, Packet, Packet.NoLog {
|
||||
override val uin: Long get() = delegate.groupUin ?: error("cannot find groupUin")
|
||||
override val owner: Long get() = delegate.groupOwner ?: error("cannot find groupOwner")
|
||||
override val groupCode: Long get() = Group.calculateGroupCodeByGroupUin(uin)
|
||||
|
@ -35,11 +35,8 @@ import net.mamoe.mirai.qqandroid.network.protocol.data.proto.TroopTips0x857
|
||||
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.buildResponseUniPacket
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.data.jce.MsgType0x210
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive.onlinePush0x210.OnlinePush0x210Factory
|
||||
import net.mamoe.mirai.qqandroid.utils.io.JceStruct
|
||||
import net.mamoe.mirai.qqandroid.utils.io.readString
|
||||
import net.mamoe.mirai.qqandroid.utils.io.serialization.*
|
||||
import net.mamoe.mirai.qqandroid.utils.io.serialization.decodeUniPacket
|
||||
import net.mamoe.mirai.qqandroid.utils.io.serialization.jce.JceId
|
||||
import net.mamoe.mirai.qqandroid.utils.io.serialization.jceRequestSBuffer
|
||||
@ -310,7 +307,14 @@ internal class OnlinePush {
|
||||
}
|
||||
0x10 -> {
|
||||
val dataBytes = this.readBytes(26)
|
||||
val message = this.readString(this.readByte().toInt())
|
||||
val size = this.readByte().toInt() // orthodox, don't `readUByte`
|
||||
if (size < 0) {
|
||||
error(
|
||||
"negative array size: $size, remaining bytes=${this.readBytes()
|
||||
.toUHexString()}"
|
||||
)
|
||||
}
|
||||
val message = this.readString(size)
|
||||
// println(dataBytes.toUHexString())
|
||||
|
||||
if (dataBytes[0].toInt() != 59) {
|
||||
|
@ -9,7 +9,7 @@ internal object ByteArrayPool : DefaultPool<ByteArray>(256) {
|
||||
/**
|
||||
* 每一个 [ByteArray] 的大小
|
||||
*/
|
||||
const val BUFFER_SIZE: Int = 81920 / 2
|
||||
const val BUFFER_SIZE: Int = 8192000
|
||||
|
||||
override fun produceInstance(): ByteArray = ByteArray(BUFFER_SIZE)
|
||||
|
||||
|
@ -150,8 +150,8 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
|
||||
suspend fun doInit() {
|
||||
tryNTimesOrException(2) {
|
||||
if (it != 0) {
|
||||
delay(3000)
|
||||
logger.warning("Init failed. Retrying in 3s...")
|
||||
delay(3000)
|
||||
}
|
||||
_network.init()
|
||||
}?.let {
|
||||
|
Loading…
Reference in New Issue
Block a user