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
//! 好友分组。
//!
//! 更多信息参考 [`FriendGroup`]。

use std::sync::Arc;

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

use super::ClientImpl;

/// 好友分组。
///
/// # Python
/// ```python
/// class FriendGroup: ...
/// ```
#[pyclass]
#[derive(Clone)]
pub struct FriendGroup {
    #[allow(unused)] // TODO: remove this
    pub(super) client: Arc<ClientImpl>,
    pub(super) info: FriendGroupInfo,
}

#[pymethods]
impl FriendGroup {
    /// 好友分组 ID。
    ///
    /// # Python
    /// ```python
    /// @property
    /// def id(self) -> int: ...
    /// ```
    #[getter]
    pub fn id(&self) -> u8 {
        self.info.group_id
    }

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

    /// 好友分组中的好友数量。
    ///
    /// # Python
    /// ```python
    /// @property
    /// def count(self) -> int: ...
    /// ```
    #[getter]
    pub fn friend_count(&self) -> i32 {
        self.info.friend_count
    }

    /// 分组中在线的好友数量。
    ///
    /// # Python
    /// ```python
    /// @property
    /// def online_count(self) -> int: ...
    /// ```
    #[getter]
    pub fn online_count(&self) -> i32 {
        self.info.online_friend_count
    }

    /// TODO: 未知
    ///
    /// # Python
    /// ```python
    /// @property
    /// def seq_id(self) -> int: ...
    /// ```
    #[getter]
    pub fn seq_id(&self) -> u8 {
        self.info.seq_id
    }

    fn __repr__(&self) -> String {
        format!(
            "FriendGroupInfo(id={:?}, name={:?}, friend_count={:?}, online_count={:?}, seq_id={:?})",
            self.id(),
            self.name(),
            self.friend_count(),
            self.online_count(),
            self.seq_id()
        )
    }
}