Forward images to Matrix
parent
4f9e2f5b5c
commit
e0731c2df3
|
@ -1694,6 +1694,8 @@ dependencies = [
|
|||
"kuchiki",
|
||||
"log",
|
||||
"matrix-sdk",
|
||||
"mime_guess",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serenity",
|
||||
|
@ -2019,9 +2021,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.11.4"
|
||||
version = "0.11.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "246e9f61b9bb77df069a947682be06e31ac43ea37862e244a69f177694ea6d22"
|
||||
checksum = "66d2927ca2f685faf0fc620ac4834690d29e7abb153add10f5812eef20b5e280"
|
||||
dependencies = [
|
||||
"base64 0.13.0",
|
||||
"bytes 1.1.0",
|
||||
|
@ -3204,8 +3206,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "5e68338db6becec24d3c7977b5bf8a48be992c934b5d07177e3931f5dc9b076c"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"wasm-bindgen-macro",
|
||||
]
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ html-escape = "0.2.9"
|
|||
html5ever = "0.25.1"
|
||||
kuchiki = "0.8.1"
|
||||
serde_json = "1.0.68"
|
||||
mime_guess = "2.0.3"
|
||||
reqwest = { version = "0.11.6", features = ["blocking"] }
|
||||
|
||||
[dependencies.serenity]
|
||||
version = "0.10.9"
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
discord::{
|
||||
self, delete_on_discord, edit_on_discord, forward_image_to_discord, forward_to_discord,
|
||||
},
|
||||
matrix::{self, delete_on_matrix, edit_on_matrix, forward_to_matrix},
|
||||
matrix::{self, delete_on_matrix, edit_on_matrix, forward_image_to_matrix, forward_to_matrix},
|
||||
messages::{DeletedMessage, EditedMessage, MessageReference, SentImageMessage, SentMessage},
|
||||
};
|
||||
|
||||
|
@ -296,8 +296,12 @@ impl Bridgers {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(_matrix) = self.matrix.lock().unwrap().borrow().as_ref() {
|
||||
if let Some(_room_id) = self.get_linked_matrix_room(&message.source) {}
|
||||
if let Some(matrix) = self.matrix.lock().unwrap().borrow().as_ref() {
|
||||
if let Some(room_id) = self.get_linked_matrix_room(&message.source) {
|
||||
if let Some(m) = forward_image_to_matrix(matrix, room_id, &message).await {
|
||||
related_messages.push(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.store_related_messages(&related_messages);
|
||||
|
|
|
@ -343,6 +343,34 @@ pub async fn forward_to_matrix(
|
|||
None
|
||||
}
|
||||
|
||||
pub async fn forward_image_to_matrix(
|
||||
client: &Client,
|
||||
room_id: RoomId,
|
||||
message: &SentImageMessage,
|
||||
) -> Option<MessageReference> {
|
||||
if let Some(room) = client.get_joined_room(&room_id) {
|
||||
let image_url = message.image_url.clone();
|
||||
let mut response = tokio::task::spawn_blocking(|| reqwest::blocking::get(image_url).ok())
|
||||
.await
|
||||
.ok()
|
||||
.flatten()?;
|
||||
|
||||
let event = room
|
||||
.send_attachment(
|
||||
&message.image_url,
|
||||
&mime_guess::from_path(&message.image_url).first_or_octet_stream(),
|
||||
&mut response,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.ok()?;
|
||||
|
||||
return Some(MessageReference::from((&room_id, &event.event_id)));
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub async fn edit_on_matrix(
|
||||
client: &Client,
|
||||
room_id: RoomId,
|
||||
|
|
Loading…
Reference in New Issue