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 block_type = if hour == 0 {"2".to_string()} else {"1".to_string()};
50
51 let form = vec![
52 ("room_id", room_id.to_string()),
53 ("tuid", tuid.to_string()),
54 ("mobile_app", "web".to_string()),
55 ("type", block_type),
56 ("hour", hour.to_string()),
57 ("csrf_token", csrf.clone()),
58 ("csrf", csrf)
59 ];
60
61 self
66 .post("https://api.live.bilibili.com/xlive/web-ucenter/v1/banned/AddSilentUser")
67 .form(&form)
68 .send_bpi("禁言观众").await
69 }
70
71 pub async fn live_list_silent_users(
74 &self,
75 room_id: i64,
76 ps: i32
77 ) -> Result<BpiResponse<SilentUserListData>, BpiError> {
78 let csrf = self.csrf()?;
79
80 let form = vec![
81 ("room_id", room_id.to_string()),
82 ("ps", ps.to_string()),
83 ("csrf_token", csrf.clone()),
84 ("csrf", csrf)
85 ];
86
87 self
88 .post("https://api.live.bilibili.com/xlive/web-ucenter/v1/banned/GetSilentUserList")
89 .form(&form)
90 .send_bpi("查询直播间禁言列表").await
91 }
92
93 pub async fn live_del_block_user(
96 &self,
97 roomid: i64,
98 id: i64
99 ) -> Result<BpiResponse<serde_json::Value>, BpiError> {
100 let csrf = self.csrf()?;
101
102 let form = vec![
103 ("room_id", roomid.to_string()),
104 ("tuid", id.to_string()),
105 ("csrf_token", csrf.clone()),
106 ("csrf", csrf)
107 ];
108
109 self
110 .post("https://api.live.bilibili.com/xlive/web-ucenter/v1/banned/DelSilentUser")
111 .form(&form)
112 .send_bpi("解除禁言").await
113 }
114}
115
116#[cfg(test)]
117mod tests {
118 use super::*;
119
120 #[tokio::test]
121 async fn test_get_silent_user_list() {
122 let bpi = BpiClient::new();
123 let resp = bpi.live_list_silent_users(3818081, 1).await.unwrap();
124 tracing::info!("{:?}", resp);
125 }
126
127 #[tokio::test]
128 async fn test_add_silent_user() {
129 let bpi = BpiClient::new();
130 let resp = bpi.live_add_silent_user(3818081, 316183842, 0).await.unwrap();
131 tracing::info!("{:?}", resp);
132 }
133
134 #[tokio::test]
135 async fn test_del_silent_user_list() {
136 let bpi = BpiClient::new();
137 let resp = bpi.live_del_block_user(3818081, 316183842).await.unwrap();
138 tracing::info!("{:?}", resp);
139 }
140}