Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade dependencies #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
999 changes: 613 additions & 386 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
graphql_client = "0.12"
graphql_client = "0.13"
once_cell = "1"
regex = "1"
axum = "0.5"
toml = "0.7"
axum = "0.6"
toml = "0.8"
tracing = "0.1"
uom = "0.34"
uom = "0.35"
serde_json = "1"
anyhow = "1"
sled = "0.34"
Expand All @@ -31,8 +31,8 @@ version = "0.11"
features = ["json"]

[dependencies.ruma]
version = "0.7"
features = ["client-api-c", "client-ext-client-api", "client-reqwest", "unstable-msc2676", "rand"]
version = "0.9"
features = ["client-api-c", "client-ext-client-api", "client-reqwest", "rand"]

[dependencies.serde]
version = "1"
Expand All @@ -44,4 +44,4 @@ features = ["signal", "macros", "rt-multi-thread"]

[dependencies.tracing-subscriber]
version = "0.3"
features = ["env-filter"]
features = ["env-filter"]
5 changes: 2 additions & 3 deletions src/services/matrix/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ impl MatrixListener {
loop {
let mut req = sync_events::v3::Request::new();
req.filter = None;
let last_sync = self
req.since = self
.storage
.get("last_sync")
.unwrap()
.map(|s| String::from_utf8(s.to_vec()).unwrap());
req.since = last_sync.as_deref();
req.full_state = false;
req.set_presence = &PresenceState::Unavailable;
req.set_presence = PresenceState::Unavailable;
req.timeout = Some(Duration::new(30, 0));

tokio::select! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ use github_search::github_search;
use group_ping::group_ping;
use link_url::link_url;
use ruma::{
events::room::message::{Relation, RoomMessageEventContent, TextMessageEventContent},
events::room::message::{
Relation, RoomMessageEventContent, RoomMessageEventContentWithoutRelation,
TextMessageEventContent,
},
RoomId, UserId,
};
use sled::Tree;
Expand All @@ -25,14 +28,14 @@ use std::convert::TryInto;
use std::time::SystemTime;
use text_expansion::text_expansion;
use tokio::sync::mpsc::Sender;
use tracing::{debug, trace, error};
use tracing::{debug, error, trace};
use unit_conversion::unit_conversion;

/// Handler for all text based non-command events
#[allow(clippy::too_many_arguments)]
pub async fn commandless_handler(
text: &TextMessageEventContent,
relates_to: Option<&Relation>,
relates_to: Option<&Relation<RoomMessageEventContentWithoutRelation>>,
sender: &UserId,
room_id: &RoomId,
storage: &mut Tree,
Expand Down Expand Up @@ -155,21 +158,23 @@ fn correction_time_cooldown(storage: &Tree, room_id: &RoomId) -> bool {
Some(v) => {
let bytes: [u8; 8] = v.to_vec().try_into().unwrap();
let old_time = u64::from_be_bytes(bytes);
let new_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs();
let new_time = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_secs();

if new_time < old_time + 300 {
true
} else {
false
}
},
None => true // Will only be None if this client has not yet corrected anyone in specified room, so return true to allow correction
}
None => true, // Will only be None if this client has not yet corrected anyone in specified room, so return true to allow correction
}

},
}
Err(e) => {
error!("Somehow unable to retrieve correction time cooldown key from database. Error is {}", e);
false // Will only be Err in truly extreme situations. Log + return false to prevent correction and thus potential spam.
}
}
}
}
6 changes: 4 additions & 2 deletions src/services/matrix/matrix_handlers/listeners/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use crate::config::MatrixListenerConfig;
use crate::messages::{MatrixInviteMessage, MatrixInviteType, MatrixMessage, MatrixMessageType};
use anyhow::bail;
use ruma::{
events::room::message::{Relation, TextMessageEventContent},
events::room::message::{
Relation, RoomMessageEventContentWithoutRelation, TextMessageEventContent,
},
RoomId, UserId,
};
use sled::Tree;
Expand All @@ -27,7 +29,7 @@ use tracing::{debug, trace};
#[allow(clippy::too_many_arguments)]
pub async fn handle_text_event(
text: &TextMessageEventContent,
relates_to: Option<&Relation>,
relates_to: Option<&Relation<RoomMessageEventContentWithoutRelation>>,
sender: &UserId,
room_id: &RoomId,
storage: &mut Tree,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ use crate::helpers::convert_unit;
use crate::messages::{MatrixMessage, MatrixMessageType};
use crate::regex::UNIT_CONVERSION;
use anyhow::bail;
use ruma::events::room::message::RoomMessageEventContent;
use ruma::{
events::room::message::{Relation, TextMessageEventContent},
events::room::message::{
Relation, RoomMessageEventContent, RoomMessageEventContentWithoutRelation,
TextMessageEventContent,
},
RoomId,
};
use tokio::sync::mpsc::Sender;
Expand All @@ -16,7 +18,7 @@ use tracing::debug;
/// Command based unit conversion handler that will parse, generate a response body, and send it
pub async fn unit_conversion_handler(
text: &TextMessageEventContent,
relates_to: Option<&Relation>,
relates_to: Option<&Relation<RoomMessageEventContentWithoutRelation>>,
room_id: &RoomId,
send: &mut Sender<MatrixMessage>,
) -> anyhow::Result<()> {
Expand Down
10 changes: 5 additions & 5 deletions src/services/matrix/matrix_handlers/responders/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub async fn send_message(
content: RoomMessageEventContent,
) -> anyhow::Result<()> {
let txn_id = TransactionId::new();
let req = send_message_event::v3::Request::new(&room_id, &txn_id, &content)
let req = send_message_event::v3::Request::new(room_id, txn_id, &content)
.context("m.room.message serialization must work")?;
client
.send_request(req)
Expand All @@ -34,8 +34,8 @@ pub async fn send_ban_message(
) -> anyhow::Result<()> {
for room_id in rooms {
debug!("Banning user {} in room {}...", user, room_id);
let mut req = ban_user::v3::Request::new(&room_id, user);
req.reason = reason.as_deref();
let mut req = ban_user::v3::Request::new(room_id, user.to_owned());
req.reason = reason.clone();
if let Err(e) = client.send_request(req).await {
error!("{:?}", e);
};
Expand All @@ -51,7 +51,7 @@ pub async fn accept_invite(
let room_id = room_id.context("Accept invite message was not provided with room_id")?;
info!("Authorized user {} invited me to room {}", sender, room_id);
client
.send_request(join_room_by_id::v3::Request::new(&room_id))
.send_request(join_room_by_id::v3::Request::new(room_id.clone()))
.await
.context("Unable to join room")?;

Expand All @@ -67,7 +67,7 @@ pub async fn reject_invite(
) -> anyhow::Result<()> {
let room_id = room_id.context("Reject invite message was not provided with room_id")?;
client
.send_request(leave_room::v3::Request::new(&room_id))
.send_request(leave_room::v3::Request::new(room_id))
.await
.context("Unable to reject invite")?;

Expand Down
17 changes: 10 additions & 7 deletions src/services/webhook/webhook_handlers/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::helpers::MatrixFormattedTextResponse;
use crate::messages::{MatrixMessage, MatrixMessageType};
use crate::services::webhook::listener::WebhookListener;
use axum::{
extract::{Extension, FromRequest, RequestParts},
http::StatusCode,
extract::{Extension, FromRequestParts},
http::{request::Parts as RequestParts, StatusCode},
Json,
};
use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId, OwnedUserId};
Expand All @@ -13,8 +13,8 @@ use std::sync::Arc;

pub async fn message(
req_token: MessageToken,
Json(message): Json<Message>,
Extension(state): Extension<Arc<WebhookListener>>,
Json(message): Json<Message>,
) -> StatusCode {
if req_token.0.eq(&state.config.token) {
let matrix_message = MatrixMessage {
Expand Down Expand Up @@ -59,12 +59,15 @@ pub struct Message {
pub struct MessageToken(String);

#[axum::async_trait]
impl<B: std::marker::Send> FromRequest<B> for MessageToken {
impl<S> FromRequestParts<S> for MessageToken {
type Rejection = StatusCode;

async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
if req.headers().contains_key("X-Webhook-Token") {
let token = req.headers().get("X-Webhook-Token").unwrap();
async fn from_request_parts(
req: &mut RequestParts,
_state: &S,
) -> Result<Self, Self::Rejection> {
if req.headers.contains_key("X-Webhook-Token") {
let token = req.headers.get("X-Webhook-Token").unwrap();
match token.to_str() {
Ok(v) => Ok(MessageToken(v.to_owned())),
Err(_) => Err(StatusCode::INTERNAL_SERVER_ERROR),
Expand Down
Loading