use serde::{ Deserialize, Serialize };
use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct EmoticonItem {
pub bulge_display: i32,
pub descript: String,
pub emoji: String,
pub emoticon_id: i64,
pub emoticon_unique: String,
pub emoticon_value_type: i32,
pub height: i32,
pub identity: i32,
pub in_player_area: i32,
pub is_dynamic: i32,
pub perm: i32,
pub unlock_need_gift: i32,
pub unlock_need_level: i32,
pub unlock_show_color: String,
pub unlock_show_image: String,
pub unlock_show_text: String,
pub url: String,
pub width: i32,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct TopShowItem {
pub image: String,
pub text: String,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct TopShow {
pub top_left: TopShowItem,
pub top_right: TopShowItem,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct EmoticonPackage {
pub current_cover: String,
pub emoticons: Vec<EmoticonItem>,
pub pkg_descript: String,
pub pkg_id: i64,
pub pkg_name: String,
pub pkg_perm: i32,
pub pkg_type: i32,
pub recently_used_emoticons: Vec<serde_json::Value>,
pub top_show: Option<TopShow>,
pub top_show_recent: Option<TopShow>,
pub unlock_identity: i32,
pub unlock_need_gift: i32,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct EmoticonData {
pub data: Vec<EmoticonPackage>,
pub fans_brand: i32,
pub purchase_url: Option<String>,
}
pub type EmoticonResponse = BpiResponse<EmoticonData>;
impl BpiClient {
pub async fn live_emoticons(
&self,
room_id: i64,
platform: &str
) -> Result<EmoticonResponse, BpiError> {
let params = [
("room_id", room_id.to_string()),
("platform", platform.to_string()),
];
let resp: EmoticonResponse = self
.get("https://api.live.bilibili.com/xlive/web-ucenter/v2/emoticon/GetEmoticons")
.query(¶ms)
.send_bpi("获取直播间表情包").await?;
Ok(resp)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_get_live_emoticons() -> Result<(), Box<BpiError>> {
let bpi = BpiClient::new();
let resp = bpi.live_emoticons(14047, "pc").await?;
let data = resp.data.unwrap();
assert!(data.data.len() > 0);
Ok(())
}
}