CLAK4UEUG4QMNZVXFSS7GOQ3SV5FA24C3WVHPPD53RQDHKNKRD3QC
async fn hello_world(
homeserver_url: Uri,
username: &str,
password: &str,
room_alias: &RoomAliasId,
) -> anyhow::Result<()> {
let client = Client::new(homeserver_url, None);
client.log_in(username, password, None, Some("ruma-example-client")).await?;
#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
let config_path = match env::args_os().nth(1) {
Some(x) => x,
None => {
eprintln!("Usage: {} <config path>", env::args().next().unwrap());
exit(1)
}
};
let room_id = client.request(get_alias::Request::new(room_alias)).await?.room_id;
client.request(join_room_by_id::Request::new(&room_id)).await?;
let config: config::Config =
toml::from_slice(&fs::read(config_path).context("reading config")?)
.context("parsing config")?;
let client = Client::new(config.homeserver, None);
for room_alias in &config.rooms {
let room_id = client
.request(get_alias::Request::new(room_alias))
.await?
.room_id;
client
.request(join_room_by_id::Request::new(&room_id))
.await?;
client
.request(send_message_event::Request::new(
&room_id,
"1",
&AnyMessageEventContent::RoomMessage(MessageEventContent::text_plain(
"Hello World!",
)),
))
.await?;
}
#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
let (homeserver_url, username, password, room) =
match (env::args().nth(1), env::args().nth(2), env::args().nth(3), env::args().nth(4)) {
(Some(a), Some(b), Some(c), Some(d)) => (a, b, c, d),
_ => {
eprintln!(
"Usage: {} <homeserver_url> <username> <password> <room>",
env::args().next().unwrap()
);
exit(1)
}
};
hello_world(
homeserver_url.parse()?,
&username,
&password,
&RoomAliasId::try_from(room.as_str())?,
)
.await
}
use serde::Deserialize;
use ruma::RoomAliasId;
#[derive(Deserialize)]
pub struct Config {
#[serde(with = "http_serde::uri")]
pub homeserver: http::Uri,
pub username: String,
pub password: String,
pub rooms: Vec<RoomAliasId>,
pub idle_days: f32,
pub reason: String,
}
serde = { version = "1.0.123", features = ["derive"] }
toml = "0.5.8"
http-serde = "1.0"