Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OnlineAudio.urlForDownload not exists when using pad with private chatting #1551

Merged
merged 1 commit into from
Sep 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import net.mamoe.mirai.internal.network.components.SimpleNoticeProcessor
import net.mamoe.mirai.internal.network.components.SsoProcessor
import net.mamoe.mirai.internal.network.notice.group.GroupMessageProcessor
import net.mamoe.mirai.internal.network.protocol.data.proto.MsgComm
import net.mamoe.mirai.internal.network.protocol.packet.chat.voice.PttStore
import net.mamoe.mirai.utils.assertUnreachable
import net.mamoe.mirai.utils.context

Expand Down Expand Up @@ -48,6 +49,16 @@ internal class PrivateMessageProcessor : SimpleNoticeProcessor<MsgComm.Msg>(type
166, 167, // 单向好友
208, // friend ptt, maybe also support stranger
-> {
data.msgBody.richText.ptt?.let { ptt ->
if (ptt.downPara.isEmpty()) {
val rsp = bot.network.sendAndExpect(
PttStore.C2CPttDown(bot.client, senderUin, ptt.fileUuid)
)
if (rsp is PttStore.C2CPttDown.Response.Success) {
ptt.downPara = rsp.downloadUrl.encodeToByteArray()
}
}
}
handlePrivateMessage(
data,
bot.getFriend(senderUin)?.impl()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ internal class ImMsgBody : ProtoBuf {
@ProtoNumber(17) @JvmField val pttUrl: ByteArray = EMPTY_BYTE_ARRAY,
@ProtoNumber(18) @JvmField val groupFileKey: ByteArray = EMPTY_BYTE_ARRAY,
@ProtoNumber(19) @JvmField val time: Int = 0,
@ProtoNumber(20) @JvmField val downPara: ByteArray = EMPTY_BYTE_ARRAY,
@ProtoNumber(20) @JvmField var downPara: ByteArray = EMPTY_BYTE_ARRAY,
@ProtoNumber(29) @JvmField val format: Int = 0,
@ProtoNumber(30) @JvmField val pbReserve: ByteArray = EMPTY_BYTE_ARRAY,
@ProtoNumber(31) @JvmField val bytesPttUrls: List<ByteArray> = emptyList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ internal object KnownPacketFactories {
ImgStore.GroupPicUp,
PttStore.GroupPttUp,
PttStore.GroupPttDown,
PttStore.C2CPttDown,
LongConn.OffPicUp,
// LongConn.OffPicDown,
TroopManagement.EditSpecialTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,50 @@ internal class PttStore {
}
}

object C2CPttDown : OutgoingPacketFactory<C2CPttDown.Response>(
"PttCenterSvr.pb_pttCenter_CMD_REQ_APPLY_DOWNLOAD-1200"
) {
operator fun invoke(client: QQAndroidClient, uin: Long, uuid: ByteArray) =
buildOutgoingUniPacket(client) {
writeProtoBuf(
Cmd0x346.ReqBody.serializer(), Cmd0x346.ReqBody(
msgApplyDownloadReq = Cmd0x346.ApplyDownloadReq(
uin = uin,
uuid = uuid,
needHttpsUrl = 1,
),
clientType = 104,
cmd = 1200,
businessId = 17, // or 3?
)
)
}

sealed class Response : Packet {
class Failed(val retMsg: String) : Response() {
override fun toString(): String {
return "PttCenterSvr.pb_pttCenter#download.Failed(retMsg=$retMsg)"
}
}

class Success(val downloadUrl: String) : Response() {
override fun toString(): String {
return "PttCenterSvr.pb_pttCenter#download.Success"
}
}
}

override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): C2CPttDown.Response {
val data = readProtoBuf(Cmd0x346.RspBody.serializer())
val rsp = data.msgApplyDownloadRsp ?: return Response.Failed("Response not found")
if (rsp.retMsg != "success") {
return Response.Failed(rsp.retMsg)
}
val downloadInfo = rsp.msgDownloadInfo ?: return Response.Failed("Download info not found")
return Response.Success(downloadInfo.downloadUrl)
}
}

object C2C {
fun createC2CPttStoreBDHExt(
bot: QQAndroidBot,
Expand Down