funpay_client/parsing/
message.rs1use scraper::{Html, Selector};
2
3pub fn parse_message_html(html: &str) -> (Option<String>, Option<String>) {
4 let html_owned = html.replace("<br>", "\n");
5 let doc = Html::parse_fragment(&html_owned);
6
7 let sel_text = Selector::parse("div.chat-msg-text").unwrap();
8 if let Some(n) = doc.select(&sel_text).next() {
9 let t = n.text().collect::<String>();
10 return (Some(t), None);
11 }
12
13 let sel_alert = Selector::parse("div[role=alert]").unwrap();
14 if let Some(n) = doc.select(&sel_alert).next() {
15 let t = n.text().collect::<String>();
16 return (Some(t), None);
17 }
18
19 let sel_img = Selector::parse("a.chat-img-link").unwrap();
20 if let Some(n) = doc.select(&sel_img).next() {
21 let href = n.value().attr("href").map(|s| s.to_string());
22 return (None, href);
23 }
24
25 (None, None)
26}