qq_bot/restful/
get_guild.rs

1use super::*;
2
3use reqwest::Method;
4
5use crate::QQSecret;
6use std::str::FromStr;
7use url::Url;
8
9/// `GET /users/@me/guilds`
10///
11/// <https://bot.q.qq.com/wiki/develop/api/openapi/user/guilds.html>
12#[derive(Debug)]
13pub struct GetGuildListResponse {
14    pub items: Vec<GuildItem>,
15}
16
17impl GetGuildListResponse {
18    pub fn end_point() -> String {
19        if cfg!(debug_assertions) {
20            format!("https://sandbox.api.sgroup.qq.com/users/@me/guilds")
21        }
22        else {
23            format!("https://api.sgroup.qq.com/users/@me/guilds")
24        }
25    }
26    pub async fn send(key: &QQSecret) -> QQResult<Self> {
27        let url = Url::from_str(&Self::end_point())?;
28        let response = key.as_request(Method::GET, url).send().await?;
29        Ok(Self { items: response.json().await? })
30    }
31}
32
33#[derive(Deserialize, Debug)]
34pub struct GuildItem {
35    /// 频道名称
36    pub name: String,
37    /// 描述
38    pub description: String,
39    /// 频道头像地址
40    #[serde(deserialize_with = "crate::utils::read_url")]
41    pub icon: Url,
42    /// 频道ID
43    #[serde(deserialize_with = "crate::utils::read_u64")]
44    pub id: u64,
45    /// 	最大成员数
46    pub max_members: u32,
47    /// 成员数
48    pub member_count: u32,
49    /// 当前人是否是创建人
50    pub owner: bool,
51    /// 创建人用户ID
52    #[serde(deserialize_with = "crate::utils::read_u64")]
53    pub owner_id: u64,
54    /// 加入时间
55    pub joined_at: String,
56}