1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-06-30 11:47:45 +00:00

Don't panic when the event file doesn't exist

This commit is contained in:
Joshua Goins 2025-06-22 09:05:54 -04:00
parent 4ba444be1f
commit d35e0830d3
2 changed files with 9 additions and 6 deletions

View file

@ -576,7 +576,7 @@ async fn client_loop(
let mut call_func = || { let mut call_func = || {
lua.scope(|scope| { lua.scope(|scope| {
let connection_data = scope let connection_data = scope
.create_userdata_ref_mut(&mut lua_player)?;; .create_userdata_ref_mut(&mut lua_player)?;
let func: Function = let func: Function =
lua.globals().get("onUnknownCommandError")?; lua.globals().get("onUnknownCommandError")?;
func.call::<()>((command_name, connection_data))?; func.call::<()>((command_name, connection_data))?;

View file

@ -17,11 +17,14 @@ impl Event {
let config = get_config(); let config = get_config();
let file_name = format!("{}/{}", &config.world.scripts_location, path); let file_name = format!("{}/{}", &config.world.scripts_location, path);
if let Err(err) = lua let result = std::fs::read(&file_name);
.load(std::fs::read(&file_name).expect("Failed to locate scripts directory!")) if let Err(err) = std::fs::read(&file_name) {
.set_name("@".to_string() + &file_name) tracing::warn!("Failed to load {}: {:?}", file_name, err);
.exec() return Self { file_name, lua, id };
{ }
let file = result.unwrap();
if let Err(err) = lua.load(file).set_name("@".to_string() + &file_name).exec() {
tracing::warn!("Syntax error in {}: {:?}", file_name, err); tracing::warn!("Syntax error in {}: {:?}", file_name, err);
return Self { file_name, lua, id }; return Self { file_name, lua, id };
} }