diff options
| author | moderndevslulw <moderndevslulw@alright.party> | 2025-07-07 04:21:48 +0500 |
|---|---|---|
| committer | moderndevslulw <moderndevslulw@alright.party> | 2025-07-07 04:21:48 +0500 |
| commit | ebc27728975cd669b7167e5631afbdf5ed2db432 (patch) | |
| tree | 5135ce75351da4f11863c374b5020324b3629012 /public | |
| parent | ee4df5bfd30a4e087331adc2b4b306286e5d419d (diff) | |
feat: show lua scripts
Diffstat (limited to 'public')
| -rw-r--r-- | public/index.php | 14 | ||||
| -rw-r--r-- | public/scripts.php | 151 | ||||
| -rw-r--r-- | public/static/img/icons/code.png | bin | 0 -> 637 bytes | |||
| -rw-r--r-- | public/static/img/icons/script.png | bin | 0 -> 1031 bytes |
4 files changed, 161 insertions, 4 deletions
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(); + } } - ?> <html> @@ -32,6 +36,8 @@ if (strlen($url['path']) > 2 && str_starts_with($url['path'], '/!')) { </div> <div class="column justify-end gap-8 p-16"> <h1 class="self-end text-right">Enhance your chat with <?= BOT_USERNAME_FORMATTED ?></h1> + + <p class="self-end text-right"> A multi-utility Twitch chat bot that brings<br> 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 @@ +<?php +include_once $_SERVER['DOCUMENT_ROOT'] . '/../lib/partials.php'; +include_once $_SERVER['DOCUMENT_ROOT'] . '/../lib/utils.php'; +include_once $_SERVER['DOCUMENT_ROOT'] . '/../vendor/autoload.php'; +include_once $_SERVER['DOCUMENT_ROOT'] . '/../config.php'; + +use Raudius\Luar\Luar; + +function parse_lua_script($value) +{ + if ($value instanceof \Raudius\Luar\Interpreter\LuarObject\Literal) { + return $value->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']); + } +} +?> +<html> + +<head> + <title><?= isset($command) ? "!{$command['name']} - Script" : 'Scripts' ?> - <?= BOT_USERNAME_FORMATTED ?></title> + <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> + <link rel="stylesheet" href="/static/style.css"> + <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon"> +</head> + +<body> + <main> + <?php html_navigation_bar() ?> + <content> + <div class="row gap-8 background-colorful p-4" style="box-shadow: 0 2px 1px rgba(0, 0, 0, 0.25);z-index:1;"> + <img src="/static/img/icons/script.png" alt=""> + <h2>Scripts</h2> + </div> + <div class="row"> + <?php if (!empty($scripts)): ?> + <!-- SIDE BAR --> + <div class="wiki-sidebar"> + <?php foreach ($scripts as $script): ?> + <p><a href="/!<?= $script['name'] ?>" + title="<?= substr($script['description_text'] ?? '', 0, 64) . (strlen($script['description_text']) > 64 ? '...' : '') ?>"><?= $script['name'] ?></a> + </p> + <?php endforeach; ?> + </div> + <?php endif; ?> + + <!-- WIKI CONTENT --> + <div class="wiki-content"> + <?php if (isset($command)): ?> + <h1>!<?= $command['name'] ?><a href="/!/<?= $command['name'] ?>.lua"><img + src="/static/img/icons/code.png" alt="[code]" title="Check the source code"></a></h1> + <table class="vertical"> + <tr> + <th>Delay</th> + <td><?= format_timestamp($command['delay_sec']) ?></td> + </tr> + <?php if (!empty($command['subcommands'])): ?> + <tr> + <th>Subcommands</th> + <td> + <?= implode(', ', array_map(fn($x) => "<code>$x</code>", $command['subcommand'])) ?> + </td> + </tr> + <?php endif; ?> + <?php if (!empty($command['aliases'])): ?> + <tr> + <th>Aliases</th> + <td> + <?= implode(', ', array_map(fn($x) => "<code>$x</code>", $command['aliases'])) ?> + </td> + </tr> + <?php endif; ?> + <tr> + <th>Minimal rights</th> + <td><?= $command['minimal_rights'] ?></td> + </tr> + </table> + <div> + <?php if (isset($command['description_formatted'])): ?> + <?= $command['description_formatted'] ?> + <?php else: ?> + <p><i>No description.</i></p> + <?php endif; ?> + </div> + <?php else: ?> + <p><i>Select a script from the list on the left.</i></p> + <?php endif; ?> + </div> + </div> + </content> + </main> + + <?php html_footer() ?> +</body> + +</html>
\ No newline at end of file diff --git a/public/static/img/icons/code.png b/public/static/img/icons/code.png Binary files differnew file mode 100644 index 0000000..cad8e96 --- /dev/null +++ b/public/static/img/icons/code.png diff --git a/public/static/img/icons/script.png b/public/static/img/icons/script.png Binary files differnew file mode 100644 index 0000000..3d9e3db --- /dev/null +++ b/public/static/img/icons/script.png |
