Compare commits
3 Commits
d61bce3468
...
e89fcd3a62
Author | SHA1 | Date |
---|---|---|
SadlyNotSappho | e89fcd3a62 | |
SadlyNotSappho | 01734698d2 | |
SadlyNotSappho | 5d10e34027 |
|
@ -14,21 +14,6 @@ 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
|
||||||
|
@ -70,4 +55,3 @@ Icon
|
||||||
Network Trash Folder
|
Network Trash Folder
|
||||||
Temporary Items
|
Temporary Items
|
||||||
.apdisk
|
.apdisk
|
||||||
|
|
||||||
|
|
|
@ -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"]
|
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in New Issue