diff --git a/src/main.rs b/src/main.rs index 69fd918..9b2a295 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,9 +8,9 @@ use matrix_sdk::{ Client, Room, RoomState, }; -use rumqttc::{MqttOptions, AsyncClient, QoS}; -use std::time::Duration; +use rumqttc::{AsyncClient, MqttOptions, QoS}; use std::thread; +use std::time::Duration; async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room) { if room.state() != RoomState::Joined { @@ -21,18 +21,28 @@ async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room) { }; if text_content.body.contains("!party") { - // mosquitto_pub -h mqtt.chaospott.de -t foobar/oben/licht -m "baellebad,100" - let mut mqttoptions = MqttOptions::new("rumqtt-sync", "mqtt.chaospott.de", 1883); + let mut mqttoptions = MqttOptions::new("rumqtt-sync", "localhost", 1883); mqttoptions.set_keep_alive(Duration::from_secs(5)); let (mut client, mut eventloop) = AsyncClient::new(mqttoptions, 10); - if let Ok(resp) = client.publish("foobert/willwas", QoS::AtLeastOnce, false, vec![3; 3]).await { + let payload = "testtesttest"; + + if let Ok(resp) = client + .publish( + "foobert/willwas", + QoS::AtLeastOnce, + true, + payload.as_bytes(), + ) + .await + { println!("{:?}", resp) + } else { + println!("fuckit") } - else { println!("fuckit") } let content = RoomMessageEventContent::text_plain("🎉🎊🥳 let's PARTY!! 🥳🎊🎉"); @@ -53,7 +63,11 @@ async fn login_and_sync( // Note that when encryption is enabled, you should use a persistent store to be // able to restore the session with a working encryption setup. // See the `persist_session` example. - let client = Client::builder().homeserver_url(homeserver_url).build().await.unwrap(); + let client = Client::builder() + .homeserver_url(homeserver_url) + .build() + .await + .unwrap(); client .matrix_auth() .login_username(&username, &password) @@ -79,8 +93,6 @@ async fn login_and_sync( Ok(()) } - - #[tokio::main] async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); @@ -99,4 +111,4 @@ async fn main() -> anyhow::Result<()> { login_and_sync(homeserver_url, username, password).await?; Ok(()) -} \ No newline at end of file +}