hotfixes & QOL

This commit is contained in:
2025-06-14 14:09:46 +02:00
parent e53b5ba677
commit 2a951723b1
10 changed files with 98 additions and 61 deletions
+23 -6
View File
@@ -23,19 +23,30 @@ pub async fn start(args: Args) -> PyResult<()> {
let py_args = args_str.replace(":true", ":True").replace(":false", ":False");
let app_path = CString::new(format!("args = {}\n{}", py_args, code)).unwrap();
let mut traceback: String = String::new();
let mut is_error = false;
pyo3::prepare_freethreaded_python();
let from_python = Python::with_gil(|py| -> PyResult<Py<PyAny>> {
let _ = Python::with_gil(|py| -> Result<(), PyErr> {
let syspath = py.import("sys")?.getattr("path")?.downcast_into::<PyList>()?;
syspath.insert(0, path)?;
let empty = CString::new("").unwrap();
let app: Py<PyAny> = PyModule::from_code(py, &app_path, &empty, &empty)?.into();
let py_result = PyModule::from_code(py, &app_path, &empty, &empty);
return Ok(app);
if let Err(ref e) = py_result {
traceback = py.import("traceback")?
.call_method1("format_exception", (e.get_type(py), e.value(py), e.traceback(py)))?
.extract::<Vec<String>>()?
.join("");
is_error = true;
}
return Ok(());
});
if from_python.is_err() {
if is_error {
let own_env = std::env::var("ASSISTANT_OWNERS").unwrap_or("0".to_string());
let own_vec_str: Vec<String> = own_env.split(",").map(String::from).collect();
let own_vec_u64: Vec<u64> = own_vec_str
@@ -43,9 +54,15 @@ pub async fn start(args: Args) -> PyResult<()> {
.map(|s| s.parse::<u64>().expect("Failed to parse ASSISTANT_OWNERS. Invalid syntax."))
.collect();
send_dm(lang!("dc_msg_dm_python_err", format!("{:?}", from_python)), args, own_vec_u64).await;
errln!("pyO3: {:?}", from_python);
send_dm(
lang!("dc_msg_dm_python_err", format!("{}", traceback)),
args,
own_vec_u64
).await;
errln!("pyO3: {}", traceback);
}
return Ok(());
}