From 2ba8e46abe16fabd716b671308ee6650838185e1 Mon Sep 17 00:00:00 2001 From: Ethan Water Date: Mon, 10 Apr 2023 15:15:54 -0400 Subject: [PATCH] Rust implementation Rust implementation of fucking_coffee, hangover, and smack_my_bitch_up --- rust/dependencies.txt | 9 +++++++ rust/fucking_coffee.rs | 37 ++++++++++++++++++++++++++ rust/hangover.rs | 55 +++++++++++++++++++++++++++++++++++++++ rust/smack_my_bitch_up.rs | 53 +++++++++++++++++++++++++++++++++++++ 4 files changed, 154 insertions(+) create mode 100644 rust/dependencies.txt create mode 100644 rust/fucking_coffee.rs create mode 100644 rust/hangover.rs create mode 100644 rust/smack_my_bitch_up.rs diff --git a/rust/dependencies.txt b/rust/dependencies.txt new file mode 100644 index 0000000..5ed126b --- /dev/null +++ b/rust/dependencies.txt @@ -0,0 +1,9 @@ +smack_my_bitch_up + hangover +-rand = "0.8.5" +-dotenv = "0.15.0" +-openapi = { path = "./twilio-rust" } +-tokio = { version = "1.21.1", features = ["rt", "rt-multi-thread", "macros"] } + +fucking_coffee +-pure rust + diff --git a/rust/fucking_coffee.rs b/rust/fucking_coffee.rs new file mode 100644 index 0000000..e8ee76d --- /dev/null +++ b/rust/fucking_coffee.rs @@ -0,0 +1,37 @@ +use std::{ + io::{Read, Write}, + net::TcpStream, + process::Command, + thread, + time::Duration, +}; + +const COFFEE_MACHINE_IP: &str = "10.10.42.42:23"; +const COFFEE_MACHINE_PASSWORD: &str = "1234"; + +fn main() -> std::io::Result<()> { + //Exit early if no sessions with my username are found + let users = Command::new("who").output().unwrap(); + let is_active = String::from_utf8_lossy(&users.stdout) + .split('\n') + .any(|line| line.starts_with("username")); + if !is_active { + std::process::exit(0); + } + + //Brew fucking coffee + let delay_before_brew = Duration::from_secs(17); + let delay = Duration::from_secs(24); + + thread::sleep(delay_before_brew); + let mut conn = TcpStream::connect(COFFEE_MACHINE_IP)?; + + conn.write_all(COFFEE_MACHINE_PASSWORD.as_bytes())?; + conn.read_exact(&mut [0u8; 1024])?; + conn.write_all(b"sys brew")?; + + thread::sleep(delay); + conn.write_all(b"sys pour")?; + + Ok(()) +} diff --git a/rust/hangover.rs b/rust/hangover.rs new file mode 100644 index 0000000..3f423ba --- /dev/null +++ b/rust/hangover.rs @@ -0,0 +1,55 @@ +use std::{env, process::Command}; +use dotenv::dotenv; +use rand::seq::SliceRandom; +use openapi::apis::{ + configuration::Configuration, + default_api::{self as twilio_api, CreateMessageParams}, +}; + +#[tokio::main] +async fn main() { + dotenv().expect("Error reading .env file"); + let my_number = env::var("MY_NUMBER").expect("oof"); + let boss_number = env::var("BOSSES_NUMBER").unwrap(); + let api_key_sid = env::var("API_KEY_SID").unwrap(); + let api_key_secret = env::var("API_KEY_SECRET").unwrap(); + let account_sid = env::var("ACCOUNT_SID").unwrap(); + + //Exit early if no sessions with my username are found + let users = Command::new("who").output().unwrap(); + let is_active = String::from_utf8_lossy(&users.stdout) + .split('\n') + .any(|line| line.starts_with("username")); + if !is_active { + std::process::exit(0); + } + + //Create message + let reasons: Vec<&str> = vec!["Locked out", + "Pipes broke", + "Food poisoning", + "Not feeling well"]; + let random_reason = reasons.choose(&mut rand::thread_rng()).unwrap(); + let message = format!("Gonna work from home. {}", random_reason); + + + //Send a text message + let twilio_config = Configuration { + basic_auth: Some((api_key_sid, Some(api_key_secret))), + ..Default::default() + }; + + let msg_params = CreateMessageParams { + account_sid, + to: my_number, + from: Some(boss_number), + body: Some(msg.into()), + ..Default::default() + }; + + let send_msg = twilio_api::create_message(&twilio_config, msg_params).await; + match send_msg { + Ok(result) => result, + Err(error) => panic!("Error sending message: {}", error), + }; +} diff --git a/rust/smack_my_bitch_up.rs b/rust/smack_my_bitch_up.rs new file mode 100644 index 0000000..2742340 --- /dev/null +++ b/rust/smack_my_bitch_up.rs @@ -0,0 +1,53 @@ +use std::{env, process::Command}; +use dotenv::dotenv; +use rand::seq::SliceRandom; +use openapi::apis::{ + configuration::Configuration, + default_api::{self as twilio_api, CreateMessageParams}, +}; + +#[tokio::main] +async fn main() { + dotenv().expect("Error reading .env file"); + let my_number = env::var("MY_NUMBER").expect("oof"); + let her_number = env::var("HER_NUMBER").unwrap(); + let api_key_sid = env::var("API_KEY_SID").unwrap(); + let api_key_secret = env::var("API_KEY_SECRET").unwrap(); + let account_sid = env::var("ACCOUNT_SID").unwrap(); + + //Exit early if no sessions with my username are found + let users = Command::new("who").output().unwrap(); + let is_active = String::from_utf8_lossy(&users.stdout) + .split('\n') + .any(|line| line.starts_with("username")); + if !is_active { + std::process::exit(0); + } + + //Create message + let reasons: Vec<&str> = vec!["Working hard", + "Gotta ship this feature", + "Someone fucked the system again"]; + let random_reason: &str = reasons.choose(&mut rand::thread_rng()).unwrap(); + let msg = format!("Late at work. {}", random_reason); + + //Send a text message + let twilio_config = Configuration { + basic_auth: Some((api_key_sid, Some(api_key_secret))), + ..Default::default() + }; + + let msg_params = CreateMessageParams { + account_sid, + to: my_number, + from: Some(her_number), + body: Some(msg.into()), + ..Default::default() + }; + + let send_msg = twilio_api::create_message(&twilio_config, msg_params).await; + match send_msg { + Ok(result) => result, + Err(error) => panic!("Error sending message: {}", error), + }; +}