diff --git a/Cargo.toml b/Cargo.toml index 87c5e8e..b0f0002 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,7 +49,7 @@ exec = ["pretty_env_logger"] search = ["tantivy"] telegram = ["exec", "search", "teloxide", "reqwest", "tokio", "md5", "rand"] discord = ["exec", "search", "serenity", "tokio", "anyhow"] -matrix = ["exec", "search", "matrix-sdk"] +matrix = ["exec", "search", "matrix-sdk", "anyhow"] [lib] diff --git a/src/matrix/main.rs b/src/matrix/main.rs new file mode 100644 index 0000000..5960d07 --- /dev/null +++ b/src/matrix/main.rs @@ -0,0 +1,29 @@ +use std::env; +use matrix_sdk::{Client}; +use matrix_sdk::config::{SyncRoomMessageEvent, SyncSettings}; + + +#[tokio::main] +async fn main() -> ! { + + let homeserver_url = env::var("MATRIX_HOMESERVER_URL") + .expect("MATRIX_HOMESERVER_URL to be defined"); + + let user_id: String = env::var("MATRIX_USER_ID") + .expect("MATRIX_USER_ID to be defined"); + let user_password: String = env::var("MATRIX_USER_PASSWORD") + .expect("MATRIX_USER_PASSWORD to be defined"); + + let client = Client::builder() + .homeserver_url(homeserver_url) + .build() + .await?; + + client.login_username(&user_id, &user_password).send().await?; + + client.add_event_handler(|ev: SyncRoomMessageEvent| async move { + println!("Received a message {:?}", ev); + }); + + client.sync(SyncSettings::default()).await; +} \ No newline at end of file diff --git a/src/matrix/mod.rs b/src/matrix/mod.rs index d25c84d..c792fb0 100644 --- a/src/matrix/mod.rs +++ b/src/matrix/mod.rs @@ -1,3 +1,5 @@ //! Module providing utilities to be used in the `patched_porobot_matrix` executable target. //! //! While adding new features to this module, remember that binaries [can only access the public API of the crate](https://doc.rust-lang.org/cargo/reference/cargo-targets.html#binaries), as they considered a separate crate from the rest of the project. + +pub(crate) mod main; \ No newline at end of file