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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//! 群。

use std::sync::Arc;

use pyo3::prelude::*;
use ricq::structs::GroupInfo;

use super::ClientImpl;

/// 群聊。
#[pyclass]
pub struct Group {
    #[allow(unused)] // TODO: remove this
    pub(super) client: Arc<ClientImpl>,
    pub(super) info: GroupInfo,
}

#[pymethods]
impl Group {
    /// uin。
    ///
    /// 含义可参考:[#181](https://github.com/Mrs4s/MiraiGo/issues/181)。
    ///
    /// # Python
    /// ```python
    /// @property
    /// def uin(self) -> int: ...
    /// ```
    #[getter]
    pub fn uin(&self) -> i64 {
        self.info.uin
    }

    /// 群号。
    ///
    /// # Python
    /// ```python
    /// @property
    /// def code(self) -> int: ...
    /// ```
    #[getter]
    pub fn code(&self) -> i64 {
        self.info.code
    }

    /// 群名称。
    ///
    /// # Python
    /// ```python
    /// @property
    /// def name(self) -> str: ...
    /// ```
    #[getter]
    pub fn name(&self) -> &str {
        &self.info.name
    }

    /// 入群公告。
    ///
    /// # Python
    /// ```python
    /// @property
    /// def memo(self) -> str: ...
    /// ```
    #[getter]
    pub fn memo(&self) -> &str {
        &self.info.memo
    }

    /// 群主 QQ 号。
    ///
    /// # Python
    /// ```python
    /// @property
    /// def owner_uin(self) -> int: ...
    /// ```
    #[getter]
    pub fn owner_uin(&self) -> i64 {
        self.info.owner_uin
    }

    /// 群创建时间。
    ///
    /// # Python
    /// ```python
    /// @property
    /// def group_create_time(self) -> int: ...
    /// ```
    #[getter]
    pub fn group_create_time(&self) -> u32 {
        self.info.group_create_time
    }

    /// 群等级。
    ///
    /// # Python
    /// ```python
    /// @property
    /// def level(self) -> int: ...
    /// ```
    #[getter]
    pub fn level(&self) -> u32 {
        self.info.group_level
    }

    /// 群成员数量。
    ///
    /// # Python
    /// ```python
    /// @property
    /// def member_count(self) -> int: ...
    /// ```
    #[getter]
    pub fn member_count(&self) -> u16 {
        self.info.member_count
    }

    /// 最大群成员数量。
    ///
    /// # Python
    /// ```python
    /// @property
    /// def max_member_count(self) -> int: ...
    /// ```
    #[getter]
    pub fn max_member_count(&self) -> u16 {
        self.info.max_member_count
    }

    /// 是否开启全员禁言。
    ///
    /// # Python
    /// ```python
    /// @property
    /// def mute_all(self) -> bool: ...
    /// ```
    #[getter]
    pub fn mute_all(&self) -> bool {
        self.info.shut_up_timestamp != 0
    }

    /// 被禁言剩余时间,单位秒。
    ///
    /// # Python
    /// ```python
    /// @property
    /// def my_shut_up_timestamp(self) -> int: ...
    /// ```
    #[getter]
    pub fn my_shut_up_timestamp(&self) -> i64 {
        self.info.my_shut_up_timestamp
    }

    /// 最后一条消息的 seq。
    ///
    /// 只有通过 [`get_group`] 或 [`get_groups`] 获取的群才有此字段。
    ///
    /// # Python
    /// ```python
    /// @property
    /// def last_msg_seq(self) -> int: ...
    /// ```
    ///
    /// [`get_group`]: crate::client::Client::get_group
    /// [`get_groups`]: crate::client::Client::get_groups
    #[getter]
    pub fn last_msg_seq(&self) -> i64 {
        self.info.last_msg_seq
    }

    fn __repr__(&self) -> String {
        format!(
            "Group(uin={:?}, code={:?}, name={:?}, memo={:?}, owner_uin={:?}, group_create_time={:?}, \
                group_level={:?}, member_count={:?}, max_member_count={:?}, mute_all={:?}, \
                my_shut_up_timestamp={:?}, last_msg_seq={:?})",
            self.uin(),
            self.code(),
            self.name(),
            self.memo(),
            self.owner_uin(),
            self.group_create_time(),
            self.level(),
            self.member_count(),
            self.max_member_count(),
            self.mute_all(),
            self.my_shut_up_timestamp(),
            self.last_msg_seq()
        )
    }
}