From 9eef7d378719476e8f9352acfe6328111d3734db Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Mon, 10 Oct 2022 00:10:25 +0800 Subject: [PATCH] [core] Fix group audio url fetching. fix #2269 --- .../notice/group/GroupMessageProcessor.kt | 21 ++++++++++++ .../protocol/packet/chat/voice/PttStore.kt | 34 ++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/mirai-core/src/commonMain/kotlin/network/notice/group/GroupMessageProcessor.kt b/mirai-core/src/commonMain/kotlin/network/notice/group/GroupMessageProcessor.kt index 60402c639..0d46b26bb 100644 --- a/mirai-core/src/commonMain/kotlin/network/notice/group/GroupMessageProcessor.kt +++ b/mirai-core/src/commonMain/kotlin/network/notice/group/GroupMessageProcessor.kt @@ -31,6 +31,7 @@ import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.internal.network.protocol.data.proto.MsgComm import net.mamoe.mirai.internal.network.protocol.data.proto.MsgOnlinePush import net.mamoe.mirai.internal.network.protocol.data.proto.Oidb0x8fc +import net.mamoe.mirai.internal.network.protocol.packet.chat.voice.PttStore import net.mamoe.mirai.internal.utils.io.serialization.loadAs import net.mamoe.mirai.message.data.MessageSourceKind import net.mamoe.mirai.utils.* @@ -104,6 +105,26 @@ internal class GroupMessageProcessor( elem.anonGroupMsg != null -> anonymous = elem.anonGroupMsg } } + + msg.msg.msgBody.richText.ptt?.let pttPatch@{ ptt -> + if (ptt.downPara.isNotEmpty()) return@pttPatch + + kotlin.runCatching { + val response = bot.network.sendAndExpect( + PttStore.GroupPttDown( + bot.client, + group.groupCode, + ptt, + msg.msg + ), + 5000, + 2 + ) + + ptt.downPara = + "http://${response.strDomain}${response.downPara.decodeToString()}".encodeToByteArray() + } + } } diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/voice/PttStore.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/voice/PttStore.kt index 5337a6a4f..c2960d69c 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/voice/PttStore.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/voice/PttStore.kt @@ -16,6 +16,8 @@ import net.mamoe.mirai.internal.network.Packet import net.mamoe.mirai.internal.network.QQAndroidClient import net.mamoe.mirai.internal.network.protocol.data.proto.Cmd0x346 import net.mamoe.mirai.internal.network.protocol.data.proto.Cmd0x388 +import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody +import net.mamoe.mirai.internal.network.protocol.data.proto.MsgComm import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacketFactory import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacketWithRespType import net.mamoe.mirai.internal.network.protocol.packet.buildOutgoingUniPacket @@ -148,6 +150,36 @@ internal class PttStore { } + operator fun invoke( + client: QQAndroidClient, + groupCode: Long, + ptt: ImMsgBody.Ptt, + msg: MsgComm.Msg, + ) = buildOutgoingUniPacket(client) { + writeProtoBuf( + Cmd0x388.ReqBody.serializer(), Cmd0x388.ReqBody( + netType = 3, // wifi + subcmd = 4, + msgGetpttUrlReq = listOf( + Cmd0x388.GetPttUrlReq( + groupCode = groupCode, + fileid = 0, + fileId = ptt.fileId.toLong(), + fileMd5 = ptt.fileMd5, + dstUin = msg.msgHead.toUin, + fileKey = ptt.groupFileKey, + buType = 3, + innerIp = 0, + buildVer = "8.5.5".encodeToByteArray(), + codec = 0, + reqTerm = 5, + reqPlatformType = 9, + ) + ) + ) + ) + } + @OptIn(ExperimentalStdlibApi::class) operator fun invoke( client: QQAndroidClient, @@ -167,7 +199,7 @@ internal class PttStore { dstUin = dstUin, buType = 4, innerIp = 0, - buildVer = "6.5.5.663".encodeToByteArray(), + buildVer = "8.5.5".encodeToByteArray(), codec = 0, reqTerm = 5, reqPlatformType = 9