bpi_rs/live/
silent_user_manage.rs1use serde::{ Deserialize, Serialize };
2
3use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
4
5#[derive(Debug, Serialize, Clone, Deserialize)]
6pub struct SilentUserInfo {
7 pub tuid: i64,
9 pub tname: String,
11 pub uid: i64,
13 pub name: String,
15 pub ctime: String,
17 pub id: i64,
19 pub is_anchor: i32,
21 pub face: String,
23 pub admin_level: i32,
25}
26
27#[derive(Debug, Serialize, Clone, Deserialize)]
28pub struct SilentUserListData {
29 pub data: Vec<SilentUserInfo>,
31 pub total: i32,
33 pub total_page: i32,
35}
36
37impl BpiClient {
38 pub async fn live_add_silent_user(
42 &self,
43 room_id: i64,
44 tuid: i64,
45 hour: i32
46 ) -> Result<BpiResponse<serde_json::Value>, BpiError> {
47 let csrf = self.csrf()?;
48
49 let form = vec![
50 ("room_id", room_id.to_string()),
51 ("tuid", tuid.to_string()),
52 ("mobile_app", "web".to_string()),
53 ("hour", hour.to_string()),
54 ("csrf_token", csrf.clone()),
55 ("csrf", csrf)
56 ];
57
58 self
63 .post("https://api.live.bilibili.com/xlive/web-ucenter/v1/banned/AddSilentUser")
64 .form(&form)
65 .send_bpi("禁言观众").await
66 }
67
68 pub async fn live_list_silent_users(
71 &self,
72 room_id: i64,
73 ps: i32
74 ) -> Result<BpiResponse<SilentUserListData>, BpiError> {
75 let csrf = self.csrf()?;
76
77 let form = vec![
78 ("room_id", room_id.to_string()),
79 ("ps", ps.to_string()),
80 ("csrf_token", csrf.clone()),
81 ("csrf", csrf)
82 ];
83
84 self
85 .post("https://api.live.bilibili.com/xlive/web-ucenter/v1/banned/GetSilentUserList")
86 .form(&form)
87 .send_bpi("查询直播间禁言列表").await
88 }
89
90 pub async fn live_del_block_user(
93 &self,
94 roomid: i64,
95 id: i64
96 ) -> Result<BpiResponse<serde_json::Value>, BpiError> {
97 let csrf = self.csrf()?;
98
99 let form = vec![
100 ("room_id", roomid.to_string()),
101 ("tuid", id.to_string()),
102 ("csrf_token", csrf.clone()),
103 ("csrf", csrf)
104 ];
105
106 self
107 .post("https://api.live.bilibili.com/xlive/web-ucenter/v1/banned/DelSilentUser")
108 .form(&form)
109 .send_bpi("解除禁言").await
110 }
111}
112
113#[cfg(test)]
114mod tests {
115 use super::*;
116
117 #[tokio::test]
118 async fn test_get_silent_user_list() {
119 let bpi = BpiClient::new();
120 let resp = bpi.live_list_silent_users(3818081, 1).await.unwrap();
121 tracing::info!("{:?}", resp);
122 }
123
124 #[tokio::test]
125 async fn test_add_silent_user() {
126 let bpi = BpiClient::new();
127 let resp = bpi.live_add_silent_user(3818081, 316183842, 0).await.unwrap();
128 tracing::info!("{:?}", resp);
129 }
130
131 #[tokio::test]
132 async fn test_del_silent_user_list() {
133 let bpi = BpiClient::new();
134 let resp = bpi.live_del_block_user(3818081, 316183842).await.unwrap();
135 tracing::info!("{:?}", resp);
136 }
137}