Update all dependencies to latest versions #18

Manually merged
froge merged 1 commit from deps-bump into master 2024-07-08 15:29:59 +00:00
3 changed files with 34 additions and 38 deletions

View file

@ -8,16 +8,16 @@ lto = "fat"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
matrix-sdk = {version = "0.6.2", features = ["anyhow", "e2e-encryption", "socks"]} matrix-sdk = {version = "0.7.1", features = ["anyhow", "e2e-encryption", "socks"]}
anyhow = "1.0.75" anyhow = "1.0.86"
clap = "4.4.6" clap = "4.5.8"
toml = "0.8.2" toml = "0.8.14"
log = "0.4.20" log = "0.4.22"
env_logger = "0.10.0" env_logger = "0.11.3"
tokio = {version = "1.32.0", features = ["parking_lot", "rt-multi-thread", "macros"]} tokio = {version = "1.38.0", features = ["parking_lot", "rt-multi-thread", "macros"]}
serde = {version = "1.0.188", features = ["derive"]} serde = {version = "1.0.204", features = ["derive"]}
tracing-subscriber = "0.3.17" tracing-subscriber = "0.3.18"
scraper = "0.17.1" scraper = "0.19.0"
reqwest = "0.11.22" reqwest = "0.12.5"
regex = "1.9.6" regex = "1.10.5"
lazy_static = "1.4.0" lazy_static = "1.5.0"

View file

@ -5,9 +5,10 @@
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, RoomMessageEventContent, MessageType, OriginalSyncRoomMessageEvent, Relation, ForwardThread, AddMentions, RoomMessageEventContent,
}, },
Client, Client,
}; };
@ -97,7 +98,7 @@ fn get_urls_from_message(message: &str) -> Vec<&str> {
pub async fn embed_handler(event: OriginalSyncRoomMessageEvent, room: Room, client: Client) { pub async fn embed_handler(event: OriginalSyncRoomMessageEvent, room: Room, client: Client) {
let fn_start = Instant::now(); let fn_start = Instant::now();
if let Room::Joined(room) = room { if room.state() == RoomState::Joined {
let full_reply_event = event.clone().into_full_event(room.room_id().to_owned()); let full_reply_event = event.clone().into_full_event(room.room_id().to_owned());
// If the sender ID matches our client, ignore the message // If the sender ID matches our client, ignore the message
@ -142,11 +143,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); .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);
if room.send(bot_reply, None).await.is_err() { if room.send(bot_reply).await.is_err() {
warn!("Failed to send embed for URL: '{}'", &url); warn!("Failed to send embed for URL: '{}'", &url);
} }
warn!("Ran fn room.send after: '{:#?}'", fn_start.elapsed()); warn!("Ran fn room.send after: '{:#?}'", fn_start.elapsed());
@ -156,10 +157,10 @@ pub async fn embed_handler(event: OriginalSyncRoomMessageEvent, room: Room, clie
"Couldn't parse metadata for URL", "Couldn't parse metadata for URL",
"<blockquote><h5>Couldn't parse metadata for URL</h5></blockquote>", "<blockquote><h5>Couldn't parse metadata for URL</h5></blockquote>",
) )
.make_reply_to(&full_reply_event); .make_reply_to(&full_reply_event, ForwardThread::Yes, AddMentions::Yes);
// Send the reply to the room // Send the reply to the room
warn!("Sending 'No metadata' embed for URL: '{}'", &url); warn!("Sending 'No metadata' embed for URL: '{}'", &url);
if room.send(bot_reply, None).await.is_err() { if room.send(bot_reply).await.is_err() {
warn!("Failed to send embed for URL: '{}'", &url); warn!("Failed to send embed for URL: '{}'", &url);
} }
warn!("Ran fn room.send after: '{:#?}'", fn_start.elapsed()); warn!("Ran fn room.send after: '{:#?}'", fn_start.elapsed());

View file

@ -2,9 +2,10 @@
#![deny(missing_docs)] #![deny(missing_docs)]
pub mod embeds; pub mod embeds;
use log::{error, 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,
@ -70,12 +71,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 // Deleting these devices needs "user interaction" or something, so we just send password again
// and it works :D // and it works :D
if let Err(e) = client.delete_devices(&old_devices, None).await { if let Err(e) = client.delete_devices(&old_devices, None).await {
if let Some(info) = e.uiaa_response() { if let Some(info) = e.as_uiaa_response() {
let mut password = uiaa::Password::new( let mut password = uiaa::Password::new(
uiaa::UserIdentifier::UserIdOrLocalpart(&config.username), uiaa::UserIdentifier::UserIdOrLocalpart(config.username.clone()),
&config.password, config.password.clone(),
); );
password.session = info.session.as_deref(); password.session = info.session.clone();
client client
.delete_devices(&old_devices, Some(uiaa::AuthData::Password(password))) .delete_devices(&old_devices, Some(uiaa::AuthData::Password(password)))
.await?; .await?;
@ -94,24 +95,17 @@ 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() && !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.accept_invitation() room.join()
.await .await
.expect("Failed to accept invite"); .expect("Failed to accept invite");
warn!("Joining room!"); warn!("Joined room: '{}'!", room_name);
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 { } else {
warn!("Rejecting invite to room: '{}'", room_name); warn!("Rejecting invite to room: '{}'", room_name);
room.reject_invitation().await.unwrap_or_default(); room.leave().await.unwrap_or_default();
} }
} }
warn!("Finished checking old invites"); warn!("Finished checking old invites");
@ -135,6 +129,7 @@ pub async fn run(config: Config) -> anyhow::Result<()> {
// Attempt to log into the server // Attempt to log into the server
client client
.matrix_auth()
.login_username(&config.username, &config.password) .login_username(&config.username, &config.password)
.initial_device_display_name(&config.display_name) .initial_device_display_name(&config.display_name)
.send() .send()
@ -165,13 +160,13 @@ pub async fn run(config: Config) -> anyhow::Result<()> {
// Add handler to log new room invites as they're recieved // Add handler to log new room invites as they're recieved
client.add_event_handler(|ev: StrippedRoomMemberEvent, room: Room| async move { client.add_event_handler(|ev: StrippedRoomMemberEvent, room: Room| async move {
if let Room::Invited(invited_room) = room { if room.state() == RoomState::Invited {
warn!( warn!(
"Got invite to room: '{}' sent by '{}'", "Got invite to room: '{}' sent by '{}'",
invited_room.name().unwrap_or_default(), room.name().unwrap_or_default(),
ev.sender ev.sender
); );
} };
}); });
// Add handler to detect and create embeds for HTTP links in chat // Add handler to detect and create embeds for HTTP links in chat