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 --- composer.json | 12 +- composer.lock | 274 ++++++++++++++++++++++++++++++++++++- lib/partials.php | 3 + 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 7 files changed, 446 insertions(+), 8 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 diff --git a/composer.json b/composer.json index 6c2f494..3b01c1d 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,15 @@ "email": "moderndevslulw@alright.party" } ], + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/MrMeshok/Luar" + } + ], "require": { - "erusev/parsedown": "^1.7" + "erusev/parsedown": "^1.7", + "yosymfony/toml": "^1.0", + "raudius/luar": "dev-main" } -} +} \ No newline at end of file diff --git a/composer.lock b/composer.lock index 3b7787b..9d0c972 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,63 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "55b64d5b88829d139fe1f58294be952e", + "content-hash": "3004266237a857340372a416994126c2", "packages": [ + { + "name": "antlr/antlr4-php-runtime", + "version": "0.9.1", + "source": { + "type": "git", + "url": "https://github.com/antlr/antlr-php-runtime.git", + "reference": "3afe41b19f8ea3d6b10400397712cb8181da5e25" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/antlr/antlr-php-runtime/zipball/3afe41b19f8ea3d6b10400397712cb8181da5e25", + "reference": "3afe41b19f8ea3d6b10400397712cb8181da5e25", + "shasum": "" + }, + "require": { + "ext-mbstring": "^8.0", + "php": "^8.0", + "psr/log": "^2.0 || ^3.0" + }, + "require-dev": { + "ergebnis/composer-normalize": "^2.15", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^1.4", + "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/phpstan-strict-rules": "^1.1", + "slevomat/coding-standard": "^7.0", + "squizlabs/php_codesniffer": "^3.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.2-dev" + } + }, + "autoload": { + "psr-4": { + "Antlr\\Antlr4\\Runtime\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "PHP 8.0+ runtime for ANTLR 4", + "keywords": [ + "antlr4", + "php", + "runtime" + ], + "support": { + "issues": "https://github.com/antlr/antlr-php-runtime/issues", + "source": "https://github.com/antlr/antlr-php-runtime/tree/0.9.1" + }, + "time": "2023-09-04T20:27:34+00:00" + }, { "name": "erusev/parsedown", "version": "1.7.4", @@ -55,12 +110,227 @@ "source": "https://github.com/erusev/parsedown/tree/1.7.x" }, "time": "2019-12-30T22:54:17+00:00" + }, + { + "name": "psr/log", + "version": "3.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/f16e1d5863e37f8d8c2a01719f5b34baa2b714d3", + "reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3", + "shasum": "" + }, + "require": { + "php": ">=8.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "support": { + "source": "https://github.com/php-fig/log/tree/3.0.2" + }, + "time": "2024-09-11T13:17:53+00:00" + }, + { + "name": "raudius/luar", + "version": "dev-main", + "source": { + "type": "git", + "url": "https://github.com/MrMeshok/Luar.git", + "reference": "7c39de80c35f0e0c4349e61bef9b9f6763f34ba7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/MrMeshok/Luar/zipball/7c39de80c35f0e0c4349e61bef9b9f6763f34ba7", + "reference": "7c39de80c35f0e0c4349e61bef9b9f6763f34ba7", + "shasum": "" + }, + "require": { + "antlr/antlr4-php-runtime": "^0.9.1", + "ext-json": "*" + }, + "require-dev": { + "clean/phpdoc-md": "^0.19.3", + "phpunit/phpunit": "^9.5" + }, + "default-branch": true, + "type": "library", + "autoload": { + "psr-4": { + "Raudius\\Luar\\": "src", + "Raudius\\Luar\\UnitTests\\": "tests/unit" + } + }, + "scripts": { + "test:unit": [ + "phpunit -c tests/phpunit.xml" + ], + "docs:generate": [ + "phpdoc-md" + ] + }, + "license": [ + "GPL-2.0-only" + ], + "authors": [ + { + "name": "Raul Ferreira Fuentes", + "email": "r.ferreira.fuentes@gmail.com" + } + ], + "description": "Lua interpreter written entirely in PHP", + "support": { + "source": "https://github.com/MrMeshok/Luar/tree/v0.1.5" + }, + "time": "2025-05-30T10:46:52+00:00" + }, + { + "name": "yosymfony/parser-utils", + "version": "v2.0.0", + "source": { + "type": "git", + "url": "https://github.com/yosymfony/parser-utils.git", + "reference": "00bec9a12722b21f2baf7f9db35f127e90c162c9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/yosymfony/parser-utils/zipball/00bec9a12722b21f2baf7f9db35f127e90c162c9", + "reference": "00bec9a12722b21f2baf7f9db35f127e90c162c9", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "require-dev": { + "phpunit/phpunit": "^6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "Yosymfony\\ParserUtils\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Victor Puertas", + "email": "vpgugr@gmail.com", + "homepage": "http://yosymfony.com" + } + ], + "description": "Parser utilities", + "homepage": "http://github.com/yosymfony/toml", + "keywords": [ + "lexer", + "parser" + ], + "support": { + "issues": "https://github.com/yosymfony/parser-utils/issues", + "source": "https://github.com/yosymfony/parser-utils/tree/master" + }, + "time": "2018-06-29T15:31:11+00:00" + }, + { + "name": "yosymfony/toml", + "version": "v1.0.4", + "source": { + "type": "git", + "url": "https://github.com/yosymfony/toml.git", + "reference": "bdab92ad920d0e36810a3a3e4a998d23f3498f8e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/yosymfony/toml/zipball/bdab92ad920d0e36810a3a3e4a998d23f3498f8e", + "reference": "bdab92ad920d0e36810a3a3e4a998d23f3498f8e", + "shasum": "" + }, + "require": { + "php": ">=7.1", + "yosymfony/parser-utils": "^2.0" + }, + "require-dev": { + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Yosymfony\\Toml\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Victor Puertas", + "email": "vpgugr@gmail.com", + "homepage": "http://yosymfony.com" + } + ], + "description": "A PHP parser for TOML compatible with specification 0.4.0", + "homepage": "http://github.com/yosymfony/toml", + "keywords": [ + "mojombo", + "parser", + "toml" + ], + "support": { + "issues": "https://github.com/yosymfony/toml/issues", + "source": "https://github.com/yosymfony/toml/tree/master" + }, + "time": "2018-08-08T15:08:14+00:00" } ], "packages-dev": [], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": { + "raudius/luar": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": {}, diff --git a/lib/partials.php b/lib/partials.php index d7b7127..87fd7af 100644 --- a/lib/partials.php +++ b/lib/partials.php @@ -13,6 +13,9 @@ function html_navigation_bar()
home wiki + + scripts + channels 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