From ebc27728975cd669b7167e5631afbdf5ed2db432 Mon Sep 17 00:00:00 2001 From: moderndevslulw Date: Mon, 7 Jul 2025 04:21:48 +0500 Subject: feat: show lua scripts --- public/index.php | 14 +++- public/scripts.php | 151 +++++++++++++++++++++++++++++++++++++ public/static/img/icons/code.png | Bin 0 -> 637 bytes public/static/img/icons/script.png | Bin 0 -> 1031 bytes 4 files changed, 161 insertions(+), 4 deletions(-) create mode 100644 public/scripts.php create mode 100644 public/static/img/icons/code.png create mode 100644 public/static/img/icons/script.png (limited to 'public') diff --git a/public/index.php b/public/index.php index 9cb267b..53cd770 100644 --- a/public/index.php +++ b/public/index.php @@ -3,12 +3,16 @@ include_once $_SERVER['DOCUMENT_ROOT'] . '/../lib/partials.php'; $url = parse_url($_SERVER['REQUEST_URI']); -if (strlen($url['path']) > 2 && str_starts_with($url['path'], '/!')) { +if (strlen($url['path']) > 2) { $page_id = substr($url['path'], 2); - header("Location: /wiki.php?p=$page_id"); - exit(); + if (str_starts_with($url['path'], '/!')) { + header("Location: /scripts.php?id=$page_id"); + exit(); + } else if (str_starts_with($url['path'], '/+')) { + header("Location: /wiki.php?id=$page_id"); + exit(); + } } - ?> @@ -32,6 +36,8 @@ if (strlen($url['path']) > 2 && str_starts_with($url['path'], '/!')) {

Enhance your chat with

+ +

A multi-utility Twitch chat bot that brings
a lot of functionality into your chat. diff --git a/public/scripts.php b/public/scripts.php new file mode 100644 index 0000000..0f80be4 --- /dev/null +++ b/public/scripts.php @@ -0,0 +1,151 @@ +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 ($cmd_id = $_GET['id'] ?? false) { + $command = array_find( + $scripts, + fn($x) => + $x['name'] == $cmd_id || (isset($x['aliases']) ? in_array($cmd_id, $x['aliases']) : false) + ); + + if (!$command) { + 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 ?> + + + + + + +

+ + +
+ +

Scripts

+
+
+ + +
+ +

+

+ +
+ + + +
+ +

![code]

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

No description.

+ +
+ +

Select a script from the list on the left.

+ +
+
+
+
+ + + + + \ No newline at end of file diff --git a/public/static/img/icons/code.png b/public/static/img/icons/code.png new file mode 100644 index 0000000..cad8e96 Binary files /dev/null and b/public/static/img/icons/code.png differ diff --git a/public/static/img/icons/script.png b/public/static/img/icons/script.png new file mode 100644 index 0000000..3d9e3db Binary files /dev/null and b/public/static/img/icons/script.png differ -- cgit v1.2.3