Skip to content

Commit

Permalink
format files and edit build.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
callmeclover committed May 16, 2024
1 parent e86f9c8 commit d1f41a8
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 179 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
name = "jerry"
description = "stupid robot nuisance"
version = "0.4.0"
version = "0.4.1"
authors = ["Clover Johnson <[email protected]>"]
license = "MIT"
repository = "https://github.com/callmeclover/jerry"
build = "build.rs"
edition = "2021"

[package.metadata.winres]
LegalCopyright = "Copyright © 2024"
LegalCopyright = "Copyright © callmeclover 2024"
FileDescription = "stupid robot nuisance"

[dependencies]
Expand Down
13 changes: 8 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ fn main() {
if std::env::var("PROFILE").unwrap() == "release" {
let mut res = winres::WindowsResource::new();

res.set_icon("icon.ico")
.set_language(0x0409);
res.set_icon("icon.ico").set_language(0x0409);

if cfg!(feature = "advanced") { res.set_manifest_file("manifest_adv.xml"); }
else { res.set_manifest_file("manifest.xml"); }
if cfg!(feature = "advanced") {
res.set_manifest_file("manifest_adv.xml")
.set("InternalName", "jerry.advanced.exe");
} else {
res.set_manifest_file("manifest.xml");
}

if let Err(e) = res.compile() {
eprintln!("{}", e);
std::process::exit(1);
}
}
}
}
27 changes: 10 additions & 17 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use dialoguer::{theme::ColorfulTheme, Confirm};
use std::{fs, path::Path};
use toml::{de::Error, from_str, to_string_pretty};

#[derive(Debug, serde::Serialize, serde::Deserialize)]
#[derive(Default)]
#[derive(Debug, serde::Serialize, serde::Deserialize, Default)]
pub struct Config {
#[allow(dead_code)] // Disable dead code warning for the entire struct
basic: Basic,
Expand All @@ -30,8 +29,7 @@ struct Basic {
do_gen_tts: bool,
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
#[derive(Default)]
#[derive(Debug, serde::Serialize, serde::Deserialize, Default)]
struct Extra {
#[allow(dead_code)]
do_debugging: bool,
Expand Down Expand Up @@ -78,18 +76,14 @@ pub async fn get_config() -> Config {
}
Err(_err) => {
println!("The config file has either been incorrectly modified or has had a section removed.");
println!(
"Resetting the config file..."
);
println!("Resetting the config file...");

let new_config_contents = to_string_pretty(&Config::default())
.expect("Failed to serialize struct to TOML");
fs::write("./config.toml", new_config_contents)
.expect("Failed to write updated TOML contents");

println!(
"Sucessfully reset the config file."
);
println!("Sucessfully reset the config file.");
}
}
}
Expand All @@ -104,7 +98,10 @@ pub async fn get_config() -> Config {
#[cfg(not(feature = "invisibility"))]
{
if Confirm::with_theme(&ColorfulTheme::default())
.with_prompt("The config file can't be found, would you like to create one now?".to_string())
.with_prompt(
"The config file can't be found, would you like to create one now?"
.to_string(),
)
.wait_for_newline(true)
.interact()
.unwrap()
Expand All @@ -116,13 +113,9 @@ pub async fn get_config() -> Config {
fs::write("./config.toml", new_config_contents)
.expect("Failed to write updated TOML contents");

println!(
"Sucessfully created the config file."
);
println!("Sucessfully created the config file.");
} else {
println!(
"Using default config file."
);
println!("Using default config file.");
println!("Using a default config is not recomended. To ignore this prompt and gain more customizability, create a dedicated config file.");
return Config::default();
}
Expand Down
204 changes: 116 additions & 88 deletions src/func.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::lists::*;
#[cfg(feature = "advanced")]
use crate::{GamepadInjector,PenInjector};
use crate::{GamepadInjector, PenInjector};
use cgisf_lib::{gen_sentence, SentenceConfigBuilder};
use chrono::{prelude::*, DateTime};
use enigo::*;
Expand Down Expand Up @@ -199,10 +199,21 @@ fn quote_gen(tts: &mut Tts) {
}

async fn quote_gen_ext(tts: &mut Tts) {
if ping::ping(std::net::IpAddr::from_str("8.8.8.8").unwrap(),None,None,None,None,None).is_ok() {
let quote: &str = &reqwest::get("http://metaphorpsum.com/sentences/1/").await
if ping::ping(
std::net::IpAddr::from_str("8.8.8.8").unwrap(),
None,
None,
None,
None,
None,
)
.is_ok()
{
let quote: &str = &reqwest::get("http://metaphorpsum.com/sentences/1/")
.await
.expect("could not get external sentence api")
.text().await
.text()
.await
.unwrap();
println!("{}", quote);
let _ = tts.speak(quote, true);
Expand Down Expand Up @@ -242,94 +253,111 @@ pub async fn main_logic(options: &[(&str, usize)], tts: &mut Tts, enigo: &mut En
}

#[cfg(feature = "advanced")]
fn gamepad(gamepad: &mut GamepadInjector, rng: &mut rand::rngs::ThreadRng) {
let lists: Vec<(Vec<(&str, usize)>, usize)> = vec![
(GAMEPAD_BUTTONS.to_vec(), 5),
(GAMEPAD_MOVE.to_vec(), 3),
(GAMEPAD_SPECIAL.to_vec(), 1),
];
let index: WeightedIndex<usize> =
WeightedIndex::new(lists.iter().map(|item: &(Vec<(&str, usize)>, usize)| item.1)).unwrap();
let list: &Vec<(&str, usize)> = &lists[index.sample(rng)].0;
let index2: WeightedIndex<usize> =
WeightedIndex::new(list.iter().map(|item: &(&str, usize)| item.1)).unwrap();
let action = list[index2.sample(rng)].0;
match action {
"LeftThumbstickMove" => {
gamepad.update_left_thumbstick((rng.gen_range(-1.0..=1.0), rng.gen_range(-1.0..=1.0)));
gamepad.inject();
thread::sleep(Duration::from_millis(rng.gen_range(0..=5000)));
gamepad.update_left_thumbstick((0.0,0.0));
}
"RightThumbstickMove" => {
gamepad.update_right_thumbstick((rng.gen_range(-1.0..=1.0), rng.gen_range(-1.0..=1.0)));
gamepad.inject();
thread::sleep(Duration::from_millis(rng.gen_range(0..=5000)));
gamepad.update_right_thumbstick((0.0,0.0));
}
"LeftTrigger" => {
gamepad.update_left_trigger(rng.gen_range(0.0..=1.0));
gamepad.inject();
thread::sleep(Duration::from_millis(rng.gen_range(0..=5000)));
gamepad.update_left_trigger(0.0);
}
"RightTrigger" => {
gamepad.update_right_trigger(rng.gen_range(0.0..=1.0));
gamepad.inject();
thread::sleep(Duration::from_millis(rng.gen_range(0..=5000)));
gamepad.update_right_trigger(0.0);
}
_=>{
gamepad.toggle_button(action);
}
}
gamepad.inject();
fn gamepad(gamepad: &mut GamepadInjector, rng: &mut rand::rngs::ThreadRng) {
let lists: Vec<(Vec<(&str, usize)>, usize)> = vec![
(GAMEPAD_BUTTONS.to_vec(), 5),
(GAMEPAD_MOVE.to_vec(), 3),
(GAMEPAD_SPECIAL.to_vec(), 1),
];
let index: WeightedIndex<usize> = WeightedIndex::new(
lists
.iter()
.map(|item: &(Vec<(&str, usize)>, usize)| item.1),
)
.unwrap();
let list: &Vec<(&str, usize)> = &lists[index.sample(rng)].0;
let index2: WeightedIndex<usize> =
WeightedIndex::new(list.iter().map(|item: &(&str, usize)| item.1)).unwrap();
let action = list[index2.sample(rng)].0;
match action {
"LeftThumbstickMove" => {
gamepad.update_left_thumbstick((rng.gen_range(-1.0..=1.0), rng.gen_range(-1.0..=1.0)));
gamepad.inject();
thread::sleep(Duration::from_millis(rng.gen_range(0..=5000)));
gamepad.update_left_thumbstick((0.0, 0.0));
}
"RightThumbstickMove" => {
gamepad.update_right_thumbstick((rng.gen_range(-1.0..=1.0), rng.gen_range(-1.0..=1.0)));
gamepad.inject();
thread::sleep(Duration::from_millis(rng.gen_range(0..=5000)));
gamepad.update_right_thumbstick((0.0, 0.0));
}
"LeftTrigger" => {
gamepad.update_left_trigger(rng.gen_range(0.0..=1.0));
gamepad.inject();
thread::sleep(Duration::from_millis(rng.gen_range(0..=5000)));
gamepad.update_left_trigger(0.0);
}
"RightTrigger" => {
gamepad.update_right_trigger(rng.gen_range(0.0..=1.0));
gamepad.inject();
thread::sleep(Duration::from_millis(rng.gen_range(0..=5000)));
gamepad.update_right_trigger(0.0);
}
_ => {
gamepad.toggle_button(action);
}
}
gamepad.inject();
}

#[cfg(feature = "advanced")]
fn pen(pen: &mut PenInjector, rng: &mut rand::rngs::ThreadRng) {
let lists: Vec<(Vec<(&str, usize)>, usize)> = vec![
(PEN_BUTTONS.to_vec(), 3),
(PEN_MOVE.to_vec(), 5),
(PEN_SPECIAL.to_vec(), 1),
];
let index: WeightedIndex<usize> =
WeightedIndex::new(lists.iter().map(|item: &(Vec<(&str, usize)>, usize)| item.1)).unwrap();
let list: &Vec<(&str, usize)> = &lists[index.sample(rng)].0;
let index2: WeightedIndex<usize> =
WeightedIndex::new(list.iter().map(|item: &(&str, usize)| item.1)).unwrap();
let action = list[index2.sample(rng)].0;
match action {
"Pressure" => {
pen.update_pressure(rng.gen_range(0.0..=1024.0));
}
"Rotation" => {
pen.update_rotation(rng.gen_range(0.0..=359.0));
}
"Tilt" => {
pen.update_tilt((rng.gen_range(-90..=90), rng.gen_range(-90..=90)));
}
"XY_Move" => {
let display = Screen::from_point(0, 0).unwrap().display_info;
pen.update_position((rng.gen_range(0..=display.width).try_into().unwrap(), rng.gen_range(0..=display.height).try_into().unwrap()));
}
"X_Move" => {
let display = Screen::from_point(0, 0).unwrap().display_info;
pen.update_position((rng.gen_range(0..=display.width).try_into().unwrap(), -1));
}
"Y_Move" => {
let display = Screen::from_point(0, 0).unwrap().display_info;
pen.update_position((-1, rng.gen_range(0..=display.height).try_into().unwrap()));
}
_=>{
pen.toggle_button(action);
}
}
pen.inject();
#[cfg(feature = "advanced")]
fn pen(pen: &mut PenInjector, rng: &mut rand::rngs::ThreadRng) {
let lists: Vec<(Vec<(&str, usize)>, usize)> = vec![
(PEN_BUTTONS.to_vec(), 3),
(PEN_MOVE.to_vec(), 5),
(PEN_SPECIAL.to_vec(), 1),
];
let index: WeightedIndex<usize> = WeightedIndex::new(
lists
.iter()
.map(|item: &(Vec<(&str, usize)>, usize)| item.1),
)
.unwrap();
let list: &Vec<(&str, usize)> = &lists[index.sample(rng)].0;
let index2: WeightedIndex<usize> =
WeightedIndex::new(list.iter().map(|item: &(&str, usize)| item.1)).unwrap();
let action = list[index2.sample(rng)].0;
match action {
"Pressure" => {
pen.update_pressure(rng.gen_range(0.0..=1024.0));
}
"Rotation" => {
pen.update_rotation(rng.gen_range(0.0..=359.0));
}
"Tilt" => {
pen.update_tilt((rng.gen_range(-90..=90), rng.gen_range(-90..=90)));
}
"XY_Move" => {
let display = Screen::from_point(0, 0).unwrap().display_info;
pen.update_position((
rng.gen_range(0..=display.width).try_into().unwrap(),
rng.gen_range(0..=display.height).try_into().unwrap(),
));
}
"X_Move" => {
let display = Screen::from_point(0, 0).unwrap().display_info;
pen.update_position((rng.gen_range(0..=display.width).try_into().unwrap(), -1));
}
"Y_Move" => {
let display = Screen::from_point(0, 0).unwrap().display_info;
pen.update_position((-1, rng.gen_range(0..=display.height).try_into().unwrap()));
}
_ => {
pen.toggle_button(action);
}
}
pen.inject();
}

#[cfg(feature = "advanced")]
pub async fn main_logic_adv(options: &[(&str, usize)], tts: &mut Tts, enigo: &mut Enigo, gamepadobj: &mut GamepadInjector, penobj: &mut PenInjector) {
pub async fn main_logic_adv(
options: &[(&str, usize)],
tts: &mut Tts,
enigo: &mut Enigo,
gamepadobj: &mut GamepadInjector,
penobj: &mut PenInjector,
) {
let mut rng: rand::prelude::ThreadRng = thread_rng();

let index: WeightedIndex<usize> =
Expand All @@ -347,4 +375,4 @@ pub async fn main_logic_adv(options: &[(&str, usize)], tts: &mut Tts, enigo: &mu
}

sleep(Duration::from_millis(1500)).await;
}
}
Loading

0 comments on commit d1f41a8

Please sign in to comment.