diff --git a/Cargo.toml b/Cargo.toml index 85a4418..775eda5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,16 +8,16 @@ lto = "fat" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -matrix-sdk = {version = "0.7.1", features = ["anyhow", "e2e-encryption", "socks"]} -anyhow = "1.0.86" -clap = "4.5.8" -toml = "0.8.14" -log = "0.4.22" -env_logger = "0.11.3" -tokio = {version = "1.38.0", features = ["parking_lot", "rt-multi-thread", "macros"]} -serde = {version = "1.0.204", features = ["derive"]} -tracing-subscriber = "0.3.18" -scraper = "0.19.0" -reqwest = "0.12.5" -regex = "1.10.5" -lazy_static = "1.5.0" +matrix-sdk = {version = "0.6.2", features = ["anyhow", "e2e-encryption", "socks"]} +anyhow = "1.0.75" +clap = "4.4.6" +toml = "0.8.2" +log = "0.4.20" +env_logger = "0.10.0" +tokio = {version = "1.32.0", features = ["parking_lot", "rt-multi-thread", "macros"]} +serde = {version = "1.0.188", features = ["derive"]} +tracing-subscriber = "0.3.17" +scraper = "0.17.1" +reqwest = "0.11.22" +regex = "1.9.6" +lazy_static = "1.4.0" diff --git a/src/embeds.rs b/src/embeds.rs index 5c46f88..a41cf7d 100644 --- a/src/embeds.rs +++ b/src/embeds.rs @@ -5,10 +5,9 @@ use lazy_static::lazy_static; use log::warn; use matrix_sdk::{ - RoomState, room::Room, ruma::events::room::message::{ - MessageType, OriginalSyncRoomMessageEvent, Relation, ForwardThread, AddMentions, RoomMessageEventContent, + MessageType, OriginalSyncRoomMessageEvent, Relation, RoomMessageEventContent, }, Client, }; @@ -98,7 +97,7 @@ fn get_urls_from_message(message: &str) -> Vec<&str> { pub async fn embed_handler(event: OriginalSyncRoomMessageEvent, room: Room, client: Client) { let fn_start = Instant::now(); - if room.state() == RoomState::Joined { + if let Room::Joined(room) = room { let full_reply_event = event.clone().into_full_event(room.room_id().to_owned()); // If the sender ID matches our client, ignore the message @@ -143,11 +142,11 @@ pub async fn embed_handler(event: OriginalSyncRoomMessageEvent, room: Room, clie &embed.title, &embed.description ), ) - .make_reply_to(&full_reply_event, ForwardThread::Yes, AddMentions::Yes); + .make_reply_to(&full_reply_event); // Finally send the reply to the room warn!("Sending embed for URL: '{}'", &url); - if room.send(bot_reply).await.is_err() { + if room.send(bot_reply, None).await.is_err() { warn!("Failed to send embed for URL: '{}'", &url); } warn!("Ran fn room.send after: '{:#?}'", fn_start.elapsed()); @@ -157,10 +156,10 @@ pub async fn embed_handler(event: OriginalSyncRoomMessageEvent, room: Room, clie "Couldn't parse metadata for URL", "
", ) - .make_reply_to(&full_reply_event, ForwardThread::Yes, AddMentions::Yes); + .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).await.is_err() { + if room.send(bot_reply, None).await.is_err() { warn!("Failed to send embed for URL: '{}'", &url); } warn!("Ran fn room.send after: '{:#?}'", fn_start.elapsed()); diff --git a/src/lib.rs b/src/lib.rs index cf879f1..2cf40ee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,10 +2,9 @@ #![deny(missing_docs)] pub mod embeds; -use log::warn; +use log::{error, warn}; use matrix_sdk::{ config::SyncSettings, - RoomState, room::Room, ruma::{ api::client::uiaa, events::room::member::StrippedRoomMemberEvent, OwnedDeviceId, @@ -71,12 +70,12 @@ pub async fn delete_old_encryption_devices(client: &Client, config: &Config) -> // Deleting these devices needs "user interaction" or something, so we just send password again // and it works :D if let Err(e) = client.delete_devices(&old_devices, None).await { - if let Some(info) = e.as_uiaa_response() { + if let Some(info) = e.uiaa_response() { let mut password = uiaa::Password::new( - uiaa::UserIdentifier::UserIdOrLocalpart(config.username.clone()), - config.password.clone(), + uiaa::UserIdentifier::UserIdOrLocalpart(&config.username), + &config.password, ); - password.session = info.session.clone(); + password.session = info.session.as_deref(); client .delete_devices(&old_devices, Some(uiaa::AuthData::Password(password))) .await?; @@ -95,17 +94,24 @@ pub async fn reject_stale_invites(client: &Client, config: &Config) { for room in client.invited_rooms() { let room_name = room.name().unwrap_or_default(); if !room.is_space() - && !room.is_direct().await.expect("Failed to check if room is DM") + && !room.is_direct() && config.room_ids.iter().any(|r| *r == room.room_id()) { warn!("Got invite to room: '{}'", room_name); - room.join() + room.accept_invitation() .await .expect("Failed to accept invite"); - warn!("Joined room: '{}'!", room_name); + warn!("Joining room!"); + if let Err(e) = client.join_room_by_id(room.room_id()).await { + error!( + "Failed to join room with id: {} and error: {}", + room.room_id(), + e + ); + } } else { warn!("Rejecting invite to room: '{}'", room_name); - room.leave().await.unwrap_or_default(); + room.reject_invitation().await.unwrap_or_default(); } } warn!("Finished checking old invites"); @@ -129,7 +135,6 @@ pub async fn run(config: Config) -> anyhow::Result<()> { // Attempt to log into the server client - .matrix_auth() .login_username(&config.username, &config.password) .initial_device_display_name(&config.display_name) .send() @@ -160,13 +165,13 @@ pub async fn run(config: Config) -> anyhow::Result<()> { // Add handler to log new room invites as they're recieved client.add_event_handler(|ev: StrippedRoomMemberEvent, room: Room| async move { - if room.state() == RoomState::Invited { + if let Room::Invited(invited_room) = room { warn!( "Got invite to room: '{}' sent by '{}'", - room.name().unwrap_or_default(), + invited_room.name().unwrap_or_default(), ev.sender ); - }; + } }); // Add handler to detect and create embeds for HTTP links in chatCouldn't parse metadata for URL