aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 4c2c73490307d0cbf32684c93050ce5b1e35dd4f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
mod app;
pub mod event;
pub mod state;

use std::{error::Error, fs::read_to_string, path::Path};

use app::App;
use clap::Parser;
use rand::{thread_rng, Rng};

#[derive(Parser)]
struct Args {
    #[arg(short, long)]
    quote: String,
}

fn generate_quotes(path: &Path) -> Result<Vec<String>, Box<dyn Error>> {
    let mut ris = Vec::new();
    if path.is_file() {
        ris.push(read_to_string(path)?);
    } else {
        for f in path.read_dir()? {
            if f.is_err() {
                continue;
            }
            let v = f.unwrap().path();
            if v.is_file() {
                ris.push(read_to_string(v)?);
            }
        }
    }
    return Ok(ris);
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let args = Args::parse();
    let path = Path::new(&args.quote);
    let mut quotes = generate_quotes(&path).unwrap();
    let mut rng = thread_rng();
    let chosen = rng.gen_range(0..quotes.len());
    let quote = quotes.remove(chosen);
    drop(quotes);

    // TODO Add more options to choose quotes
    let mut app = App::new(quote);

    app.run().await?;
    return Ok(());
}
XMR address: 854DmXNrxULU3ZFJVs4Wc8PFhbq29RhqHhY8W6cdWrtFN3qmooKyyeYPcDzZTNRxphhJ5UzASQfAdEMwSteVqymk28aLhqj