Compare commits

..

3 Commits

Author SHA1 Message Date
SadlyNotSappho e89fcd3a62 Fix gitignore and add some broken code. 2023-01-17 15:06:27 -08:00
SadlyNotSappho 01734698d2 Add matrix-sdk crates 2023-01-17 14:16:33 -08:00
SadlyNotSappho 5d10e34027 Initialize rust project 2023-01-17 14:14:07 -08:00
3 changed files with 92 additions and 16 deletions

16
.gitignore vendored
View File

@ -14,21 +14,6 @@ Cargo.lock
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
# ---> ArchLinuxPackages
*.tar
*.tar.*
*.jar
*.exe
*.msi
*.zip
*.tgz
*.log
*.log.*
*.sig
pkg/
src/
# ---> VisualStudioCode
.vscode/*
!.vscode/settings.json
@ -70,4 +55,3 @@ Icon
Network Trash Folder
Temporary Items
.apdisk

19
Cargo.toml Normal file
View File

@ -0,0 +1,19 @@
[package]
name = "matrix-desktop"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = "4.1.1"
matrix-sdk = "0.6.2"
matrix-sdk-base = "0.6.1"
matrix-sdk-crypto = "0.6.0"
anyhow = "1"
dirs = "4.0.0"
tracing-subscriber = "0.3.15"
[dependencies.tokio]
version = "1.24.2"
features = ["full"]

73
src/main.rs Normal file
View File

@ -0,0 +1,73 @@
use clap::{arg, Command};
use matrix_sdk::{
config::SyncSettings,
room::Room,
ruma::events::room::{
member::StrippedRoomMemberEvent,
message::{MessageType, OriginalSyncRoomMessageEvent, RoomMessageEventContent},
},
Client,
};
use tokio::time::{sleep, Duration};
fn cli() -> Command {
Command::new("gaychat")
.about("a matrix client for the gays")
.allow_external_subcommands(false)
.arg(arg!(<HOMESERVER> "The homeserver your account uses."))
.arg(arg!(<USERNAME> "Your account's username.")).arg_required_else_help(true)
.arg(arg!(<PASSWORD> "Your account's password.")).arg_required_else_help(true)
}
#[tokio::main]
async fn main() -> Result<(), ()> {
tracing_subscriber::fmt::init();
let args = cli().get_matches();
let homeserver: &String = args.get_one("HOMESERVER").unwrap();
let username: &String = args.get_one("USERNAME").unwrap();
let password: &String = args.get_one("PASSWORD").unwrap();
login_and_sync(homeserver, username, password).await.unwrap();
Ok(())
}
async fn login_and_sync(
homeserver: &String,
username: &String,
password: &String
) -> anyhow::Result<()> {
let home = dirs::data_dir().expect("no home dir found").join("gaychat");
let client = Client::builder()
.homeserver_url(homeserver)
.sled_store(home, None)?
.build()
.await?;
client.login_username(username, password)
.initial_device_display_name("testing");
println!("Logged in as {username} at {homeserver}");
let sync_token = client.sync_once(SyncSettings::default()).await.unwrap().next_batch;
client.add_event_handler(on_room_message);
let settings = SyncSettings::default().token(sync_token);
client.sync(settings).await?;
Ok(())
}
async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room) {
let Room::Joined(room) = room else {return};
let MessageType::Text(text_content) = event.content.msgtype else {return};
println!("{:?}", text_content);
}