From 0c9f1f377d6820087de3344895443b523442a185 Mon Sep 17 00:00:00 2001 From: Tait Hoyem Date: Fri, 11 Feb 2022 16:19:11 -0700 Subject: [PATCH] Make program 214 compliant --- melly_files.txt | 11 +++++++++++ sayings/blind.txt | 6 ++++++ sayings/generic.txt | 7 +++++++ sayings/quote.txt | 5 +++++ sayings/sex.txt | 6 ++++++ sayings/special-melly.txt | 6 ++++++ sayings/techies.txt | 3 ++- src/all_sayings.rs | 13 ++++--------- src/choose_saying.rs | 9 --------- src/get_files.rs | 8 ++++++++ src/get_lines.rs | 9 +++++++++ src/lib.rs | 7 ++++--- src/main.rs | 12 +++--------- src/ns.rs | 3 --- src/randoms.rs | 7 +++++++ src/saying_files.rs | 10 ---------- src/sayings.rs | 11 ++++------- 17 files changed, 82 insertions(+), 51 deletions(-) create mode 100644 melly_files.txt create mode 100644 sayings/blind.txt create mode 100644 sayings/generic.txt create mode 100644 sayings/quote.txt create mode 100644 sayings/sex.txt delete mode 100644 src/choose_saying.rs create mode 100644 src/get_files.rs create mode 100644 src/get_lines.rs delete mode 100644 src/ns.rs create mode 100644 src/randoms.rs delete mode 100644 src/saying_files.rs diff --git a/melly_files.txt b/melly_files.txt new file mode 100644 index 0000000..841b92b --- /dev/null +++ b/melly_files.txt @@ -0,0 +1,11 @@ +sayings/squishy.txt +sayings/love.txt +sayings/programming.txt +sayings/special-melly.txt +sayings/generic.txt +sayings/food.txt +sayings/blind.txt +sayings/sex.txt +sayings/quote.txt +sayings/music.txt +sayings/techies.txt diff --git a/sayings/blind.txt b/sayings/blind.txt new file mode 100644 index 0000000..1a1095e --- /dev/null +++ b/sayings/blind.txt @@ -0,0 +1,6 @@ +It's a good thing you do not like me for my looks! +Shove this cane up your ass! +Your energy bill will always be lower than mine. +Read my pimples, see if they speak to you! +Follow me! +Don't forget your cane, idiot! diff --git a/sayings/generic.txt b/sayings/generic.txt new file mode 100644 index 0000000..c797502 --- /dev/null +++ b/sayings/generic.txt @@ -0,0 +1,7 @@ +We should go feed eachother cheese at the beach. +Let's watch a movie, your choice! +I want to squish your face! +I want to eat you, like a cheese ball! +I want to boop your nose! +Let's go work out together! +🤍💛! diff --git a/sayings/quote.txt b/sayings/quote.txt new file mode 100644 index 0000000..2a74d56 --- /dev/null +++ b/sayings/quote.txt @@ -0,0 +1,5 @@ +"You miss 100% of the shots you don't take"--Wayne Gretzky +"Money money money money!"--Mr. Krabs +"You could make a religion out of this!"--Bill Wurtz +"Be as humble as myself."--Kenye West +"Don't be a pussy!"--Tait diff --git a/sayings/sex.txt b/sayings/sex.txt new file mode 100644 index 0000000..8a7b1be --- /dev/null +++ b/sayings/sex.txt @@ -0,0 +1,6 @@ +If you don't make love to the coconut song, have you even lived? +Lick it; suck it; twist it; pull it! +JUST DO IT! +Can prostitutes work from home? And would it be over Zoom? +"My cock is community property!" +Happy D diff --git a/sayings/special-melly.txt b/sayings/special-melly.txt index ebc55fb..5442ac7 100644 --- a/sayings/special-melly.txt +++ b/sayings/special-melly.txt @@ -1,2 +1,8 @@ Smelly Melly! belly, button +Melly, button +Free dorm food! +Let's go to Kelly's! +Let's go to the cheese store! +Let's go watch the sunset at the dock. +If I'm far away, just remember, I can't see you right now either. diff --git a/sayings/techies.txt b/sayings/techies.txt index 52a1a39..2efbae1 100644 --- a/sayings/techies.txt +++ b/sayings/techies.txt @@ -1,3 +1,4 @@ I'd like to peek at every one of your directories. unzip; strip; touch; grep; mount; fsck; yes; more; fsck; fsck; umount; clean; sleep; -Run `curl https://melody-214.tait.tech` for more info funny sayings +Run `curl https://melody-214.tait.tech` for more! +nmcli dev wifi connect tait diff --git a/src/all_sayings.rs b/src/all_sayings.rs index 3824673..89f44b0 100644 --- a/src/all_sayings.rs +++ b/src/all_sayings.rs @@ -1,11 +1,6 @@ -use lazy_static; -use crate::sayings::read_all_sayings; -use std::sync::Mutex; - +use crate::sayings::read_all_sayings as s; +use std::sync::Mutex as M; lazy_static! { - static ref SAYINGS: Mutex> = Mutex::new(read_all_sayings()); -} - -pub fn all_sayings() -> Vec { - SAYINGS.lock().expect("Error locking SAYINGS.").to_vec() +static ref SAYINGS:M> = M::new(s()); } +pub fn all_sayings()->Vec{SAYINGS.lock().expect("lock err").to_vec()} diff --git a/src/choose_saying.rs b/src/choose_saying.rs deleted file mode 100644 index 983825c..0000000 --- a/src/choose_saying.rs +++ /dev/null @@ -1,9 +0,0 @@ -extern crate rand; -use rand::thread_rng; -use crate::all_sayings::all_sayings; -use crate::choose_saying::rand::prelude::IteratorRandom; - -pub fn random_saying() -> String { - let mut rng = thread_rng(); - all_sayings().iter().choose(&mut rng).expect("Error getting random saying.").to_string() -} diff --git a/src/get_files.rs b/src/get_files.rs new file mode 100644 index 0000000..010496b --- /dev/null +++ b/src/get_files.rs @@ -0,0 +1,8 @@ +use crate::env; +use crate::get_lines; + +/// Gets the list of all files to load sayings from. +/// Panics on any kind of possible error +pub fn get_files() -> Vec { + return get_lines::get_lines(env::gcf()); +} diff --git a/src/get_lines.rs b/src/get_lines.rs new file mode 100644 index 0000000..32585fa --- /dev/null +++ b/src/get_lines.rs @@ -0,0 +1,9 @@ +use std::fs; + +pub fn get_lines(file_name: String) -> Vec { + fs::read_to_string(file_name) + .expect("Error reading some file") + .lines() + .map(|x| x.to_string()) + .collect() +} diff --git a/src/lib.rs b/src/lib.rs index 4b1b569..cf87370 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,8 @@ -pub mod saying_files; pub mod env; -pub mod ns; -pub mod choose_saying; +/// All rise and hail the great pseudo-random number generator code! +pub mod randoms; pub mod sayings; pub mod all_sayings; +pub mod get_lines; +pub mod get_files; #[macro_use] extern crate lazy_static; diff --git a/src/main.rs b/src/main.rs index f13fc22..f761dc5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,8 @@ #[macro_use] extern crate rocket; extern crate lazy_static; -use melly_valentines::choose_saying::random_saying; - +use melly_valentines::randoms::random_saying; #[get("/")] -fn a() -> String { - random_saying() -} - +fn a()->String{random_saying()} #[launch] -fn rocket() -> _ { - rocket::build().mount("/", routes![a]) -} +fn rocket()->_{rocket::build().mount("/",routes![a])} diff --git a/src/ns.rs b/src/ns.rs deleted file mode 100644 index 4473406..0000000 --- a/src/ns.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub fn new_saying() -> String { - return "Helo!".to_string(); -} diff --git a/src/randoms.rs b/src/randoms.rs new file mode 100644 index 0000000..65b0e7e --- /dev/null +++ b/src/randoms.rs @@ -0,0 +1,7 @@ +use rand::thread_rng; +use crate::all_sayings::all_sayings; +use rand::prelude::IteratorRandom; + +pub fn random_saying() ->String{ + all_sayings().iter().choose(&mut thread_rng()).expect("saying error").to_string() +} diff --git a/src/saying_files.rs b/src/saying_files.rs deleted file mode 100644 index 7dd8a6f..0000000 --- a/src/saying_files.rs +++ /dev/null @@ -1,10 +0,0 @@ -use std::fs; -use crate::env::gcf; - -pub fn get_files() -> Vec { - fs::read_to_string(gcf()) - .expect("Error reading core file") - .lines() - .map(|x| x.to_string()) - .collect() -} diff --git a/src/sayings.rs b/src/sayings.rs index 3d034bf..ebdd75c 100644 --- a/src/sayings.rs +++ b/src/sayings.rs @@ -1,9 +1,6 @@ -use crate::saying_files::get_files; +use crate::get_files::get_files; +use crate::get_lines::get_lines; -pub fn read_all_sayings() -> Vec { - get_files() - .iter() - .map(|n| n.lines().map(|l| l.to_string())) - .flatten() - .collect() +pub fn read_all_sayings()-> Vec{ + get_files().iter().map(|n| n.lines().map(|l| get_lines(l.to_string()))).flatten().flatten().collect() }