Skip to main content

bpi_rs/live/
user.rs

1use serde::{ Deserialize, Serialize };
2
3use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
4
5// ================= 数据结构 =================
6
7#[derive(Debug, Serialize, Clone, Deserialize)]
8pub struct PageInfo {
9    /// 页码总长度
10    pub total_page: i32,
11    /// 当前返回的页码
12    pub cur_page: i32,
13}
14
15#[derive(Debug, Serialize, Clone, Deserialize)]
16pub struct FansMedalItem {
17    /// 可否删除
18    #[serde(rename = "can_deleted")]
19    pub can_delete: bool,
20    /// 日经验上限(原力值)
21    pub day_limit: i32,
22    /// 大航海等级
23    pub guard_level: i32,
24    /// 加成状态
25    pub guard_medal_title: String,
26    /// 当前已得亲密度
27    pub intimacy: i32,
28    /// 是否点亮
29    pub is_lighted: i32,
30    /// 勋章等级
31    pub level: i32,
32    /// 勋章名
33    pub medal_name: String,
34    /// 勋章边框颜色信息
35    pub medal_color_border: i32,
36    /// 勋章起始颜色
37    pub medal_color_start: i32,
38    /// 勋章结束颜色
39    pub medal_color_end: i32,
40    /// 粉丝勋章id
41    pub medal_id: i64,
42    /// 升级所需经验
43    pub next_intimacy: i32,
44    /// 本日亲密度
45    pub today_feed: i32,
46    /// 直播间房间号
47    pub roomid: i64,
48    /// 状态
49    pub status: i32,
50    /// up主mid
51    pub target_id: i64,
52    /// up主用户名
53    pub target_name: String,
54    /// up主用户名
55    pub uname: String,
56}
57
58#[derive(Debug, Serialize, Clone, Deserialize)]
59pub struct MyMedalsData {
60    /// 勋章数量
61    pub count: i32,
62    /// 粉丝勋章信息本体
63    pub items: Vec<FansMedalItem>,
64    /// 页码信息
65    pub page_info: PageInfo,
66}
67
68pub type MyMedalsResponse = BpiResponse<MyMedalsData>;
69
70// ================= 实现 =================
71
72impl BpiClient {
73    /// 获取自己持有的粉丝勋章信息
74    ///
75
76    /// # 文档
77    /// [查看API文档](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/live)
78    pub async fn live_my_medals(
79        &self,
80        page: i32,
81        page_size: i32
82    ) -> Result<MyMedalsResponse, BpiError> {
83        let params = [
84            ("page", page.to_string()),
85            ("page_size", page_size.to_string()),
86        ];
87
88        let resp: MyMedalsResponse = self
89            .get("https://api.live.bilibili.com/xlive/app-ucenter/v1/user/GetMyMedals")
90            .query(&params)
91            .send_bpi("获取自己持有的粉丝勋章信息").await?;
92
93        Ok(resp)
94    }
95}
96
97#[cfg(test)]
98mod tests {
99    use super::*;
100
101    #[tokio::test]
102    async fn test_get_my_medals() -> Result<(), Box<BpiError>> {
103        let bpi = BpiClient::new();
104        let resp = bpi.live_my_medals(1, 10).await?;
105
106        tracing::info!("{:?}", resp.data);
107        Ok(())
108    }
109}