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 <tazjin@tvl.su>
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2022-04-18 00:10:12 +02:00 committed by clbot
parent 6c8841c176
commit 856dfa62a1

View file

@ -59,6 +59,7 @@ struct TgMessage {
message: Option<String>,
photos: Vec<String>,
videos: Vec<String>,
has_audio: bool,
}
fn extract_photo_url(style: &str) -> Option<&str> {
@ -110,11 +111,18 @@ fn parse_tgmessage(embed: &str) -> Result<TgMessage> {
}
}
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<String> {
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);
}