extern crate elefren; use std::error::Error; use clap::Parser; use elefren::prelude::*; use elefren::helpers::toml; use elefren::helpers::cli; use elefren::entities::event::Event; use eggbug::{Client, Post}; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] struct Args { /// URL of the mastodon instance you're using #[arg(short, long, required = true)] instance: String, /// Cohost e-mail #[arg(short, long, required = true)] email: String, /// Cohost password #[arg(short, long, required = true)] password: String, } #[tokio::main] async fn main() -> Result<(), Box> { let args = Args::parse(); let mastodon = if let Ok(data) = toml::from_file("mastodon-data.toml") { Mastodon::from(data) } else { register(&args.instance)? }; // Good! We're now logged into mastodon, check that it worked mastodon.verify_credentials()?; // Now log into Cohost let cohost = Client::new(); let cohost = cohost.login(&args.email, &args.password).await?; // Now loop over events as they come for event in mastodon.streaming_user()? { match event { } } Ok(()) } fn register(instance: &str) -> Result> { let registration = Registration::new(instance) .client_name("northbound-train") .build()?; let mastodon = cli::authenticate(registration)?; // Save app data for using on the next run. toml::to_file(&*mastodon, "mastodon-data.toml")?; Ok(mastodon) }