Skip to content

Commit

Permalink
Verbosify code by adding doc comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
callmeclover committed Jun 24, 2024
1 parent fb9260d commit e452b31
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 21 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## [1.0.0] - 2024-05-30
## [1.0.1] - 2024-06-24

- [x] officially support osx and linux
- [x] add doc comments

11:07:34 PM, 5/30/2024 (UTC-5)
9:52:22 AM, 6/24/2024 (UTC-5)
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ currently, there are 3 versions (not including crosses of any):

**the `advanced` feature requires administrator privileges. this is why it is seperate from `default`. it also depends on the `windows` crate, so it does not support linux/macos.**

**the `invisibility` feature has no console window, so it cannot be regularly exited out of. see [this notice](#other-little-notice) for info on killing a hidden instance.**
**the `invisibility` feature has no console window, so it cannot be regularly exited out of. you'll need to kill its process.**

i will also not be publishing any invisible or advanced builds for jerry beyond [v0.3.4](https://github.com/callmeclover/jerry/releases/tag/v0.3.4) and [v1.0.0](https://github.com/callmeclover/jerry/releases/tag/v1.0.0) respectively. build them yourself with `cargo build --features invisible` or `cargo build --features advanced`.

Expand All @@ -25,12 +25,6 @@ i will also not be publishing any invisible or advanced builds for jerry beyond

i, @callmeclover, hold 0 responsibility over what this thing does, [**especially forks**](#on-the-topic-of-forks). you are on your own if he does anything bad.

## other little notice

the invisible version hides the console window, so you need to kill his process in task manager if he gets out of hand.

he doesn't cloak himself, so his process name is `jerry.exe`.

## on the topic of forks

jerry is, technically, considered malware. as the [wiki page](https://wikipedia.com/wiki/Malware) states, _"[Malware] is any software intentionally designed to cause disruption to a computer, server, client, or computer network,"_ which is exactly what jerry does.
Expand Down
9 changes: 6 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
- [ ] testing
- [x] v1.0.0 testing
- [x] windows tests
- [ ] linux tests
- [x] linux tests
- [x] macos tests
- [ ] platform parity
- [x] windows
- [ ] linux
- [ ] macos
- [ ] macos
- [ ] verbosify code
- [x] add doc comments
- [ ] add comments everywhere else
13 changes: 9 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
use cached::proc_macro::cached;
#[allow(unused_imports)]
use dialoguer::{theme::ColorfulTheme, Confirm};
use serde::{Deserialize, Serialize};
use std::{fs, path::Path};
use toml::{de::Error, from_str, to_string_pretty};
#[cfg(not(feature = "invisibility"))]
use dialoguer::{theme::ColorfulTheme, Confirm};

#[derive(Debug, Serialize, Deserialize, Default, Clone, Eq, Hash, PartialEq)]
/// Jerry's config struct.
pub struct Config {
#[allow(dead_code)] // Disable dead code warning for the entire struct
#[allow(dead_code)]
basic: Basic,
#[allow(dead_code)] // Disable dead code warning for the entire struct
#[allow(dead_code)]
pub extra: Extra,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[allow(clippy::struct_excessive_bools)]
/// Basic options, like whether to enable keyboard inputs or not.
struct Basic {
#[allow(dead_code)]
use_mouse: bool,
Expand All @@ -34,6 +36,7 @@ struct Basic {

#[derive(Debug, Serialize, Deserialize, Default, Clone, Hash, PartialEq, Eq)]
#[allow(clippy::struct_excessive_bools)]
/// Extra options, like whether to use an external sentence api or not.
pub struct Extra {
#[allow(dead_code)]
pub do_debugging: bool,
Expand Down Expand Up @@ -67,6 +70,7 @@ impl Default for Basic {
}

#[cached]
/// Attempt to read a config file, or create one.
pub fn get_config() -> Config {
loop {
if Path::new("./config.toml").exists() {
Expand Down Expand Up @@ -129,6 +133,7 @@ pub fn get_config() -> Config {
}
}

/// Get a vector of possible inputs from a Config object.
pub fn get_options(config: &Config) -> Vec<(&'static str, usize)> {
let mut options: Vec<(&'static str, usize)> = vec![];

Expand Down
21 changes: 17 additions & 4 deletions src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ lazy_static! {
static ref IS_RCTRL_PRESSED: Mutex<bool> = Mutex::new(false);
}

/// Toggle the value of a modifier key.
fn toggle_key_press(key: Key, enigo: &mut Enigo) {
let kvalue = !*(match key {
Key::Shift => IS_SHIFT_PRESSED.lock().unwrap(),
Expand All @@ -56,6 +57,7 @@ fn toggle_key_press(key: Key, enigo: &mut Enigo) {
}
}

/// Drag the mouse to `pos`.
pub fn drag_mouse_abs(enigo: &mut Enigo, pos: (i32, i32), speed: Speed) {
let (mouse_x, mouse_y) = enigo.location().expect("Unable to locate mouse position.");

Expand All @@ -81,6 +83,7 @@ pub fn drag_mouse_abs(enigo: &mut Enigo, pos: (i32, i32), speed: Speed) {
}
}

/// Drag the mouse relatively to `pos`.
pub fn drag_mouse_rel(enigo: &mut Enigo, pos: (i32, i32), speed: Speed) {
let delta_sum = (pos.0.pow(2) + pos.1.pow(2)) as f32;
let distance = delta_sum.sqrt();
Expand All @@ -102,6 +105,7 @@ pub fn drag_mouse_rel(enigo: &mut Enigo, pos: (i32, i32), speed: Speed) {
}
}

/// Convert a string to a mouse button.
fn convert_mouse_action(input: &str) -> Option<Button> {
match input {
"left" => Some(Button::Left),
Expand All @@ -111,6 +115,7 @@ fn convert_mouse_action(input: &str) -> Option<Button> {
}
}

/// Convert an ISO timestamp to a human-readable one.
fn convert_to_human_readable(timestamp: &str) -> String {
// Parse the timestamp
let parsed_time = DateTime::parse_from_str(timestamp, "%Y-%m-%d %H:%M:%S%.f %:z")
Expand All @@ -122,6 +127,7 @@ fn convert_to_human_readable(timestamp: &str) -> String {
formatted_time
}

/// Send keyboard inputs.
fn keyboard(enigo: &mut Enigo, rng: &mut rand::rngs::ThreadRng) {
let lists: Vec<(&'static [(Key, usize)], usize)> = vec![
(ALPHANUMERIC_KEYS, 5),
Expand All @@ -141,6 +147,7 @@ fn keyboard(enigo: &mut Enigo, rng: &mut rand::rngs::ThreadRng) {
}
}

/// Send mouse inputs.
fn mouse(enigo: &mut Enigo, rng: &mut rand::rngs::ThreadRng) {
let lists: Vec<(Vec<(&str, usize)>, usize)> = vec![
(MOUSE_MOVE.to_vec(), 5),
Expand Down Expand Up @@ -299,6 +306,7 @@ fn mouse(enigo: &mut Enigo, rng: &mut rand::rngs::ThreadRng) {
}
}

/// Get a random quote from a random pool.
fn quote(tts: &mut Tts, rng: &mut rand::rngs::ThreadRng) {
let lists: Vec<(Vec<(&str, usize)>, usize)> = vec![
(QUOTES_NEGATIVE.to_vec(), 5),
Expand All @@ -325,6 +333,7 @@ fn quote(tts: &mut Tts, rng: &mut rand::rngs::ThreadRng) {
}
}

/// Generate a quote, locally.
fn quote_gen(tts: &mut Tts) {
if get_config().extra.do_debugging {
tracing::info!("quote_gen: generating sentence")
Expand All @@ -342,6 +351,7 @@ fn quote_gen(tts: &mut Tts) {
}
}

/// Generate a quote, using an external service.
async fn quote_gen_ext(tts: &mut Tts) {
if ping::ping(
std::net::IpAddr::from_str("8.8.8.8").unwrap(),
Expand Down Expand Up @@ -375,6 +385,7 @@ async fn quote_gen_ext(tts: &mut Tts) {
}
}

/// Takes a screenshot of all screens and saves them to the `./screenshots` directory.
fn screenshot(tts: &mut Tts) {
println!("hahahahah i am going to screenshot everything");
let _ = tts.speak("hahahahah i am going to screenshot everything", true);
Expand All @@ -397,6 +408,7 @@ fn screenshot(tts: &mut Tts) {
}
}

/// Function to execute actions.
pub async fn main_logic(options: &[(&str, usize)], tts: &mut Tts, enigo: &mut Enigo) {
let mut rng: rand::prelude::ThreadRng = thread_rng();

Expand All @@ -415,8 +427,8 @@ pub async fn main_logic(options: &[(&str, usize)], tts: &mut Tts, enigo: &mut En
sleep(Duration::from_millis(1500)).await;
}

#[cfg(feature = "advanced")]
#[cfg(target_os = "windows")]
#[cfg(all(feature = "advanced", target_os = "windows"))]
/// Inject gamepad inputs.
fn gamepad(gamepad: &mut GamepadInjector, rng: &mut rand::rngs::ThreadRng) {
let lists: Vec<(Vec<(&str, usize)>, usize)> = vec![
(GAMEPAD_BUTTONS.to_vec(), 5),
Expand Down Expand Up @@ -488,8 +500,8 @@ fn gamepad(gamepad: &mut GamepadInjector, rng: &mut rand::rngs::ThreadRng) {
gamepad.inject();
}

#[cfg(feature = "advanced")]
#[cfg(target_os = "windows")]
#[cfg(all(feature = "advanced", target_os = "windows"))]
/// Inject pen inputs.
fn pen(pen: &mut PenInjector, rng: &mut rand::rngs::ThreadRng) {
let lists: Vec<(Vec<(&str, usize)>, usize)> = vec![
(PEN_BUTTONS.to_vec(), 3),
Expand Down Expand Up @@ -569,6 +581,7 @@ fn pen(pen: &mut PenInjector, rng: &mut rand::rngs::ThreadRng) {
}

#[cfg(feature = "advanced")]
/// Advanced main_logic function. Used only for things like gamepad and pen support.
pub async fn main_logic_adv(
options: &[(&str, usize)],
tts: &mut Tts,
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
all(feature = "invisibility", target_os = "windows"),
windows_subsystem = "windows"
)]

// Begin allow clippy warnings

#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::cast_precision_loss)]
#![allow(clippy::cast_sign_loss)]
Expand All @@ -13,6 +15,7 @@ mod config;
mod func;
mod lists;
mod model;

use config::{get_config, get_options, Config};
use enigo::{Enigo, Settings};
#[allow(clippy::wildcard_imports)]
Expand All @@ -23,6 +26,7 @@ use std::fs::{create_dir, metadata};
use tts::Tts;

#[tokio::main]
/// Where this asshole starts.
async fn main() {
#[cfg(all(target_os = "unix", feature = "invisibility"))]
{
Expand Down

0 comments on commit e452b31

Please sign in to comment.