diff options
author | Minteck <contact@minteck.org> | 2022-08-10 10:38:44 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-08-10 10:38:44 +0200 |
commit | c6dbf0450566c40efc4a26f4f0717452b6ef95cd (patch) | |
tree | b4be2d508223820d0a77d5a3e35e82684da3b6ec /pluralkit/index.php | |
download | hornchat-mane.tar.gz hornchat-mane.tar.bz2 hornchat-mane.zip |
Diffstat (limited to 'pluralkit/index.php')
-rw-r--r-- | pluralkit/index.php | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/pluralkit/index.php b/pluralkit/index.php new file mode 100644 index 0000000..1bcf53a --- /dev/null +++ b/pluralkit/index.php @@ -0,0 +1,32 @@ +<?php + +$user = $_GET['user'] ?? null; +$inputJSON = file_get_contents('php://input'); +$input = json_decode($inputJSON, true); +$data = json_decode(file_get_contents("../data/fronters.json"), true); + +if ($user === null) { + header("HTTP/1.1 500 Internal Server Error") and die(); +} + +if (!in_array($user, array_keys($data))) { + header("HTTP/1.1 404 Not Found") and die(); +} + +if ($input["signing_token"] !== $data[$user]["token"]) { + header("HTTP/1.1 401 Unauthorized") and die(); +} + +if ($input["type"] === "CREATE_SWITCH" || $input["type"] === "UPDATE_SWITCH" || $input["type"] === "DELETE_SWITCH") { + $data[$user]["system"] = $input["system_id"]; + if (isset($input["data"]) && isset($input["data"]["members"])) { + $data[$user]["fronters"] = $input["data"]["members"]; + } else { + sleep(rand(1, 3)); + $data[$user]["fronters"] = array_map(function ($i) { + return $i['uuid']; + }, json_decode(file_get_contents("https://api.pluralkit.me/v2/systems/$input[system_id]/fronters"), true)["members"]); + } +} + +file_put_contents("../data/fronters.json", json_encode($data, JSON_PRETTY_PRINT));
\ No newline at end of file |