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:
parent
6c8841c176
commit
856dfa62a1
1 changed files with 15 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue