qq_bot/restful/
get_channel.rs

1use super::*;
2
3/// `GET /guilds/{guild_id}/channels`
4///
5/// <https://bot.q.qq.com/wiki/develop/api/openapi/guild/get_guild.html>
6#[derive(Serialize, Deserialize, Debug)]
7pub struct GetChannelListResponse {
8    pub items: Vec<ChannelItem>,
9}
10
11impl GetChannelListResponse {
12    pub fn end_point(key: &QQSecret) -> String {
13        if cfg!(debug_assertions) {
14            format!("https://sandbox.api.sgroup.qq.com/guilds/{guild_id}/channels", guild_id = key.guild_id())
15        }
16        else {
17            format!("https://api.sgroup.qq.com/guilds/{guild_id}/channels", guild_id = key.guild_id())
18        }
19    }
20
21    pub async fn send(key: &QQSecret) -> QQResult<Self> {
22        let url = Url::from_str(&Self::end_point(key))?;
23        let response = key.as_request(Method::GET, url).send().await?;
24        let out: Vec<ChannelItem> = response.json().await?;
25        return Ok(Self { items: out });
26    }
27}
28
29#[derive(Serialize, Deserialize, Debug)]
30pub struct ChannelItem {
31    /// 子频道 id
32    pub id: String,
33    /// 频道 id
34    pub guild_id: String,
35    /// 子频道名
36    pub name: String,
37    /// 子频道类型 ChannelType
38    pub r#type: u32,
39    /// 子频道子类型 ChannelSubType
40    pub sub_type: u32,
41    /// 排序值,具体请参考 有关 position 的说明
42    pub position: u32,
43    /// 所属分组 id,仅对子频道有效,对 子频道分组(ChannelType=4) 无效
44    pub parent_id: String,
45    /// 创建人 id
46    pub owner_id: String,
47    /// 子频道私密类型 PrivateType
48    pub private_type: Option<u32>,
49    /// 子频道发言权限 SpeakPermission
50    pub speak_permission: Option<u32>,
51    /// 用于标识应用子频道应用类型,仅应用子频道时会使用该字段,具体定义请参考 应用子频道的应用类型
52    pub application_id: Option<String>,
53    /// 用户拥有的子频道权限 Permissions
54    pub permissions: Option<String>,
55}