summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-06-21 22:32:25 +0200
committerRaindropsSys <contact@minteck.org>2023-06-21 22:32:25 +0200
commit7a7a49332df7c852abbaa33c7e8e87f93d064d61 (patch)
tree43daff24ec8ca4667aae9f3847948f868ae20894
parent898a3d5af7d8bc4578786f1099d6fe092573d112 (diff)
downloadpluralconnect-7a7a49332df7c852abbaa33c7e8e87f93d064d61.tar.gz
pluralconnect-7a7a49332df7c852abbaa33c7e8e87f93d064d61.tar.bz2
pluralconnect-7a7a49332df7c852abbaa33c7e8e87f93d064d61.zip
Updated includes/external/matrix/index.js, added pages/api/evening.php and deleted pages/api/schedule.php (automated)
-rw-r--r--includes/external/matrix/index.js3
-rw-r--r--pages/api/evening.php138
-rw-r--r--pages/api/schedule.php73
3 files changed, 139 insertions, 75 deletions
diff --git a/includes/external/matrix/index.js b/includes/external/matrix/index.js
index 8e6f0b8..c01b3d2 100644
--- a/includes/external/matrix/index.js
+++ b/includes/external/matrix/index.js
@@ -109,8 +109,7 @@ client.once("sync", async function (state, prevState, res) {
});
if (user === "raindrops" && name === "Hazy Stardawn") {
- child_process.execSync("convert " + avatar1 + " -set colorspace Gray -separate -average /tmp/chm-" + user + ".webp");
-
+ await sleep(2000);
let res2 = await client.uploadContent(fs.readFileSync("../../../assets/uploads/hazy.png"));
await axios.put("https://chat.equestria.dev/_matrix/client/r0/rooms/" + encodeURIComponent(require('../../app.json')['matrix']['room']) + "/state/m.room.member/%40raindrops%3Aequestria.dev", {
diff --git a/pages/api/evening.php b/pages/api/evening.php
new file mode 100644
index 0000000..9884e05
--- /dev/null
+++ b/pages/api/evening.php
@@ -0,0 +1,138 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc";
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $isLowerLoggedIn;
+if (!$isLoggedIn || $isLowerLoggedIn) {
+ header("Location: /-/login");
+ die();
+}
+
+$pairs = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/pairs.json"), true);
+$ignored = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/ignored.json"), true);
+$data = [];
+
+$members = $members = [
+ ...array_map(function ($i) {
+ $system = "ynmuc";
+ $i["_lastFronted"] = -1;
+ $id = $i["id"];
+ $memberData = $i;
+
+ $fronters = array_map(function ($item) {
+ return $item["id"];
+ }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true)["members"]);
+
+ if (in_array($id, $fronters)) {
+ $i["_lastFronted"] = time();
+ } else {
+ $switches = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json"), true);
+
+ $thisMember = array_filter($switches, function ($item) use ($memberData) {
+ return in_array($memberData["id"], $item["members"]);
+ });
+
+ $thisMember = array_values($thisMember);
+ $frontingEnd = null;
+
+ if (count($thisMember) > 0) {
+ $thisIndex = array_search($thisMember[0], $switches);
+
+ $frontingStart = $thisMember[0];
+ $frontingEnd = $switches[$thisIndex - 1];
+ }
+
+ if ($frontingEnd !== null && isset($frontingStart)) {
+ $i["_lastFronted"] = strtotime($frontingEnd["timestamp"]);
+ }
+ }
+
+ return $i;
+ }, array_values(array_filter(scoreOrderGlobal(), function ($i) {
+ return $i["_system"] === "ynmuc";
+ }))),
+ ...array_map(function ($i) {
+ $system = "gdapd";
+ $i["_lastFronted"] = -1;
+ $id = $i["id"];
+ $memberData = $i;
+
+ $fronters = array_map(function ($item) {
+ return $item["id"];
+ }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true)["members"]);
+
+ if (in_array($id, $fronters)) {
+ $i["_lastFronted"] = time();
+ } else {
+ $switches = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json"), true);
+
+ $thisMember = array_filter($switches, function ($item) use ($memberData) {
+ return in_array($memberData["id"], $item["members"]);
+ });
+
+ $thisMember = array_values($thisMember);
+ $frontingEnd = null;
+
+ if (count($thisMember) > 0) {
+ $thisIndex = array_search($thisMember[0], $switches);
+
+ $frontingStart = $thisMember[0];
+ $frontingEnd = $switches[$thisIndex - 1];
+ }
+
+ if ($frontingEnd !== null && isset($frontingStart)) {
+ $i["_lastFronted"] = strtotime($frontingEnd["timestamp"]);
+ }
+ }
+
+ return $i;
+ }, array_values(array_filter(scoreOrderGlobal(), function ($i) {
+ return $i["_system"] === "gdapd";
+ })))
+];
+
+usort($pairs, function ($a, $b) use ($members) {
+ $times = [];
+
+ foreach ($a[0] as $id) {
+ $times[] = getLastFronted($members, $id);
+ }
+ foreach ($a[1] as $id) {
+ $times[] = getLastFronted($members, $id);
+ }
+
+ $timeA = time() - min(...$times);
+ $times = [];
+
+ foreach ($b[0] as $id) {
+ $times[] = getLastFronted($members, $id);
+ }
+ foreach ($b[1] as $id) {
+ $times[] = getLastFronted($members, $id);
+ }
+
+ $timeB = time() - min(...$times);
+
+ return $timeB - $timeA;
+}); $pairs = array_values($pairs); foreach ($pairs as $pair): $times = [];
+ foreach ($pair[0] as $id): $times[] = getLastFronted($members, $id); endforeach;
+ foreach ($pair[1] as $id): $times[] = getLastFronted($members, $id); endforeach;
+endforeach;
+
+$listI = 0; for ($i = 0; $i < 2; $i++): $pair = $pairs[$listI];
+ $data[$i] = [];
+ if (!in_array(date('Y-m-d', time() + 86400 * $i), $ignored)) {
+ $data[$i][0] = [];
+ $data[$i][1] = [];
+ foreach ($pair[0] as $id):
+ $data[$i][0][] = getMemberWithoutSystem($id)["display_name"] ?? getMemberWithoutSystem($id)["name"];
+ endforeach;
+ foreach ($pair[1] as $id):
+ $data[$i][1][] = getMemberWithoutSystem($id)["display_name"] ?? getMemberWithoutSystem($id)["name"];
+ endforeach;
+ } else {
+ $data[$i] = null;
+ }
+if (!in_array(date('Y-m-d', time() + 86400 * $i), $ignored)) $listI++; if ($listI === count($pairs)) $listI = 0; endfor;
+
+header("Content-Type: application/json");
+die(json_encode($data, JSON_PRETTY_PRINT)); \ No newline at end of file
diff --git a/pages/api/schedule.php b/pages/api/schedule.php
deleted file mode 100644
index 7ae263c..0000000
--- a/pages/api/schedule.php
+++ /dev/null
@@ -1,73 +0,0 @@
-<?php
-
-require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $_PROFILE;
-require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc";
-if (!$isLoggedIn) header("Location: /-/login") and die();
-
-header("Content-Type: application/json");
-
-$obj = [
- "today" => [],
- "tomorrow" => []
-];
-
-if (time() >= 1686787200) {
- die(json_encode($obj, JSON_PRETTY_PRINT));
-}
-
-$raindrops = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/planner/gdapd.json"), true);
-$cloudburst = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/planner/ynmuc.json"), true);
-
-if (isset($raindrops[date('Y-m-d', time())]) || isset($cloudburst[date('Y-m-d', time())])) {
- $rd = $raindrops[date('Y-m-d', time())];
- $cb = $cloudburst[date('Y-m-d', time())];
- $longest = max(count($rd), count($cb));
-
- for ($x = 0; $x < $longest; $x++) {
- $item = [];
- $item["raindrops"] = null;
- $item["cloudburst"] = null;
-
- if (isset($rd[$x])) {
- $item["raindrops"] = array_map(function ($i) { return getMemberWithoutSystem($i)["display_name"] ?? getMemberWithoutSystem($i)["name"]; }, array_filter($rd[$x], function ($i) { return isset($i); }));
- } else if (isset($obj["today"][$x - 1]["raindrops"])) {
- $item["raindrops"] = $obj["today"][$x - 1]["raindrops"];
- }
-
- if (isset($cb[$x])) {
- $item["cloudburst"] = array_map(function ($i) { return getMemberWithoutSystem($i)["display_name"] ?? getMemberWithoutSystem($i)["name"]; }, array_filter($cb[$x], function ($i) { return isset($i); }));
- } else if (isset($obj["today"][$x - 1]["cloudburst"])) {
- $item["cloudburst"] = $obj["today"][$x - 1]["cloudburst"];
- }
-
- $obj["today"][] = $item;
- }
-}
-
-if (isset($raindrops[date('Y-m-d', time() + 86400)]) || isset($cloudburst[date('Y-m-d', time() + 86400)])) {
- $rd = $raindrops[date('Y-m-d', time() + 86400)];
- $cb = $cloudburst[date('Y-m-d', time() + 86400)];
- $longest = max(count($rd), count($cb));
-
- for ($x = 0; $x < $longest; $x++) {
- $item = [];
- $item["raindrops"] = null;
- $item["cloudburst"] = null;
-
- if (isset($rd[$x])) {
- $item["raindrops"] = array_map(function ($i) { return getMemberWithoutSystem($i)["display_name"] ?? getMemberWithoutSystem($i)["name"]; }, array_filter($rd[$x], function ($i) { return isset($i); }));
- } else if (isset($obj["tomorrow"][$x - 1]["raindrops"])) {
- $item["raindrops"] = $obj["tomorrow"][$x - 1]["raindrops"];
- }
-
- if (isset($cb[$x])) {
- $item["cloudburst"] = array_map(function ($i) { return getMemberWithoutSystem($i)["display_name"] ?? getMemberWithoutSystem($i)["name"]; }, array_filter($cb[$x], function ($i) { return isset($i); }));
- } else if (isset($obj["tomorrow"][$x - 1]["cloudburst"])) {
- $item["cloudburst"] = $obj["tomorrow"][$x - 1]["cloudburst"];
- }
-
- $obj["tomorrow"][] = $item;
- }
-}
-
-die(json_encode($obj, JSON_PRETTY_PRINT)); \ No newline at end of file