From 818df4b4cf00c88a0ad56b733ce74de518732211 Mon Sep 17 00:00:00 2001 From: Syfaro Date: Mon, 9 Mar 2020 04:08:12 -0500 Subject: [PATCH] Look at caption entities, use correct kind of URL. --- src/handlers/channel_photo.rs | 19 +++++++++++++++++-- telegram/src/types.rs | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/handlers/channel_photo.rs b/src/handlers/channel_photo.rs index 29ce218..83ab87a 100644 --- a/src/handlers/channel_photo.rs +++ b/src/handlers/channel_photo.rs @@ -123,7 +123,14 @@ pub fn extract_links<'m>( // Possible there's links generated by bots (or users). if let Some(ref entities) = message.entities { for entity in entities { - if entity.entity_type == MessageEntityType::URL { + if entity.entity_type == MessageEntityType::TextLink { + links.extend(finder.links(entity.url.as_ref().unwrap())); + } + } + } + if let Some(ref entities) = message.caption_entities { + for entity in entities { + if entity.entity_type == MessageEntityType::TextLink { links.extend(finder.links(entity.url.as_ref().unwrap())); } } @@ -170,6 +177,7 @@ mod tests { "https://e621.net", "https://www.furaffinity.net", "https://www.weasyl.com", + "https://furrynetwork.com", ]; let message = telegram::Message { @@ -191,12 +199,19 @@ mod tests { ], }), entities: Some(vec![telegram::MessageEntity { - entity_type: telegram::MessageEntityType::URL, + entity_type: telegram::MessageEntityType::TextLink, offset: 0, length: 10, url: Some("https://www.weasyl.com".to_string()), user: None, }]), + caption_entities: Some(vec![telegram::MessageEntity { + entity_type: telegram::MessageEntityType::TextLink, + offset: 11, + length: 20, + url: Some("https://furrynetwork.com".to_string()), + user: None, + }]), ..Default::default() }; diff --git a/telegram/src/types.rs b/telegram/src/types.rs index e8b56e9..4290985 100644 --- a/telegram/src/types.rs +++ b/telegram/src/types.rs @@ -130,6 +130,7 @@ pub struct Message { pub author_signature: Option, pub text: Option, pub entities: Option>, + pub caption_entities: Option>, pub photo: Option>, pub caption: Option, pub new_chat_members: Option>,