about summary refs log tree commit diff
path: root/users/tazjin/tgsa
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-04-17T22·10+0200
committerclbot <clbot@tvl.fyi>2022-04-17T22·12+0000
commit856dfa62a15251a4688588b4d11c9ac639535294 (patch)
tree2d0e838118babe72b4590ceefac5020166ca6523 /users/tazjin/tgsa
parent6c8841c1763075f5b37a2868b3fb6fb3679bb84f (diff)
feat(tazjin/tgsa): Handle messages with audio attached r/3974
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
Diffstat (limited to 'users/tazjin/tgsa')
-rw-r--r--users/tazjin/tgsa/src/main.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/users/tazjin/tgsa/src/main.rs b/users/tazjin/tgsa/src/main.rs
index 341e1b1639..deae6a8150 100644
--- a/users/tazjin/tgsa/src/main.rs
+++ b/users/tazjin/tgsa/src/main.rs
@@ -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);
     }