qq_bot/restful/
get_guild.rs1use super::*;
2
3use reqwest::Method;
4
5use crate::QQSecret;
6use std::str::FromStr;
7use url::Url;
8
9#[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 pub name: String,
37 pub description: String,
39 #[serde(deserialize_with = "crate::utils::read_url")]
41 pub icon: Url,
42 #[serde(deserialize_with = "crate::utils::read_u64")]
44 pub id: u64,
45 pub max_members: u32,
47 pub member_count: u32,
49 pub owner: bool,
51 #[serde(deserialize_with = "crate::utils::read_u64")]
53 pub owner_id: u64,
54 pub joined_at: String,
56}