summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormoderndevslulw <moderndevslulw@alright.party>2025-07-07 04:21:48 +0500
committermoderndevslulw <moderndevslulw@alright.party>2025-07-07 04:21:48 +0500
commitebc27728975cd669b7167e5631afbdf5ed2db432 (patch)
tree5135ce75351da4f11863c374b5020324b3629012
parentee4df5bfd30a4e087331adc2b4b306286e5d419d (diff)
feat: show lua scripts
-rw-r--r--composer.json12
-rw-r--r--composer.lock274
-rw-r--r--lib/partials.php3
-rw-r--r--public/index.php14
-rw-r--r--public/scripts.php151
-rw-r--r--public/static/img/icons/code.pngbin0 -> 637 bytes
-rw-r--r--public/static/img/icons/script.pngbin0 -> 1031 bytes
7 files changed, 446 insertions, 8 deletions
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,9 +4,64 @@
"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",
"source": {
@@ -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()
<section class="row gap-16">
<a href="/">home</a>
<a href="/wiki.php">wiki</a>
+ <?php if (!empty(LUA_SCRIPT_DIRECTORY)): ?>
+ <a href="/scripts.php">scripts</a>
+ <?php endif; ?>
<?php if (SHOW_CHANNEL_LIST): ?>
<a href="/channels/">channels</a>
<?php endif; ?>
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>&excl;<?= $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
new file mode 100644
index 0000000..cad8e96
--- /dev/null
+++ b/public/static/img/icons/code.png
Binary files differ
diff --git a/public/static/img/icons/script.png b/public/static/img/icons/script.png
new file mode 100644
index 0000000..3d9e3db
--- /dev/null
+++ b/public/static/img/icons/script.png
Binary files differ