1use serde::{ Deserialize, Serialize };
2
3use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
4
5#[derive(Debug, Serialize, Clone, Deserialize)]
8pub struct EmoticonItem {
9 pub bulge_display: i32,
11 pub descript: String,
13 pub emoji: String,
15 pub emoticon_id: i64,
17 pub emoticon_unique: String,
19 pub emoticon_value_type: i32,
21 pub height: i32,
23 pub identity: i32,
25 pub in_player_area: i32,
27 pub is_dynamic: i32,
29 pub perm: i32,
31 pub unlock_need_gift: i32,
33 pub unlock_need_level: i32,
35 pub unlock_show_color: String,
37 pub unlock_show_image: String,
39 pub unlock_show_text: String,
41 pub url: String,
43 pub width: i32,
45}
46
47#[derive(Debug, Serialize, Clone, Deserialize)]
48pub struct TopShowItem {
49 pub image: String,
51 pub text: String,
53}
54
55#[derive(Debug, Serialize, Clone, Deserialize)]
56pub struct TopShow {
57 pub top_left: TopShowItem,
59 pub top_right: TopShowItem,
61}
62
63#[derive(Debug, Serialize, Clone, Deserialize)]
64pub struct EmoticonPackage {
65 pub current_cover: String,
67 pub emoticons: Vec<EmoticonItem>,
69 pub pkg_descript: String,
71 pub pkg_id: i64,
73 pub pkg_name: String,
75 pub pkg_perm: i32,
77 pub pkg_type: i32,
79 pub recently_used_emoticons: Vec<serde_json::Value>,
81 pub top_show: Option<TopShow>,
83 pub top_show_recent: Option<TopShow>,
85 pub unlock_identity: i32,
87 pub unlock_need_gift: i32,
89}
90
91#[derive(Debug, Serialize, Clone, Deserialize)]
92pub struct EmoticonData {
93 pub data: Vec<EmoticonPackage>,
95 pub fans_brand: i32,
97 pub purchase_url: Option<String>,
99}
100
101pub type EmoticonResponse = BpiResponse<EmoticonData>;
102
103impl BpiClient {
106 pub async fn live_emoticons(
109 &self,
110 room_id: i64,
111 platform: &str
112 ) -> Result<EmoticonResponse, BpiError> {
113 let params = [
114 ("room_id", room_id.to_string()),
115 ("platform", platform.to_string()),
116 ];
117
118 let resp: EmoticonResponse = self
119 .get("https://api.live.bilibili.com/xlive/web-ucenter/v2/emoticon/GetEmoticons")
120 .query(¶ms)
121 .send_bpi("获取直播间表情包").await?;
122
123 Ok(resp)
124 }
125}
126
127#[cfg(test)]
128mod tests {
129 use super::*;
130
131 #[tokio::test]
132 async fn test_get_live_emoticons() -> Result<(), Box<BpiError>> {
133 let bpi = BpiClient::new();
134 let resp = bpi.live_emoticons(14047, "pc").await?;
135
136 let data = resp.data.unwrap();
137 assert!(data.data.len() > 0);
138 Ok(())
139 }
140}