diff --git a/BDA_icon_64x64.png b/BDA_icon_64x64.png new file mode 100644 index 0000000..76de73e Binary files /dev/null and b/BDA_icon_64x64.png differ diff --git a/README.md b/README.md index d86e802..0ac33b9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # ByteDiceAssistant +![](/BDA_icon_64x64.png)\ An automation tool primarily made for myself (Byte Dice) but publicly available for anyone to use. It's both a Discord and Reddit bot in one program. > [!CAUTION] @@ -58,8 +59,12 @@ It is required to install all used Python modules. You can find those in [req.tx * View Channels * Embed Links -### How to run: -### Short answer for experienced people: +### Configuration: +You can find config files in the [cfg/](cfg/) folder. You can also find the default config in the [data/defaults/cfg_default.toml](data/defaults/cfg_default.toml) file, where comments are also listed.\ +**NOTE:** Some config files are automatically generated, and you will need to run the app once for them to generate. + +### How to start the program: +#### Short answer for experienced people: * Download the code. * Set the environment variables (listed above). * Restart the terminal. @@ -70,7 +75,7 @@ It is required to install all used Python modules. You can find those in [req.tx * For help, run `cargo run -- -h` or `cargo run -- --help`. * To only run the Python part, use `cargo run -- --py`, or for a better error output, `python ./src/python/main.py` -### Long answer for beginners: +#### Long answer for beginners: * Download the code (and extract it if needed). * Open a terminal. * Set the environment variables (listed above). diff --git a/src/data.rs b/src/data.rs index 9e973f7..c55c227 100644 --- a/src/data.rs +++ b/src/data.rs @@ -136,12 +136,9 @@ pub async fn read_cfg_data(data: &Data, wipe: bool) { fn generate_cfg_data() { let preset_str = fs::read_to_string(PRESET_PATH_CFG).unwrap(); - let preset_json: toml::Value = preset_str.parse().unwrap(); - - let json_str = toml::to_string_pretty(&preset_json).unwrap(); let mut file = fs::File::create(DATA_PATH_CFG).unwrap(); - file.write_all(json_str.as_bytes()).unwrap(); + file.write_all(preset_str.as_bytes()).unwrap(); } diff --git a/src/main.rs b/src/main.rs index e559eb3..79268ce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,6 +50,7 @@ use tokio::runtime::Runtime; use tokio::sync::Mutex; use websocket::send_cmd_json; +use crate::data::get_toml_mutex; use crate::schedule::Schedule; @@ -103,6 +104,7 @@ async fn main() { let args = ::parse(); let args_str = serde_json::to_string(&args).expect("Error serializing args to JSON"); unsafe { NOPING = args.noping; } + rs_println!("Fetching language file..."); data::load_lang_data(args.clone().lang); @@ -115,13 +117,13 @@ async fn main() { .map(|s| s.parse::().expect("Failed to parse ASSISTANT_OWNERS. Invalid syntax.")) .collect(); + let data = gen_data(args.clone(), own_vec_u64.clone()).await; + if args.test { println!("----- USING TEST BOT -----"); } if args.dev { println!("----- DEV MODE ENABLED -----"); } if args.dev && args.wipe { println!("----- \"DON'T WORRY ABOUT IT\" MODE ENABLED -----"); } if args.nosched { println!("----- NO SCHEDULES -----"); } - // TODO: handle if config for reddit is disabled to not start python - if args.py && !args.rs { println!("----- PYTHON ONLY MODE -----"); rs_println!("ARGS: {}", args_str); @@ -131,27 +133,34 @@ async fn main() { else if args.rs && ! args.py { println!("----- RUST ONLY MODE -----"); rs_println!("ARGS: {}", args_str); - start(args, own_vec_u64.clone()).await; + start(args, data).await; process::exit(0); } rs_println!("ARGS: {}", args_str); + let cfg = get_toml_mutex(&data.cfg).await.unwrap(); + let cfg_arr = cfg["commands"]["disabled_categories"].as_array().unwrap(); + let contains: toml::Value = "re".parse().unwrap(); + let run_py = !cfg_arr.contains(&contains); + let rt_rs = Runtime::new().unwrap(); let rt_py = Runtime::new().unwrap(); let python_args = args.clone(); let rust_args = args.clone(); + if !run_py { rs_println!("[IMPORTANT] You have disabled the \"re\" commands in the CFG. The app will not run the Python code nor the websockets to save resources!"); } + let rust = thread::spawn(move || { rt_rs.block_on(async { - websocket::start(rust_args.clone(), own_vec_u64.clone()).await; - start(rust_args, own_vec_u64).await; + if run_py { websocket::start(rust_args.clone(), own_vec_u64.clone()).await; } + start(rust_args, data).await; }); }); let python = thread::spawn(move || { rt_py.block_on(async { - let _ = python::start(python_args).await; + if run_py { let _ = python::start(python_args).await; } }); }); @@ -168,8 +177,7 @@ async fn main() { } -async fn start(args: Args, owners: Vec) { - let data = gen_data(args.clone(), owners).await; +async fn start(args: Args, data: Data) { let mut bot = gen_bot(data, args).await; rs_println!("Starting Discord bot...");