aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs31
1 files changed, 12 insertions, 19 deletions
diff --git a/src/main.rs b/src/main.rs
index 0365d5b..d10b40c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,6 +5,7 @@ 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 {
@@ -12,17 +13,10 @@ struct Args {
quote_folder: String,
}
-fn generate_quotes(path: &Path) -> Result<Vec<Vec<String>>, Box<dyn Error>> {
+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)?
- .trim()
- .split_whitespace()
- .filter(|s| !s.is_empty())
- .map(|s| s.to_string())
- .collect(),
- );
+ ris.push(read_to_string(path)?);
} else {
for f in path.read_dir()? {
if f.is_err() {
@@ -30,14 +24,7 @@ fn generate_quotes(path: &Path) -> Result<Vec<Vec<String>>, Box<dyn Error>> {
}
let v = f.unwrap().path();
if v.is_file() {
- ris.push(
- read_to_string(v)?
- .trim()
- .split_whitespace()
- .filter(|s| !s.is_empty())
- .map(|s| s.to_string())
- .collect(),
- );
+ ris.push(read_to_string(v)?);
}
}
}
@@ -48,8 +35,14 @@ fn generate_quotes(path: &Path) -> Result<Vec<Vec<String>>, Box<dyn Error>> {
async fn main() -> Result<(), Box<dyn Error>> {
let args = Args::parse();
let path = Path::new(&args.quote_folder);
- let quotes = generate_quotes(&path).unwrap();
- let mut app = App::new(&quotes);
+ 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