From 70f5fe96df2b8cd1ddc3192398eaffeb2eb33c9e Mon Sep 17 00:00:00 2001
From: "Rob Swindell (on Debian Linux)" <rob@synchro.net>
Date: Fri, 21 Jul 2023 12:37:16 -0700
Subject: [PATCH] js.exec() expects a full path to the script, normally

There's a weird issue where the scope-walk to find a "js.exec_dir" isn't
working (for Nick Young or Nightfox) after invoking DDMsgReader. This should
fix (or work around) that issue.

And js.exec() doesn't search the mods_dir first when a full script path isn't
passed, so with this change, child scripts that are in the mods_dir should now
work as a sysop would expect.
---
 exec/default.js | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/exec/default.js b/exec/default.js
index 76aadc4cd0..65abebeb38 100755
--- a/exec/default.js
+++ b/exec/default.js
@@ -195,7 +195,10 @@ while(bbs.online && !js.terminated) {
 		cmd = console.getstr();
 		if(cmd == '!')
 			cmd = last_str_cmd;
-		js.exec("str_cmds.js", {}, cmd);
+		var script = system.mods_dir + "str_cmds.js";
+		if(!file_exists(script))
+			script = system.exec_dir + "str_cmds.js";
+		js.exec(script, {}, cmd);
 		last_str_cmd = cmd;
 		continue;
 	}
@@ -243,10 +246,13 @@ while(bbs.online && !js.terminated) {
 		if(menu_cmd.eval)
 			eval(menu_cmd.eval);
 		if(menu_cmd.exec) {
+			var script = system.mods_dir + menu_cmd.exec;
+			if(!file_exists(script))
+				script = system.exec_dir + menu_cmd.exec;
 			if(menu_cmd.args)
-				js.exec.apply(null, [menu_cmd.exec, {}].concat(menu_cmd.args));
+				js.exec.apply(null, [script, {}].concat(menu_cmd.args));
 			else
-				js.exec(menu_cmd.exec, {});
+				js.exec(script, {});
 		}
 	}
 }
-- 
GitLab