Refactor embed module functions and apply clippy lints with rustfmt #19
					 2 changed files with 15 additions and 11 deletions
				
			
		|  | @ -5,12 +5,12 @@ | ||||||
| use lazy_static::lazy_static; | use lazy_static::lazy_static; | ||||||
| use log::warn; | use log::warn; | ||||||
| use matrix_sdk::{ | use matrix_sdk::{ | ||||||
|     RoomState, |  | ||||||
|     room::Room, |     room::Room, | ||||||
|     ruma::events::room::message::{ |     ruma::events::room::message::{ | ||||||
|         MessageType, OriginalSyncRoomMessageEvent, Relation, ForwardThread, AddMentions, RoomMessageEventContent, |         AddMentions, ForwardThread, MessageType, OriginalSyncRoomMessageEvent, Relation, | ||||||
|  |         RoomMessageEventContent, | ||||||
|     }, |     }, | ||||||
|     Client, |     Client, RoomState, | ||||||
| }; | }; | ||||||
| use regex::Regex; | use regex::Regex; | ||||||
| use scraper::{Html, Selector}; | use scraper::{Html, Selector}; | ||||||
|  | @ -125,7 +125,7 @@ pub async fn embed_handler(event: OriginalSyncRoomMessageEvent, room: Room, clie | ||||||
| 
 | 
 | ||||||
|         for url in urls { |         for url in urls { | ||||||
|             match reqwest_client.get(url).send().await { |             match reqwest_client.get(url).send().await { | ||||||
|                 Err(e) => warn!("Failed to fetch metadata for '{}' with error: '{:?}'", &url, e), |                 Err(e) => warn!("Failed to fetch metadata for URL'{}' with error: '{:?}'", &url, e), | ||||||
|                 Ok(req) => { |                 Ok(req) => { | ||||||
|                     match req.text().await { |                     match req.text().await { | ||||||
|                         Err(e) => warn!("Failed to parse HTML for URL '{}' with error: '{:?}'", &url, e), |                         Err(e) => warn!("Failed to parse HTML for URL '{}' with error: '{:?}'", &url, e), | ||||||
|  | @ -147,7 +147,11 @@ pub async fn embed_handler(event: OriginalSyncRoomMessageEvent, room: Room, clie | ||||||
|                                         &embed.title, &embed.description |                                         &embed.title, &embed.description | ||||||
|                                     ), |                                     ), | ||||||
|                                 ) |                                 ) | ||||||
|                                 .make_reply_to(&full_reply_event, ForwardThread::Yes, AddMentions::Yes); |                                 .make_reply_to( | ||||||
|  |                                     &full_reply_event, | ||||||
|  |                                     ForwardThread::Yes, | ||||||
|  |                                     AddMentions::Yes, | ||||||
|  |                                 ); | ||||||
| 
 | 
 | ||||||
|                                 // Finally send the reply to the room
 |                                 // Finally send the reply to the room
 | ||||||
|                                 warn!("Sending embed for URL: '{}'", &url); |                                 warn!("Sending embed for URL: '{}'", &url); | ||||||
|  |  | ||||||
							
								
								
									
										12
									
								
								src/lib.rs
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								src/lib.rs
									
										
									
									
									
								
							|  | @ -5,13 +5,12 @@ pub mod embeds; | ||||||
| use log::warn; | use log::warn; | ||||||
| use matrix_sdk::{ | use matrix_sdk::{ | ||||||
|     config::SyncSettings, |     config::SyncSettings, | ||||||
|     RoomState, |  | ||||||
|     room::Room, |     room::Room, | ||||||
|     ruma::{ |     ruma::{ | ||||||
|         api::client::uiaa, events::room::member::StrippedRoomMemberEvent, OwnedDeviceId, |         api::client::uiaa, events::room::member::StrippedRoomMemberEvent, OwnedDeviceId, | ||||||
|         OwnedRoomId, |         OwnedRoomId, | ||||||
|     }, |     }, | ||||||
|     Client, ClientBuildError, |     Client, ClientBuildError, RoomState, | ||||||
| }; | }; | ||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
| 
 | 
 | ||||||
|  | @ -95,13 +94,14 @@ pub async fn reject_stale_invites(client: &Client, config: &Config) { | ||||||
|     for room in client.invited_rooms() { |     for room in client.invited_rooms() { | ||||||
|         let room_name = room.name().unwrap_or_default(); |         let room_name = room.name().unwrap_or_default(); | ||||||
|         if !room.is_space() |         if !room.is_space() | ||||||
|             && !room.is_direct().await.expect("Failed to check if room is DM") |             && !room | ||||||
|  |                 .is_direct() | ||||||
|  |                 .await | ||||||
|  |                 .expect("Failed to check if room is DM") | ||||||
|             && config.room_ids.iter().any(|r| *r == room.room_id()) |             && config.room_ids.iter().any(|r| *r == room.room_id()) | ||||||
|         { |         { | ||||||
|             warn!("Got invite to room: '{}'", room_name); |             warn!("Got invite to room: '{}'", room_name); | ||||||
|             room.join() |             room.join().await.expect("Failed to accept invite"); | ||||||
|                 .await |  | ||||||
|                 .expect("Failed to accept invite"); |  | ||||||
|             warn!("Joined room: '{}'!", room_name); |             warn!("Joined room: '{}'!", room_name); | ||||||
|         } else { |         } else { | ||||||
|             warn!("Rejecting invite to room: '{}'", room_name); |             warn!("Rejecting invite to room: '{}'", room_name); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue