Skip to content

Commit

Permalink
patch quote_gen_ext
Browse files Browse the repository at this point in the history
  • Loading branch information
callmeclover committed May 2, 2024
1 parent 9bb34f2 commit 8f12cf9
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 190 deletions.
28 changes: 25 additions & 3 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "jerry"
version = "0.3.1"
version = "0.3.2"
edition = "2021"

[dependencies]
Expand All @@ -19,4 +19,5 @@ ansi_term = "0.12.1"
regex = "1.10.3"
rsautogui = "0.2.2"
reqwest = { version = "0.12.3", features = ["blocking"] }
cgisf_lib = "0.2.1"
cgisf_lib = "0.2.1"
ping = "0.5.2"
143 changes: 82 additions & 61 deletions src/libconf.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{ fs, path::Path};
use toml::{de::Error, from_str, to_string_pretty};
use ansi_term::Color;
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)]
pub struct Config {
Expand Down Expand Up @@ -43,17 +43,17 @@ impl Default for Basic {
fn default() -> Self {
Basic {
#[allow(dead_code)]
use_mouse: true,
#[allow(dead_code)]
use_keyboard: true,
#[allow(dead_code)]
use_controller: false,
#[allow(dead_code)]
do_screenshots: true,
#[allow(dead_code)]
do_tts: true,
#[allow(dead_code)]
do_gen_tts: false,
use_mouse: true,
#[allow(dead_code)]
use_keyboard: true,
#[allow(dead_code)]
use_controller: false,
#[allow(dead_code)]
do_screenshots: true,
#[allow(dead_code)]
do_tts: true,
#[allow(dead_code)]
do_gen_tts: false,
}
}
}
Expand All @@ -62,68 +62,90 @@ impl Default for Extra {
fn default() -> Self {
Extra {
#[allow(dead_code)]
do_debugging: false,
#[allow(dead_code)]
enable_debugging_extras: false,
#[allow(dead_code)]
use_external_sentence_api: false,
#[allow(dead_code)]
no_local_sentence_gen: false,
}
do_debugging: false,
#[allow(dead_code)]
enable_debugging_extras: false,
#[allow(dead_code)]
use_external_sentence_api: false,
#[allow(dead_code)]
no_local_sentence_gen: false,
}
}
}

impl Default for Config {
fn default() -> Self {
Config {
#[allow(dead_code)]
basic: Basic::default(),
#[allow(dead_code)]
extra: Extra::default()
}}}
basic: Basic::default(),
#[allow(dead_code)]
extra: Extra::default(),
}
}
}

pub async fn get_config() -> Config {
loop {
if Path::new("./config.toml").exists() {
loop {
let config_contents = fs::read_to_string("./config.toml").expect("Failed to read TOML file");
let config: Result<Config, Error> = from_str(&config_contents);
loop {
let config_contents =
fs::read_to_string("./config.toml").expect("Failed to read TOML file");
let config: Result<Config, Error> = from_str(&config_contents);

match config {
Ok(config) => {
return config;
}
Err(_err) => {
println!("{} The config file has either been incorrectly modified or has had a section removed.", Color::Red.paint("[ERR]:"));
println!("{} Resetting the config file...", Color::Blue.paint("[INFO]:"));
match config {
Ok(config) => {
return config;
}
Err(_err) => {
println!("{} The config file has either been incorrectly modified or has had a section removed.", Color::Red.paint("[ERR]:"));
println!(
"{} Resetting the config file...",
Color::Blue.paint("[INFO]:")
);

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.", Color::Green.paint("[OK]:"));
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.",
Color::Green.paint("[OK]:")
);
}
}
}
}
}
} else {
if Confirm::with_theme(&ColorfulTheme::default())
.with_prompt(format!("{} The config file can't be found, would you like to create one now?", Color::Purple.paint("[STRANGE]:")))
.wait_for_newline(true)
.interact()
.unwrap()
{
println!("{} Creating config file...", Color::Blue.paint("[INFO]:"));
} else {
if Confirm::with_theme(&ColorfulTheme::default())
.with_prompt(format!(
"{} The config file can't be found, would you like to create one now?",
Color::Purple.paint("[STRANGE]:")
))
.wait_for_newline(true)
.interact()
.unwrap()
{
println!("{} Creating config file...", Color::Blue.paint("[INFO]:"));

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");
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 created the config file.", Color::Green.paint("[OK]:"));
} else {
println!("{} Using default config file.", Color::Blue.paint("[INFO]:"));
println!("{} Using a default config is not recomended. To ignore this prompt and gain more customizability, create a dedicated config file.", Color::Yellow.paint("[WARN]:"));
return Config::default();
println!(
"{} Sucessfully created the config file.",
Color::Green.paint("[OK]:")
);
} else {
println!(
"{} Using default config file.",
Color::Blue.paint("[INFO]:")
);
println!("{} Using a default config is not recomended. To ignore this prompt and gain more customizability, create a dedicated config file.", Color::Yellow.paint("[WARN]:"));
return Config::default();
}
}
}
}
}
}

pub async fn get_options(config: Config) -> Vec<(&'static str, usize)> {
Expand All @@ -147,12 +169,11 @@ pub async fn get_options(config: Config) -> Vec<(&'static str, usize)> {
if config.basic.do_gen_tts {
if config.extra.use_external_sentence_api {
options.push(("quote_gen_ext", 5));
}
}
if !config.extra.no_local_sentence_gen {
options.push(("quote_gen", 5));
}
}


return options;
}
}
Loading

0 comments on commit 8f12cf9

Please sign in to comment.