Look at caption entities, use correct kind of URL.
This commit is contained in:
parent
98dd62521c
commit
818df4b4cf
|
@ -123,7 +123,14 @@ pub fn extract_links<'m>(
|
||||||
// Possible there's links generated by bots (or users).
|
// Possible there's links generated by bots (or users).
|
||||||
if let Some(ref entities) = message.entities {
|
if let Some(ref entities) = message.entities {
|
||||||
for entity in 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()));
|
links.extend(finder.links(entity.url.as_ref().unwrap()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,6 +177,7 @@ mod tests {
|
||||||
"https://e621.net",
|
"https://e621.net",
|
||||||
"https://www.furaffinity.net",
|
"https://www.furaffinity.net",
|
||||||
"https://www.weasyl.com",
|
"https://www.weasyl.com",
|
||||||
|
"https://furrynetwork.com",
|
||||||
];
|
];
|
||||||
|
|
||||||
let message = telegram::Message {
|
let message = telegram::Message {
|
||||||
|
@ -191,12 +199,19 @@ mod tests {
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
entities: Some(vec![telegram::MessageEntity {
|
entities: Some(vec![telegram::MessageEntity {
|
||||||
entity_type: telegram::MessageEntityType::URL,
|
entity_type: telegram::MessageEntityType::TextLink,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
length: 10,
|
length: 10,
|
||||||
url: Some("https://www.weasyl.com".to_string()),
|
url: Some("https://www.weasyl.com".to_string()),
|
||||||
user: None,
|
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()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,7 @@ pub struct Message {
|
||||||
pub author_signature: Option<String>,
|
pub author_signature: Option<String>,
|
||||||
pub text: Option<String>,
|
pub text: Option<String>,
|
||||||
pub entities: Option<Vec<MessageEntity>>,
|
pub entities: Option<Vec<MessageEntity>>,
|
||||||
|
pub caption_entities: Option<Vec<MessageEntity>>,
|
||||||
pub photo: Option<Vec<PhotoSize>>,
|
pub photo: Option<Vec<PhotoSize>>,
|
||||||
pub caption: Option<String>,
|
pub caption: Option<String>,
|
||||||
pub new_chat_members: Option<Vec<User>>,
|
pub new_chat_members: Option<Vec<User>>,
|
||||||
|
|
Loading…
Reference in New Issue