From 23383a8a635e6a71fe0c972d942f40ad1af7f776 Mon Sep 17 00:00:00 2001 From: moderndevslulw Date: Tue, 8 Jul 2025 14:05:24 +0500 Subject: fix: build metadata for scripts only when there are changes --- public/scripts.php | 84 ++++++++++++++---------------------------------------- 1 file changed, 22 insertions(+), 62 deletions(-) (limited to 'public') diff --git a/public/scripts.php b/public/scripts.php index 0f80be4..988b4bc 100644 --- a/public/scripts.php +++ b/public/scripts.php @@ -1,79 +1,39 @@ getValue(); - } else if ($value instanceof \Raudius\Luar\Interpreter\LuarObject\Table) { - return parse_lua_script($value->getValue()); - } - - if (is_array($value)) { - $out = []; - foreach ($value as $k => $v) { - if ($k == 'handle') { - continue; - } - $out[$k] = parse_lua_script($v); - } - return $out; - } - - return $value; -} - if (empty(LUA_SCRIPT_DIRECTORY)) { http_response_code(403); exit; } -$command = null; -$scripts = []; - -// loading lua scripts -$luar = new Luar(); -$parsedown = new Parsedown(); -$file_paths = glob(LUA_SCRIPT_DIRECTORY . '/*.lua'); -foreach ($file_paths as $file_path) { - $script = file_get_contents($file_path); - - $result = $luar->eval($script); - - $script = parse_lua_script($result); - $script['description_text'] = str_replace(PHP_EOL, ' ', $script['description']); - - array_push($scripts, $script); +if (!build_script_metadata(LUA_SCRIPT_DIRECTORY)) { + http_response_code(500); + exit("Failed to build a metadata for scripts."); } +$script = null; +$scripts = json_decode(file_get_contents($_SERVER["DOCUMENT_ROOT"] . '/../scriptmetadata.json'), true); + if ($cmd_id = $_GET['id'] ?? false) { - $command = array_find( + $script = array_find( $scripts, fn($x) => $x['name'] == $cmd_id || (isset($x['aliases']) ? in_array($cmd_id, $x['aliases']) : false) ); - if (!$command) { + if (!$script) { http_response_code(404); exit; } } -if ($command) { - if (isset($command['description'])) { - $command['description_formatted'] = $parsedown->text($command['description']); - } -} ?> - <?= isset($command) ? "!{$command['name']} - Script" : 'Scripts' ?> - <?= BOT_USERNAME_FORMATTED ?> + <?= isset($script) ? "!{$script['name']} - Script" : 'Scripts' ?> - <?= BOT_USERNAME_FORMATTED ?> @@ -91,9 +51,9 @@ if ($command) {
- -

+ +

@@ -101,38 +61,38 @@ if ($command) {
- -

! +

![code]

- + - + - + - +
Delay
Subcommands - "$x", $command['subcommand'])) ?> + "$x", $script['subcommands'])) ?>
Aliases - "$x", $command['aliases'])) ?> + "$x", $script['aliases'])) ?>
Minimal rights
- - + +

No description.

-- cgit v1.2.3