diff options
author | Minteck <contact@minteck.org> | 2022-09-22 19:47:05 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-09-22 19:47:05 +0200 |
commit | 2162eaa06f7e4764eb3dcfe130ec2c711d0c62ab (patch) | |
tree | a82223bc980747531c640e9dc2c151d5fe3335a3 /api | |
parent | e95b208af90cc386a7d8d1bcab426727cf4f0121 (diff) | |
download | pluralconnect-2162eaa06f7e4764eb3dcfe130ec2c711d0c62ab.tar.gz pluralconnect-2162eaa06f7e4764eb3dcfe130ec2c711d0c62ab.tar.bz2 pluralconnect-2162eaa06f7e4764eb3dcfe130ec2c711d0c62ab.zip |
Cofronting support and stuff like that
Diffstat (limited to 'api')
-rw-r--r-- | api/fronter.php | 30 | ||||
-rw-r--r-- | api/pluralkit-integration.php | 76 |
2 files changed, 75 insertions, 31 deletions
diff --git a/api/fronter.php b/api/fronter.php index e74d34a..f962625 100644 --- a/api/fronter.php +++ b/api/fronter.php @@ -31,7 +31,22 @@ switch ($type) { if ($member !== null && $member !== "null") header("Location: /?error=System member not found") and die(); if (!isset($list[$date])) $list[$date] = []; - $list[$date][] = $member; + $list[$date][] = [$member, null]; + break; + + case "cofront": + if (!isset($index) || trim($index) === "" || is_integer($index)) + if ($index !== null && $index !== "null") header("Location: /?error=Invalid index") and die(); + + $day = $list[$date]; + + if (!isset($day[$index])) + if ($index !== null && $index !== "null") header("Location: /?error=Index not found") and die(); + + if (!isset($member) || trim($member) === "" || strlen($member) !== 5 || !preg_match("/[a-z]/i", $member)) + if ($member !== null && $member !== "null") header("Location: /?error=System member not found") and die(); + + $list[$date][$index][1] = $member; break; case "delete": @@ -48,6 +63,19 @@ switch ($type) { break; + case "codelete": + if (!isset($index) || trim($index) === "" || is_integer($index)) + if ($index !== null && $index !== "null") header("Location: /?error=Invalid index") and die(); + + $day = $list[$date]; + + if (!isset($day[$index])) + if ($index !== null && $index !== "null") header("Location: /?error=Index not found") and die(); + + $list[$date][$index][1] = null; + + break; + case "down": if (!isset($index) || trim($index) === "" || is_integer($index)) if ($index !== null && $index !== "null") header("Location: /?error=Invalid index") and die(); diff --git a/api/pluralkit-integration.php b/api/pluralkit-integration.php index 98f4cb9..3582df1 100644 --- a/api/pluralkit-integration.php +++ b/api/pluralkit-integration.php @@ -39,19 +39,51 @@ if ($input["type"] === "CREATE_SWITCH" || $input["type"] === "UPDATE_SWITCH" || $ntfy = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true)["ntfy"]; - file_get_contents('https://' . $ntfy["server"] . '/public-switches', false, stream_context_create([ - 'http' => [ - 'method' => 'POST', - 'header' => - "Content-Type: text/plain\r\n" . - "Title: 🐴 Switch occurred in the $name\r\n" . - "Priority: default\r\n" . - "Tags: switch\r\n" . - "Actions: view, Open on Cold Haze, https://ponies.equestria.horse/" . $fronters["members"][0]["name"] . "/, clear=true\r\n" . - "Authorization: Basic " . base64_encode($ntfy["user"] . ":" . $ntfy["password"]), - 'content' => ($fronters["members"][0]["display_name"] ?? $fronters["members"][0]["name"]) . " switched in just now" - ] - ])); + if (count($fronters["members"]) > 1) { + $context = stream_context_create([ + 'http' => [ + 'method' => 'POST', + 'header' => + "Content-Type: text/plain\r\n" . + "Title: 🐴 Switch occurred in the $name\r\n" . + "Priority: default\r\n" . + "Tags: switch\r\n" . + "Actions: view, Open " . $fronters["members"][0]["display_name"] . " on Cold Haze, https://ponies.equestria.horse/" . $fronters["members"][0]["name"] . "/, clear=true;view, Open " . $fronters["members"][1]["display_name"] . " on Cold Haze, https://ponies.equestria.horse/" . $fronters["members"][1]["name"] . "/, clear=true\r\n" . + "Authorization: Basic " . base64_encode($ntfy["user"] . ":" . $ntfy["password"]), + 'content' => ($fronters["members"][0]["display_name"] ?? $fronters["members"][0]["name"]) . " and " . ($fronters["members"][1]["display_name"] ?? $fronters["members"][1]["name"]) . " switched in just now" + ] + ]); + } else if (count($fronters["members"]) > 0) { + $context = stream_context_create([ + 'http' => [ + 'method' => 'POST', + 'header' => + "Content-Type: text/plain\r\n" . + "Title: 🐴 Switch occurred in the $name\r\n" . + "Priority: default\r\n" . + "Tags: switch\r\n" . + "Actions: view, Open on Cold Haze, https://ponies.equestria.horse/" . $fronters["members"][0]["name"] . "/, clear=true\r\n" . + "Authorization: Basic " . base64_encode($ntfy["user"] . ":" . $ntfy["password"]), + 'content' => ($fronters["members"][0]["display_name"] ?? $fronters["members"][0]["name"]) . " switched in just now" + ] + ]); + } else { + $context = stream_context_create([ + 'http' => [ + 'method' => 'POST', + 'header' => + "Content-Type: text/plain\r\n" . + "Title: 🐴 Switch occurred in the $name\r\n" . + "Priority: default\r\n" . + "Tags: switch\r\n" . + "Actions: view, Open on Cold Haze, https://ponies.equestria.horse/, clear=true\r\n" . + "Authorization: Basic " . base64_encode($ntfy["user"] . ":" . $ntfy["password"]), + 'content' => "The fallback pony switched in just now" + ] + ]); + } + + file_get_contents('https://' . $ntfy["server"] . '/public-switches', false, $context); if ($system === "gdapd") { $topic = "public-switches-raindrops"; @@ -59,21 +91,5 @@ if ($input["type"] === "CREATE_SWITCH" || $input["type"] === "UPDATE_SWITCH" || $topic = "public-switches-cloudburst"; } - file_get_contents('https://' . $ntfy["server"] . '/' . $topic, false, stream_context_create([ - 'http' => [ - 'method' => 'POST', - 'header' => - "Content-Type: text/plain\r\n" . - "Title: 🐴 Switch occurred in the $name\r\n" . - "Priority: default\r\n" . - "Tags: switch\r\n" . - "Actions: view, Open on Cold Haze, https://ponies.equestria.horse/" . $fronters["members"][0]["name"] . "/, clear=true\r\n" . - "Authorization: Basic " . base64_encode($ntfy["user"] . ":" . $ntfy["password"]), - 'content' => ($fronters["members"][0]["display_name"] ?? $fronters["members"][0]["name"]) . " switched in just now" - ] - ])); - - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/data.json-res", "affected: " . $input["type"] . " (" . gettype($input["type"]) . ")") and die(); -} else { - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/data.json-res", "invalid method: " . $input["type"] . " (" . gettype($input["type"]) . ")") and die(); + file_get_contents('https://' . $ntfy["server"] . '/' . $topic, false, $context); }
\ No newline at end of file |