1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
use crate::protocol::protobuf;
use dynamic_protobuf::{dynamic_message, DynamicMessage};
use rand::Rng;
use ricq_core::command::common::PbToBytes;
use ricq_core::protocol::packet::Packet;
use std::sync::atomic::Ordering;

impl<'a> super::Engine<'a> {
    pub fn build_sync_channel_first_view_packet(&self) -> Packet {
        let req = protobuf::FirstViewReq {
            last_msg_time: Some(0),
            udc_flag: None,
            seq: Some(0),
            direct_message_flag: Some(1),
        };

        let b = req.to_bytes();
        self.uni_packet("trpc.group_pro.synclogic.SyncLogic.SyncFirstView", b)
    }

    pub fn build_get_user_profile_packet(&self, tiny_id: u64) -> Packet {
        let mut flags = DynamicMessage::new();

        for i in 3..=29 {
            flags.set(i, 1u32)
        }
        flags.set(99, 1u32);
        flags.set(100, 1u32);

        let payload = {
            let msg = dynamic_message! {
                1 => flags,
                3 => tiny_id,
                4 => 0u32,
            };

            self.transport.encode_oidb_packet(0xf88, 1, msg.encode())
        };

        self.uni_packet("OidbSvcTrpcTcp.0xfc9_1", payload)
    }

    pub fn build_send_channel_message_packet(
        &self,
        elems: Vec<ricq_core::pb::msg::Elem>,
        guild_id: u64,
        channel_id: u64,
    ) -> Packet {
        let routing = protobuf::ChannelRoutingHead {
            guild_id: Some(guild_id),
            channel_id: Some(channel_id),
            from_uin: Some(self.uin.load(Ordering::Relaxed) as _),
            from_tinyid: None,
            guild_code: None,
            from_appid: None,
            direct_message_flag: None,
        };

        let mut rng = rand::thread_rng();
        let random = rng.gen_range(0..i32::MAX);
        let content = protobuf::ChannelContentHead {
            r#type: Some(3840),
            sub_type: None,
            random: Some(random as _),
            seq: None,
            cnt_seq: None,
            time: None,
            meta: None,
        };

        let msg_head = protobuf::ChannelMsgHead {
            routing_head: Some(routing),
            content_head: Some(content),
        };

        let body = ricq_core::pb::msg::MessageBody {
            rich_text: Some(ricq_core::pb::msg::RichText {
                attr: None,
                elems,
                not_online_file: None,
                ptt: None,
            }),
            msg_content: None,
            msg_encrypt_content: None,
        };

        let content = protobuf::ChannelMsgContent {
            head: Some(msg_head),
            ctrl_head: None,
            body: Some(body),
            ext_info: None,
        };

        self.uni_packet(
            "MsgProxy.SendMsg",
            dynamic_message! {
                1 => content.to_bytes(),
            }
            .encode(),
        )
    }

    #[allow(clippy::too_many_arguments)]
    pub fn build_guild_image_store_packet(
        &self,
        channel_id: u64,
        guild_code: u64,
        file_name: String,
        md5: Vec<u8>,
        size: u64,
        width: u32,
        height: u32,
        image_type: u32,
    ) -> Packet {
        let req = ricq_core::pb::cmd0x388::D388ReqBody {
            net_type: Some(3),
            subcmd: Some(1),
            // TODO 支持多张图片?
            tryup_img_req: vec![ricq_core::pb::cmd0x388::TryUpImgReq {
                group_code: Some(channel_id),
                src_uin: Some(self.uin() as u64),
                file_md5: Some(md5),
                file_size: Some(size),
                file_name: Some(file_name.into_bytes()),
                src_term: Some(5),
                platform_type: Some(9),
                bu_type: Some(211),
                pic_type: Some(image_type),
                pic_width: Some(width),
                pic_height: Some(height),
                build_ver: Some(self.transport.version.build_ver.as_bytes().to_vec()),
                app_pic_type: Some(1050),
                qqmeet_guild_id: Some(guild_code),
                qqmeet_channel_id: Some(channel_id),
                ..Default::default()
            }],
            extension: Some(vec![]),
            ..Default::default()
        };
        self.uni_packet("ImgStore.QQMeetPicUp", req.to_bytes())
    }
}