commit
d9fa06a211
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,30 @@
|
|||
[package]
|
||||
name = "mara"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
color-eyre = "0.6"
|
||||
serde_dhall = "0.11"
|
||||
serde_json = "1"
|
||||
tracing = "0.1"
|
||||
tracing-futures = "0.2"
|
||||
tracing-log = "0.1"
|
||||
tracing-subscriber = "0.2"
|
||||
|
||||
serde = { version = "1", features = [ "derive" ] }
|
||||
reqwest = { version = "0.11", features = [ "json" ] }
|
||||
tokio = { version = "1", features = [ "full" ] }
|
||||
|
||||
[dependencies.matrix-sdk]
|
||||
git = "https://github.com/matrix-org/matrix-rust-sdk"
|
||||
rev = "1563ecdf1acf52b74ebea3309e72e2f8f9e854f6"
|
||||
features = [
|
||||
"eyre",
|
||||
"qrcode",
|
||||
"encryption",
|
||||
"markdown",
|
||||
"sled_cryptostore",
|
||||
]
|
|
@ -0,0 +1,90 @@
|
|||
use color_eyre::Result;
|
||||
use matrix_sdk::{
|
||||
config::{ClientConfig, SyncSettings},
|
||||
room::Room,
|
||||
ruma::{
|
||||
events::{
|
||||
room::message::{MessageType, RoomMessageEventContent, TextMessageEventContent},
|
||||
SyncMessageEvent,
|
||||
},
|
||||
UserId,
|
||||
},
|
||||
Client,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct Config {
|
||||
username: Box<UserId>,
|
||||
password: String,
|
||||
#[serde(rename = "clientID")]
|
||||
client_id: String,
|
||||
#[serde(rename = "keysPath")]
|
||||
key_path: PathBuf,
|
||||
#[serde(rename = "storePath")]
|
||||
store_path: PathBuf,
|
||||
}
|
||||
|
||||
pub const APPLICATION_NAME: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
tracing_subscriber::fmt::init();
|
||||
color_eyre::install()?;
|
||||
let cfg: Config =
|
||||
serde_dhall::from_file(env::var("CONFIG_PATH").unwrap_or("./config.dhall".to_string()))
|
||||
.parse()?;
|
||||
|
||||
let ccfg = ClientConfig::new()
|
||||
.store_path(cfg.store_path)
|
||||
.user_agent(APPLICATION_NAME)?;
|
||||
let client = Client::new_from_user_id_with_config(&cfg.username, ccfg).await?;
|
||||
|
||||
// First we need to log in.
|
||||
client
|
||||
.login(
|
||||
cfg.username.localpart(),
|
||||
&cfg.password,
|
||||
Some(&cfg.client_id),
|
||||
Some(APPLICATION_NAME),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Ignore old messages
|
||||
client.sync_once(SyncSettings::default()).await?;
|
||||
|
||||
if cfg.key_path.exists() {
|
||||
client.import_keys(cfg.key_path, "").await?;
|
||||
}
|
||||
|
||||
client.register_event_handler(on_room_message).await;
|
||||
|
||||
// Syncing is important to synchronize the client state with the server.
|
||||
// This method will never return.
|
||||
client.sync(SyncSettings::default()).await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn on_room_message(event: SyncMessageEvent<RoomMessageEventContent>, room: Room) {
|
||||
if let Room::Joined(room) = room {
|
||||
let msg_body = match event.content.msgtype {
|
||||
MessageType::Text(TextMessageEventContent { body, .. }) => body,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
if msg_body.contains("!party") {
|
||||
let content = RoomMessageEventContent::text_plain("🎉🎊🥳 let's PARTY!! 🥳🎊🎉");
|
||||
|
||||
println!("sending");
|
||||
|
||||
// send our message to the room we found the "!party" command in
|
||||
// the last parameter is an optional transaction id which we don't
|
||||
// care about.
|
||||
room.send(content, None).await.unwrap();
|
||||
|
||||
println!("message sent");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue