Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randomized responses. Mommy has all sorts of differents things to tell you~ #3

Merged
merged 2 commits into from Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
148 changes: 148 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Expand Up @@ -9,3 +9,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = { version = "0.8.5" }
serde = { version = "1.0.151", features = ["derive"] }
serde_json = "1.0.91"
10 changes: 10 additions & 0 deletions responses.json
@@ -0,0 +1,10 @@
{
"positive": [
"Good AFFECTIONATE_TERM~\nMommy's so proud of you~ ❤️",
"Awe, what a good AFFECTIONATE_TERM~\nMommy knew you could do it~ ❤️"
],
"negative": [
"Mommy knows her little AFFECTIONATE_TERM can do better~ ❤️",
"Just a little further, sweetie~ ❤️"
]
}
36 changes: 33 additions & 3 deletions src/main.rs
@@ -1,8 +1,23 @@
use rand::{rngs::StdRng, seq::SliceRandom, SeedableRng};
use serde::Deserialize;
use std::process::ExitCode;

const RESPONSES: &'static str = include_str!("../responses.json");
const AFFECTIONATE_TERM_PLACEHOLDER: &'static str = "AFFECTIONATE_TERM";

#[derive(Deserialize)]
struct Responses {
positive: Vec<String>,
negative: Vec<String>,
}

enum ResponseType {
Positive,
Negative,
}

fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
let cargo = std::env::var("CARGO")?;
let mommys_little = std::env::var("CARGO_MOMMYS_LITTLE").unwrap_or_else(|_| "girl".to_owned());
let mut arg_iter = std::env::args();
let _cargo = arg_iter.next();
let _mommy = arg_iter.next();
Expand All @@ -12,14 +27,29 @@ fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
let status = cmd.status()?;
eprintln!("\x1b[1m");
if status.success() {
eprintln!("Good {}~\nMommy's so proud of you~ ❤️", mommys_little);
eprintln!("{}", select_response(ResponseType::Positive))
} else {
eprintln!("Mommy knows her little {} can do better~ ❤️", mommys_little);
eprintln!("{}", select_response(ResponseType::Negative));
}
eprintln!("\x1b[0m");
Ok(ExitCode::from(status.code().unwrap_or(-1) as u8))
}

fn select_response(response_type: ResponseType) -> String {
let affectionate_term =
std::env::var("CARGO_MOMMYS_LITTLE").unwrap_or_else(|_| "girl".to_owned());
let mut rng = StdRng::from_entropy();
let responses: Responses = serde_json::from_str(RESPONSES).expect("RESPONSES to be valid JSON");

return match response_type {
ResponseType::Positive => responses.positive,
ResponseType::Negative => responses.negative,
}
.choose(&mut rng)
.expect("non-zero amount of responses")
.replace(AFFECTIONATE_TERM_PLACEHOLDER, &affectionate_term);
}

#[cfg(test)]
#[test]
fn test() {
Expand Down