From 856dfa62a15251a4688588b4d11c9ac639535294 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 18 Apr 2022 00:10:12 +0200 Subject: feat(tazjin/tgsa): Handle messages with audio attached Audio can not be embedded on these stupid dead comedy forums, but people can click through to listen. Change-Id: I6e28636e69e424bb8cbc6b92963d1b28b3c04bf6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/5478 Reviewed-by: tazjin Autosubmit: tazjin Tested-by: BuildkiteCI --- users/tazjin/tgsa/src/main.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'users') diff --git a/users/tazjin/tgsa/src/main.rs b/users/tazjin/tgsa/src/main.rs index 341e1b163986..deae6a81505f 100644 --- a/users/tazjin/tgsa/src/main.rs +++ b/users/tazjin/tgsa/src/main.rs @@ -59,6 +59,7 @@ struct TgMessage { message: Option, photos: Vec, videos: Vec, + has_audio: bool, } fn extract_photo_url(style: &str) -> Option<&str> { @@ -110,11 +111,18 @@ fn parse_tgmessage(embed: &str) -> Result { } } + let audio_sel = Selector::parse("audio.tgme_widget_message_voice.js-message_voice").unwrap(); + let mut has_audio = false; + if doc.select(&audio_sel).next().is_some() { + has_audio = true; + } + Ok(TgMessage { author, message, photos, videos, + has_audio, }) } @@ -152,6 +160,13 @@ fn to_bbcode(link: &TgLink, msg: &TgMessage) -> Result { out.push_str(&format!("[timg]{}[/timg]\n", shorten_link(photo)?)); } + if msg.has_audio { + out.push_str(&format!( + "[i]This message has audio attached. Go [url=\"{}\"]to Telegram[/url] to listen.[/i]", + link.to_url(), + )); + } + if let Some(message) = &msg.message { out.push_str(message); } -- cgit 1.4.1