Compare commits

..

No commits in common. "e89fcd3a624d63cd7c2dde012ef7e28752d5edd1" and "d61bce34680152df4da8b52d1c8a66bc7b4b3ee3" have entirely different histories.

3 changed files with 16 additions and 92 deletions

16
.gitignore vendored
View File

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

View File

@ -1,19 +0,0 @@
[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"]

View File

@ -1,73 +0,0 @@
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);
}