summaryrefslogtreecommitdiff
path: root/pages/parser.inc
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-10-10 20:51:39 +0200
committerMinteck <contact@minteck.org>2022-10-10 20:51:39 +0200
commit108525534c28013cfe1897c30e4565f9893f3766 (patch)
treedd3e5132971f96ab5f05e7f3f8f6dbbf379a19bd /pages/parser.inc
parent2162eaa06f7e4764eb3dcfe130ec2c711d0c62ab (diff)
downloadpluralconnect-108525534c28013cfe1897c30e4565f9893f3766.tar.gz
pluralconnect-108525534c28013cfe1897c30e4565f9893f3766.tar.bz2
pluralconnect-108525534c28013cfe1897c30e4565f9893f3766.zip
Update
Diffstat (limited to 'pages/parser.inc')
-rw-r--r--pages/parser.inc255
1 files changed, 255 insertions, 0 deletions
diff --git a/pages/parser.inc b/pages/parser.inc
new file mode 100644
index 0000000..dc07744
--- /dev/null
+++ b/pages/parser.inc
@@ -0,0 +1,255 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn;
+require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.inc';
+
+?>
+
+<br>
+<div class="container">
+ <div id="page-content">
+ <h2>Message parser</h2>
+ <p>Enter a message here, and we will tell you which system member this message came from.</p>
+
+ <div style="display:grid;grid-template-columns:1fr 2fr;grid-gap:10px;">
+ <select id="system" title="Existing prefixes from..." class="tooltip-nohelp form-select" style='color:white;background-color:#111;border-color:#222;background-image:url("data:image/svg+xml,%3csvg xmlns=&apos;http://www.w3.org/2000/svg&apos; viewBox=&apos;0 0 16 16&apos;%3e%3cpath fill=&apos;none&apos; stroke=&apos;%23ffffff&apos; stroke-linecap=&apos;round&apos; stroke-linejoin=&apos;round&apos; stroke-width=&apos;2&apos; d=&apos;M2 5l6 6 6-6&apos;/%3e%3c/svg%3e");' onchange="update();">
+ <option value="all">(all systems)</option>
+ <option value="cloudburst">Cloudburst System</option>
+ <option value="raindrops">Raindrops System</option>
+ </select>
+ <span contenteditable="true" title="Message" class="tooltip-nohelp form-control" id="message" style="word-break: break-all;color:white;background:#111;border-color:#222;" onchange="update();" onkeydown="update();" onkeyup="update();"><span></span></span>
+ <script>
+ const input = document.getElementById('message');
+
+ input.addEventListener('keypress', (e) => {
+ if (e.code === "Enter") e.preventDefault();
+ });
+ </script>
+ </div>
+
+ <br>
+
+ <div id="result-cloudburst-outer" style="width: max-content;padding: 10px;background: #151515;border-radius: 30px;text-align: center;">
+ <span style="display:block;margin-bottom:7px;font-weight: bold;">Cloudburst System</span>
+ <div id="result-cloudburst" style="background: #222;width: max-content;border-radius: 999px;display: grid;padding: 10px 20px 10px 10px;grid-template-columns: 36px 1fr;grid-gap: 10px;">
+ <div style="align-items: center;justify-content: center;display: flex;">
+ <img src="" alt="" style="width: 36px;height: 36px;vertical-align: middle;border-radius: 999px;background: #333;" id="result-cloudburst-avatar">
+ </div>
+ <div style="display: flex;align-items: center;justify-content: center;">
+ <div>
+ <span style="font-weight: bold;" id="result-cloudburst-name">Name</span>
+ <span style="padding-left: 2px;">(<code id="result-cloudburst-prefix">Prefix</code>)</span>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div id="result-raindrops-outer" style="margin-top:10px;width: max-content;padding: 10px;background: #151515;border-radius: 30px;text-align: center;">
+ <span style="display:block;margin-bottom:7px;font-weight: bold;">Raindrops System</span>
+ <div id="result-raindrops" style="background: #222;width: max-content;border-radius: 999px;display: grid;padding: 10px 20px 10px 10px;grid-template-columns: 36px 1fr;grid-gap: 10px;">
+ <div style="align-items: center;justify-content: center;display: flex;">
+ <img src="" alt="" style="width: 36px;height: 36px;vertical-align: middle;border-radius: 999px;background: #333;" id="result-raindrops-avatar">
+ </div>
+ <div style="display: flex;align-items: center;justify-content: center;">
+ <div>
+ <span style="font-weight: bold;" id="result-raindrops-name">Name</span>
+ <span style="padding-left: 2px;">(<code id="result-raindrops-prefix">Prefix</code>)</span>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <br>
+ <div id="host-alert" class="alert alert-secondary">
+ The entered message does not contain a prefix/suffix corresponding to a member of the selected system(s); therefore, the most common fronter was selected as a fallback. While the most common fronter is supposed to use their prefix too, we assume they are talking when there is no prefix/suffix in the current message.
+ </div>
+
+ <script>
+ function setCursor(pos) {
+ let el = document.getElementById("message");
+ let selection = window.getSelection();
+ let range = document.createRange();
+
+ selection.removeAllRanges();
+ range.selectNodeContents(el);
+ range.collapse(false);
+ selection.addRange(range);
+ el.focus();
+ }
+
+ let existing = <?php
+
+ $existing1 = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc/members.json"), true);
+ $existing2 = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/members.json"), true);
+
+ echo(json_encode([
+ "cloudburst" => $existing1,
+ "raindrops" => $existing2
+ ]));
+
+ ?>;
+
+ let host = {
+ raindrops: "<?php
+
+ $members = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/members.json"), true);
+ foreach ($members as $member) {
+ if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json")) continue;
+
+ $data = parseMetadata(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json"), true));
+ if ($data["host"]) {
+ echo $member['id'];
+ }
+ }
+
+ ?>",
+ cloudburst: "<?php
+
+ $members = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc/members.json"), true);
+ foreach ($members as $member) {
+ if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json")) continue;
+
+ $data = parseMetadata(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json"), true));
+ if ($data["host"]) {
+ echo $member['id'];
+ }
+ }
+
+ ?>",
+ }
+
+ function update() {
+ let data;
+ let member;
+ let system = document.getElementById("system").value;
+ let text = document.getElementById("message").innerText;
+
+ switch (system) {
+ case "all":
+ document.getElementById("result-raindrops-outer").style.display = "";
+ document.getElementById("result-cloudburst-outer").style.display = "";
+ document.getElementById("result-raindrops-outer").style.marginTop = "10px";
+ break;
+
+ case "raindrops":
+ document.getElementById("result-raindrops-outer").style.display = "";
+ document.getElementById("result-cloudburst-outer").style.display = "none";
+ document.getElementById("result-raindrops-outer").style.marginTop = "0";
+ data = existing['raindrops'];
+ break;
+
+ case "cloudburst":
+ document.getElementById("result-raindrops-outer").style.display = "none";
+ document.getElementById("result-cloudburst-outer").style.display = "";
+ document.getElementById("result-raindrops-outer").style.marginTop = "0";
+ data = existing['cloudburst'];
+ break;
+ }
+
+ if (system === "all") {
+ updateParsed(text, "raindrops", existing["raindrops"])
+ updateParsed(text, "cloudburst", existing["cloudburst"])
+ } else {
+ updateParsed(text, system, existing[system])
+ }
+ }
+
+ function updateParsed(text, system, data) {
+ let textHTML = "<span>" + text + "</span>";
+ let member;
+ let prefix = null;
+ let suffix = null;
+ let matched = false;
+
+ for (member of data) {
+ for (let proxy of member['proxy_tags']) {
+ if (proxy.prefix !== null && text.startsWith(proxy.prefix)) {
+ if (proxy.suffix !== null) {
+ if (text.endsWith(proxy.suffix)) {
+ matched = true;
+ prefix = proxy.prefix;
+ suffix = proxy.suffix;
+ text = text.substring(proxy.prefix.length, text.length - proxy.suffix.length);
+ break;
+ }
+ } else {
+ matched = true;
+ prefix = proxy.prefix;
+ suffix = null;
+ text = text.substring(proxy.prefix.length, text.length);
+ break;
+ }
+ } else if (proxy.suffix !== null && text.endsWith(proxy.suffix)) {
+ if (proxy.prefix !== null) {
+ if (text.startsWith(proxy.prefix)) {
+ matched = true;
+ prefix = proxy.prefix;
+ suffix = proxy.suffix;
+ text = text.substring(proxy.prefix.length, text.length - proxy.suffix.length);
+ break;
+ }
+ } else {
+ matched = true;
+ prefix = null;
+ suffix = proxy.suffix;
+ text = text.substring(0, text.length - proxy.suffix.length);
+ break;
+ }
+ }
+ }
+
+ if (matched) break;
+ }
+
+ if (!matched) {
+ document.getElementById("host-alert").style.display = "block";
+ member = data.filter((i) => i['id'] === host[system])[0];
+ } else {
+ document.getElementById("host-alert").style.display = "none";
+ }
+
+ document.getElementById("result-" + system + "-avatar").src = member['avatar_url'];
+ document.getElementById("result-" + system + "-name").innerText = member['display_name'] ?? member['name'];
+ document.getElementById("result-" + system + "-prefix").innerText = member['proxy_tags'][0]['prefix'] + (member['proxy_tags'][0]['suffix'] !== null ? "..." + member['proxy_tags'][0]['suffix'] : "");
+
+ if (prefix !== null) {
+ if (suffix !== null) {
+ textHTML = "<span><span class='prefix'>" + prefix + "</span>" + text + "<span class='suffix'>" + suffix + "</span></span>";
+ } else {
+ textHTML = "<span><span class='prefix'>" + prefix + "</span>" + text + "</span>";
+ }
+ } else if (suffix !== null) {
+ textHTML = "<span>" + text + "<span class='suffix'>" + suffix + "</span></span>";
+ }
+
+ document.getElementById("message").innerHTML = textHTML;
+ try { setCursor(document.getElementById("message").innerHTML.length); } catch (e) {
+ console.error(e);
+ }
+ }
+
+ update();
+ </script>
+ <style>
+ .tooltip-inner {
+ text-align: left !important;
+ }
+
+ .text-peh-nowrap {
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ overflow: hidden;
+ }
+
+ .prefix {
+ color: #88de70;
+ }
+
+ .suffix {
+ color: #de7070;
+ }
+ </style>
+</div>
+
+<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/footer.inc'; ?>