added handling for disabling "re" commands & updated readme

This commit is contained in:
2025-06-07 16:58:51 +02:00
parent 4c21b6da4e
commit 203b7499dd
4 changed files with 25 additions and 15 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

+8 -3
View File
@@ -1,5 +1,6 @@
<!-- If for some reason you're reading this without MD formatting - please disable word-wrap for your own good. -->
# 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).
+1 -4
View File
@@ -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();
}
+16 -8
View File
@@ -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 = <Args as clap::Parser>::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::<u64>().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<u64>) {
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...");