Fix PbGetMsg, fix #766

This commit is contained in:
Him188 2020-12-26 16:56:19 +08:00
parent da7abc5bf6
commit 5ba10aed31

View File

@ -43,8 +43,6 @@ import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacketFactory
import net.mamoe.mirai.internal.network.protocol.packet.buildOutgoingUniPacket
import net.mamoe.mirai.internal.network.protocol.packet.chat.GroupInfoImpl
import net.mamoe.mirai.internal.network.protocol.packet.chat.NewContact
import net.mamoe.mirai.internal.network.protocol.packet.chat.receive.MessageSvcPbGetMsg.createGroupForBot
import net.mamoe.mirai.internal.network.protocol.packet.chat.receive.MessageSvcPbGetMsg.getNewMemberInfo
import net.mamoe.mirai.internal.network.protocol.packet.chat.toLongUnsigned
import net.mamoe.mirai.internal.network.protocol.packet.list.FriendList
import net.mamoe.mirai.internal.utils.*
@ -122,30 +120,6 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory<MessageSvcPbGetMsg.Re
object EmptyResponse : GetMsgSuccess(emptyList(), null)
private fun MsgComm.Msg.getNewMemberInfo(): MemberInfo {
return object : MemberInfo {
override val nameCard: String
get() = msgHead.authNick.takeIf { it.isNotEmpty() }
?: msgHead.fromNick
override val permission: MemberPermission get() = MemberPermission.MEMBER
override val specialTitle: String get() = ""
override val muteTimestamp: Int get() = 0
override val uin: Long get() = msgHead.authUin
override val nick: String = msgHead.authNick.takeIf { it.isNotEmpty() }
?: msgHead.fromNick
override val remark: String get() = ""
}
}
private suspend fun QQAndroidBot.createGroupForBot(groupUin: Long): Group? {
val group = getGroupByUinOrNull(groupUin)
if (group != null) {
return null
}
return getNewGroup(Mirai.calculateGroupCodeByGroupUin(groupUin))?.apply { groups.delegate.add(this) }
}
@OptIn(FlowPreview::class)
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): Response {
// 00 00 01 0F 08 00 12 00 1A 34 08 FF C1 C4 F1 05 10 FF C1 C4 F1 05 18 E6 ED B9 C3 02 20 89 FE BE A4 06 28 8A CA 91 D1 0C 48 9B A5 BD 9B 0A 58 DE 9D 99 F8 08 60 1D 68 FF C1 C4 F1 05 70 00 20 02 2A 9D 01 08 F3 C1 C4 F1 05 10 A2 FF 8C F0 03 18 01 22 8A 01 0A 2A 08 A2 FF 8C F0 03 10 DD F1 92 B7 07 18 A6 01 20 0B 28 AE F9 01 30 F4 C1 C4 F1 05 38 A7 E3 D8 D4 84 80 80 80 01 B8 01 CD B5 01 12 08 08 01 10 00 18 00 20 00 1A 52 0A 50 0A 27 08 00 10 F4 C1 C4 F1 05 18 A7 E3 D8 D4 04 20 00 28 0C 30 00 38 86 01 40 22 4A 0C E5 BE AE E8 BD AF E9 9B 85 E9 BB 91 12 08 0A 06 0A 04 4E 4D 53 4C 12 15 AA 02 12 9A 01 0F 80 01 01 C8 01 00 F0 01 00 F8 01 00 90 02 00 12 04 4A 02 08 00 30 01 2A 15 08 97 A2 C1 F1 05 10 95 A6 F5 E5 0C 18 01 30 01 40 01 48 81 01 2A 10 08 D3 F7 B5 F1 05 10 DD F1 92 B7 07 18 01 30 01 38 00 42 00 48 00
@ -194,20 +168,20 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory<MessageSvcPbGetMsg.Re
}.also {
MessageSvcPbDeleteMsg.delete(bot, it) // 删除消息
}
.mapNotNull { msg ->
if (!bot.client.syncingController.pbGetMessageCacheList.addCache(
QQAndroidClient.MessageSvcSyncData.PbGetMessageSyncId(
uid = msg.msgHead.msgUid,
sequence = msg.msgHead.msgSeq,
time = msg.msgHead.msgTime
)
.filter { msg ->
bot.client.syncingController.pbGetMessageCacheList.addCache(
QQAndroidClient.MessageSvcSyncData.PbGetMessageSyncId(
uid = msg.msgHead.msgUid,
sequence = msg.msgHead.msgSeq,
time = msg.msgHead.msgTime
)
) return@mapNotNull null
// if (msg.msgHead.msgType != 732) msg._miraiContentToString().soutv("MSG")
msg.transform(bot)
)
}
.flatMapConcat { msg ->
val result = msg.transform(bot)
if (result == null) emptyFlow() else flowOf(result)
}
val list: List<Packet> = messages.toList()
if (resp.syncFlag == MsgSvc.SyncFlag.STOP) {
return GetMsgSuccess(list, resp.syncCookie)
@ -246,7 +220,31 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory<MessageSvcPbGetMsg.Re
}
}
private suspend fun MsgComm.Msg.transform(bot: QQAndroidBot): Packet? {
private suspend fun QQAndroidBot.createGroupForBot(groupUin: Long): Group? {
val group = getGroupByUinOrNull(groupUin)
if (group != null) {
return null
}
return getNewGroup(Mirai.calculateGroupCodeByGroupUin(groupUin))?.apply { groups.delegate.add(this) }
}
private fun MsgComm.Msg.getNewMemberInfo(): MemberInfo {
return object : MemberInfo {
override val nameCard: String
get() = msgHead.authNick.takeIf { it.isNotEmpty() }
?: msgHead.fromNick
override val permission: MemberPermission get() = MemberPermission.MEMBER
override val specialTitle: String get() = ""
override val muteTimestamp: Int get() = 0
override val uin: Long get() = msgHead.authUin
override val nick: String = msgHead.authNick.takeIf { it.isNotEmpty() }
?: msgHead.fromNick
override val remark: String get() = ""
}
}
internal suspend fun MsgComm.Msg.transform(bot: QQAndroidBot): Packet? {
when (msgHead.msgType) {
33 -> bot.groupListModifyLock.withLock {
@ -378,17 +376,17 @@ private suspend fun MsgComm.Msg.transform(bot: QQAndroidBot): Packet? {
return null
}
friend.lastMessageSequence.loop {
if (friend.lastMessageSequence.compareAndSet(
return if (friend.lastMessageSequence.compareAndSet(
it,
msgHead.msgSeq
) && contentHead?.autoReply != 1
) {
return FriendMessageEvent(
FriendMessageEvent(
friend,
toMessageChain(bot, groupIdOrZero = 0, onlineSource = true),
msgHead.msgTime
)
} else return null
} else null
}
}
208 -> {