- Removed unused `id` and `app_state` fields from `ChatPanel`; updated constructor to accept but ignore the state, reducing memory footprint. - Switched database access in `ChatPanel` from a raw `Mutex` lock to a connection pool (`app_state.conn.get()`), improving concurrency and error handling. - Reordered and cleaned up imports in `status_panel.rs` and formatted struct fields for readability. - Updated VS Code launch configuration to pass `--noui` argument, enabling headless mode for debugging. - Bumped several crate versions in `Cargo.lock` (e.g., `bitflags` to 2.10.0, `syn` to 2.0.108, `cookie` to 0.16.2) and added the new `ashpd` dependency, aligning the project with latest library releases.
27 lines
929 B
Rust
27 lines
929 B
Rust
use crate::shared::state::AppState;
|
|
use crate::shared::models::UserSession;
|
|
use rhai::{Dynamic, Engine};
|
|
use std::thread;
|
|
use std::time::Duration;
|
|
pub fn wait_keyword(_state: &AppState, _user: UserSession, engine: &mut Engine) {
|
|
engine
|
|
.register_custom_syntax(&["WAIT", "$expr$"], false, move |context, inputs| {
|
|
let seconds = context.eval_expression_tree(&inputs[0])?;
|
|
let duration_secs = if seconds.is::<i64>() {
|
|
seconds.cast::<i64>() as f64
|
|
} else if seconds.is::<f64>() {
|
|
seconds.cast::<f64>()
|
|
} else {
|
|
return Err(format!("WAIT expects a number, got: {}", seconds).into());
|
|
};
|
|
if duration_secs < 0.0 {
|
|
return Err("WAIT duration cannot be negative".into());
|
|
}
|
|
let capped_duration = if duration_secs > 300.0 { 300.0 } else { duration_secs };
|
|
let duration = Duration::from_secs_f64(capped_duration);
|
|
thread::sleep(duration);
|
|
Ok(Dynamic::from(format!("Waited {} seconds", capped_duration)))
|
|
},
|
|
)
|
|
.unwrap();
|
|
}
|