1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/../lib/partials.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/../lib/utils.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/../config.php';
if (empty(LUA_SCRIPT_DIRECTORY)) {
http_response_code(403);
exit;
}
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) {
$script = array_find(
$scripts,
fn($x) =>
$x['name'] == $cmd_id || (isset($x['aliases']) ? in_array($cmd_id, $x['aliases']) : false)
);
if (!$script) {
http_response_code(404);
exit;
}
}
?>
<html>
<head>
<title><?= isset($script) ? "!{$script['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 $s): ?>
<p><a href="/!<?= $s['name'] ?>"
title="<?= substr($s['description_text'] ?? '', 0, 64) . (strlen($s['description_text']) > 64 ? '...' : '') ?>"><?= $s['name'] ?></a>
</p>
<?php endforeach; ?>
</div>
<?php endif; ?>
<!-- WIKI CONTENT -->
<div class="wiki-content">
<?php if (isset($script)): ?>
<h1>!<?= $script['name'] ?><a href="/!/<?= $script['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($script['delay_sec']) ?></td>
</tr>
<?php if (!empty($script['subcommands'])): ?>
<tr>
<th>Subcommands</th>
<td>
<?= implode(', ', array_map(fn($x) => "<code>$x</code>", $script['subcommands'])) ?>
</td>
</tr>
<?php endif; ?>
<?php if (!empty($script['aliases'])): ?>
<tr>
<th>Aliases</th>
<td>
<?= implode(', ', array_map(fn($x) => "<code>$x</code>", $script['aliases'])) ?>
</td>
</tr>
<?php endif; ?>
<tr>
<th>Minimal rights</th>
<td><?= $script['minimal_rights'] ?></td>
</tr>
</table>
<div>
<?php if (isset($script['description_formatted'])): ?>
<?= $script['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>
|