summaryrefslogtreecommitdiff
path: root/api/pluralkit-integration.php
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-08-31 22:03:07 +0200
committerMinteck <contact@minteck.org>2022-08-31 22:03:07 +0200
commitb5f589c323f415bb42ea7069cb4d1a8a2233dd69 (patch)
treec3b80234ab7f463a2e7b8b672ceff57422b3496b /api/pluralkit-integration.php
parent09bd0164ebc020a54b944b7326dcba496fb5d82c (diff)
downloadpluralconnect-b5f589c323f415bb42ea7069cb4d1a8a2233dd69.tar.gz
pluralconnect-b5f589c323f415bb42ea7069cb4d1a8a2233dd69.tar.bz2
pluralconnect-b5f589c323f415bb42ea7069cb4d1a8a2233dd69.zip
Update I guess - Stuffie
Diffstat (limited to 'api/pluralkit-integration.php')
-rw-r--r--api/pluralkit-integration.php27
1 files changed, 25 insertions, 2 deletions
diff --git a/api/pluralkit-integration.php b/api/pluralkit-integration.php
index b2247ce..262d4a6 100644
--- a/api/pluralkit-integration.php
+++ b/api/pluralkit-integration.php
@@ -21,15 +21,38 @@ if ($input["signing_token"] !== $data[$user]) {
if ($input['system_id'] === "7d9f543e-f742-40f6-9d07-86c3f2983124") {
$system = "gdapd";
+ $name = "Raindrops System";
} else {
$system = "ynmuc";
+ $name = "Cloudburst System";
}
+$lastFronter = json_decode(@file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system-last.json"), true) ?? "";
+
if ($input["type"] === "CREATE_SWITCH" || $input["type"] === "UPDATE_SWITCH" || $input["type"] === "DELETE_SWITCH") {
- usleep(550000);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system-fronters.json", file_get_contents("https://pluralkit.equestria.dev/v2/systems/$input[system_id]/fronters"));
- usleep(550000);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system-switches.json", file_get_contents("https://pluralkit.equestria.dev/v2/systems/$input[system_id]/switches"));
+
+ $fronters = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system-fronters.json"), true);
+ $currentFronter = $fronters["members"][0]["id"];
+ file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system-last.json", json_encode($currentFronter));
+
+ $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"
+ ]
+ ]));
+
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();