bugfixes #15
					 1 changed files with 33 additions and 29 deletions
				
			
		|  | @ -127,32 +127,23 @@ pub async fn embed_handler(event: OriginalSyncRoomMessageEvent, room: Room, clie | |||
| 
 | ||||
|         let reqwest_client = reqwest::Client::builder().user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36").build().unwrap(); | ||||
| 
 | ||||
|         for mut url in urls { | ||||
|         for url in urls { | ||||
|             if let Ok(req) = reqwest_client.get(url).send().await { | ||||
|                 if let Ok(res) = req.text().await { | ||||
|                     // beware, dirty HTML parsing code
 | ||||
|                     let metadata = parse_metadata(&res); | ||||
| 
 | ||||
|                     // If we didn't get any metadata set URL to nothing so it won't get repeated
 | ||||
|                     // With no other embed data in the bot's embed message
 | ||||
|                     if metadata.is_none() { | ||||
|                         url = ""; | ||||
|                     } | ||||
| 
 | ||||
|                     // Build our message reply
 | ||||
|                     let embed = metadata | ||||
|                         .unwrap_or(Embed::new("No metadata found".to_string(), "".to_string())); | ||||
|                     // Build and send our message reply
 | ||||
|                     if metadata.is_some() { | ||||
|                         let embed = metadata.unwrap(); | ||||
|                         let bot_reply = RoomMessageEventContent::text_html( | ||||
|                             &embed.title, | ||||
|                             format!( | ||||
|                             r#" | ||||
|                                 <blockquote> | ||||
|                                     <h6><a href="{}">{}</a></h6> | ||||
|                                     <h3><strong>{}</strong></h3> | ||||
|                                 "<blockquote>
 | ||||
|                                 <h4>{}</h4> | ||||
|                                 <p>{}</p> | ||||
|                                 </blockquote> | ||||
|                         "#,
 | ||||
|                             &url, &url, &embed.title, &embed.description | ||||
|                                 </blockquote>",
 | ||||
|                                 &embed.title, &embed.description | ||||
|                             ), | ||||
|                         ) | ||||
|                         .make_reply_to(&full_reply_event); | ||||
|  | @ -162,11 +153,24 @@ pub async fn embed_handler(event: OriginalSyncRoomMessageEvent, room: Room, clie | |||
|                         if room.send(bot_reply, None).await.is_err() { | ||||
|                             warn!("Failed to send embed for URL: '{}'", &url); | ||||
|                         } | ||||
|                     // If we didn't get any metadata send a generic "No metadata" response
 | ||||
|                     } else { | ||||
|                         let bot_reply = RoomMessageEventContent::text_html( | ||||
|                             "Couldn't parse metadata for URL", | ||||
|                             "<blockquote><h5>Couldn't parse metadata for URL</h5></blockquote>", | ||||
|                         ) | ||||
|                         .make_reply_to(&full_reply_event); | ||||
|                         // Send the reply to the room
 | ||||
|                         warn!("Sending 'No metadata' embed for URL: '{}'", &url); | ||||
|                         if room.send(bot_reply, None).await.is_err() { | ||||
|                             warn!("Failed to send embed for URL: '{}'", &url); | ||||
|                         } | ||||
|                     } | ||||
|                 } else { | ||||
|                     warn!("Failed to parse HTML for URL: '{}'", &url); | ||||
|                 } | ||||
|             } else { | ||||
|                 warn!("Failed to get metadata for '{}'", &url); | ||||
|                 warn!("Failed to fetch metadata for '{}'", &url); | ||||
|             } | ||||
|         } | ||||
|     }; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue