diff --git a/src/main.rs b/src/main.rs index 7e997ea..68db106 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,7 +92,7 @@ async fn main() { if args.py && !args.rs { println!("----- PYTHON ONLY MODE -----"); rs_println!("ARGS: {}", args_str); - let _ = python::start(args_str); + let _ = python::start(args); process::exit(0); } else if args.rs && ! args.py { @@ -108,7 +108,7 @@ async fn main() { rs_println!("ARGS: {}", args_str); let rt = Runtime::new().unwrap(); - let python_args = args_str; + let python_args = args.clone(); let rust_args = args.clone(); let rust = thread::spawn(move || { diff --git a/src/python.rs b/src/python.rs index 326e2dd..4dc055f 100644 --- a/src/python.rs +++ b/src/python.rs @@ -1,4 +1,5 @@ -use crate::{rs_println, errln}; +use crate::messages::send_dm; +use crate::{errln, rs_println, Args}; use std::fs; use std::ffi::CString; @@ -8,16 +9,18 @@ use pyo3::prelude::*; use pyo3::types::PyList; -pub fn start(args: String) -> PyResult<()> { +pub async fn start(args: Args) -> PyResult<()> { rs_println!("Running Python program..."); + let args_str = serde_json::to_string(&args).expect("Error serializing args to JSON"); + let slash = if cfg!(windows) { "\\" } else if cfg!(unix) { "/" } else { "" }; if slash.is_empty() { errln!("Man what kinda OS do you have? Neither unix or windows, what the hell!? I can't process this anymore, you're too weird!"); } let path = format!("{0}{1}src{1}python", env!("CARGO_MANIFEST_DIR"), slash); let code = get_code(&format!("{}{}main.py", path, slash)); - let py_args = args.replace(":true", ":True").replace(":false", ":False"); + let py_args = args_str.replace(":true", ":True").replace(":false", ":False"); let app_path = CString::new(format!("args = {}\n{}", py_args, code)).unwrap(); pyo3::prepare_freethreaded_python(); @@ -32,13 +35,23 @@ pub fn start(args: String) -> PyResult<()> { return Ok(app); }); - if from_python.is_err() { errln!("pyO3: {:?}", from_python); } + if from_python.is_err() { + let own_env = std::env::var("ASSISTANT_OWNERS").unwrap_or("0".to_string()); + let own_vec_str: Vec = own_env.split(",").map(String::from).collect(); + let own_vec_u64: Vec = own_vec_str + .iter() + .map(|s| s.parse::().expect("Failed to parse ASSISTANT_OWNERS. Invalid syntax.")) + .collect(); + + send_dm(format!("Unknown internal Python Error: {:?}", from_python), args, own_vec_u64).await; + errln!("pyO3: {:?}", from_python); + } return Ok(()); } fn get_code(path: &str) -> String { return fs::read_to_string(path) - .unwrap_or_else(|_| panic!("Failed to read Python file.\nPath: {}", path)) + .unwrap_or_else(|_| errln!("Failed to read Python file.\nPath: {}", path)) .to_string(); } diff --git a/src/websocket.rs b/src/websocket.rs index 10bda9a..eba23a3 100644 --- a/src/websocket.rs +++ b/src/websocket.rs @@ -134,7 +134,7 @@ async fn handle_message(msg: tungstenite::protocol::Message, args: Args, owners: if let Some(stripped) = text.strip_prefix("json:") { let t_json: Value = serde_json::from_str(stripped).unwrap(); if t_json.get("error").is_some() { - send_dm("Unknown internal Python error occurred!".to_string(), args, owners).await; + send_dm("Unknown internal Python error occurred: Websocket response error.".to_string(), args, owners).await; } }