From 6602df4fa9cd8aa4a1e1065ee3ef8344830915bf Mon Sep 17 00:00:00 2001 From: lolcat Date: Sun, 11 Oct 2026 17:34:16 -0400 Subject: [PATCH] remove oracles, sorry cynic --- oracles/base.php | 36 ---------- oracles/calc.php | 165 ------------------------------------------- oracles/encoder.php | 40 ----------- oracles/numerics.php | 54 -------------- oracles/time.php | 45 ------------ web.php | 29 -------- 6 files changed, 369 deletions(-) delete mode 100644 oracles/base.php delete mode 100644 oracles/calc.php delete mode 100644 oracles/encoder.php delete mode 100644 oracles/numerics.php delete mode 100644 oracles/time.php diff --git a/oracles/base.php b/oracles/base.php deleted file mode 100644 index 84299fd..0000000 --- a/oracles/base.php +++ /dev/null @@ -1,36 +0,0 @@ - "some oracle" - ]; - // this function should take in a query string search from $_GET, - // and return a bool determining whether or not it is a question - // intended for the oracle. - public function check_query($q) { - return false; - } - // produce the correct answer for the query using the oracle. - // note: if it becomes apparent /during generation/ that the - // query is not in fact for the oracle, returning an empty - // string will kill the oracle pane. - // answer format: ["ans1 title" => "ans1", ...] - public function generate_response($q) { - return ""; - } -} -// backwards compatibility -if (!function_exists('str_starts_with')) { - function str_starts_with($haystack, $needle) { - return strncmp($haystack, $needle, strlen($needle)) === 0;; - } -} -if (!function_exists('str_contains')) { - function str_contains($haystack, $needle) { - return strpos((string)$haystack, (string)$needle) !== false; - } -} - -?> \ No newline at end of file diff --git a/oracles/calc.php b/oracles/calc.php deleted file mode 100644 index 833749e..0000000 --- a/oracles/calc.php +++ /dev/null @@ -1,165 +0,0 @@ - "calculator" - ]; - public function check_query($q) { - // straight numerics should go to that oracle - if (is_numeric($q)) { - return false; - } - // all chars should be number-y or operator-y - $char_whitelist = str_split("1234567890.+-/*^%() "); - foreach (str_split($q) as $char) { - if (!in_array($char, $char_whitelist)) { - return false; - } - } - return true; - } - // a custom parser and calculator because FUCK YUO, libraries are - // gay. - public function generate_response($q) - { - $nums = str_split("1234567890."); - $ops = str_split("+-/*^%;"); - $grouping = str_split("()"); - - $q = str_replace(" ", "", $q); - - // backstop for the parser so it catches the last - // numeric token - $q .= ";"; - - // the following comments refer to this example input: - // 21+9*(3+2^9)+1 - - // 2-length lists of the following patterns: - // ["n" (umeric), ] - // ["o" (perator), ""] - // ["g" (roup explicit), <"(" or ")">] - // e.g. [["n", 21], ["o", "+"], ["n", 9], ["o", *], - // ["g", "("], ["n", 3], ["o", "+"], ["n", 2], - // ["o", "^"], ["n", 9], ["g", ")"], ["o", "+"], - // ["n", "1"]] - $tokens = array(); - $dragline = 0; - foreach(str_split($q) as $i=>$char) { - if (in_array($char, $nums)) { - continue; - } - elseif (in_array($char, $ops) || in_array($char, $grouping)) { - // hitting a non-numeric implies everything since the - // last hit has been part of a number - $capture = substr($q, $dragline, $i - $dragline); - // prevent the int cast from creating imaginary - // ["n", 0] tokens - if ($capture != "") { - if (substr_count($capture, ".") > 1) { - return ""; - } - array_push($tokens, ["n", (float)$capture]); - } - // reset to one past the current (non-numeric) char - $dragline = $i + 1; - // the `;' backstop is not a real token and this should - // never be present in the token list - if ($char != ";") { - array_push($tokens, [ - ($char == "(" || $char == ")") ? "g" : "o", - $char - ]); - } - } - else { - return ""; - } - } - - // two operators back to back should fail - for ($i = 1; $i < count($tokens); $i++) { - if ($tokens[$i][0] == "o" && $tokens[$i-1][0] == "o") { - return ""; - } - } - - // no implicit multiplication - for ($i = 0; $i < count($tokens) - 1; $i++) { - if ($tokens[$i][0] == "n" && $tokens[$i+1] == ["g", "("]) { - return ""; - } - } - - //strategy: - // traverse to group open (if there is one) - // - return to start with the internals - // traverse to ^, attack token previous and after - // same but for *, then / then + then - - // poppers all teh way down - try { - return [ - substr($q, 0, strlen($q)-1)." = " => $this->executeBlock($tokens)[0][1] - ]; - } - catch (\Throwable $e) { - if (get_class($e) == "DivisionByZeroError") { - return [ - $q." = " => "Division by Zero Error!!" - ]; - } - return ""; - } - } - public function executeBlock($tokens) { - if (count($tokens) >= 2 && $tokens[0][0] == "o" && $tokens[0][1] == "-" && $tokens[1][0] == "n") { - array_splice($tokens, 0, 2, [["n", -1 * (float)$tokens[1][1]]]); - } - if (count($tokens) > 0 && $tokens[0][0] == "o" || $tokens[count($tokens)-1][0] == "o") { - throw new Exception("Error Processing Request", 1); - } - while (in_array(["g", "("], $tokens)) { - $first_open = array_search(["g", "("], $tokens); - $enclosedality = 1; - for ($i = $first_open+1; $i < count($tokens); $i++) { - if ($tokens[$i][0] == "g") { - $enclosedality += ($tokens[$i][1] == "(") ? 1 : -1; - } - if ($enclosedality == 0) { - array_splice($tokens, - $first_open, - $i+1 - $first_open, - $this->executeBlock( - array_slice($tokens, $first_open+1, $i-1 - $first_open) - ) - ); - break; - } - } - } - $operators_in_pemdas_order = [ - "^" => (fn($x, $y) => $x ** $y), - "*" => (fn($x, $y) => $x * $y), - "/" => (fn($x, $y) => $x / $y), - "%" => (fn($x, $y) => $x % $y), - "+" => (fn($x, $y) => $x + $y), - "-" => (fn($x, $y) => $x - $y) - ]; - foreach ($operators_in_pemdas_order as $op=>$func) { - while (in_array(["o", $op], $tokens)) { - for ($i = 0; $i < count($tokens); $i++) { - if ($tokens[$i] == ["o", $op]) { - array_splice( - $tokens, - $i-1, - 3, - [["n", (string)($func((float)$tokens[$i-1][1], (float)$tokens[$i+1][1]))]] - ); - } - } - } - } - return $tokens; - } -} -?> \ No newline at end of file diff --git a/oracles/encoder.php b/oracles/encoder.php deleted file mode 100644 index 00b5ad0..0000000 --- a/oracles/encoder.php +++ /dev/null @@ -1,40 +0,0 @@ - "text encoder/hasher" - ]; - private $special_types = [ - "rot13", - "base64" - ]; - public function check_query($q) { - $types = array_merge($this->special_types, hash_algos()); - foreach ($types as $type) { - $type .= " "; - if (str_starts_with($q, $type)) { - return true; - } - } - return false; - } - public function generate_response($q) - { - $type = explode(" ", $q)[0]; - $victim = substr($q, strlen($type)+1); - if (in_array($type, hash_algos())) { - return [$type." hash" => hash($type, $victim)]; - } - switch ($type) { - case "rot13": - return ["rot13 encoded" => str_rot13($victim)]; - case "base64": - return [ - "base64 encoded" => base64_encode($victim), - "base64 decoded" => base64_decode($victim) - ]; - } - return ""; - } -} -?> \ No newline at end of file diff --git a/oracles/numerics.php b/oracles/numerics.php deleted file mode 100644 index 3d428e3..0000000 --- a/oracles/numerics.php +++ /dev/null @@ -1,54 +0,0 @@ - "numeric base conversion" - ]; - public function check_query($q) { - if (str_contains($q, " ")) { - return false; - } - - $q = strtolower($q); - - $profiles = [ - ["0x", str_split("0123456789abcdef")], - ["", str_split("1234567890")], - ["b", str_split("10")] - ]; - - foreach ($profiles as $profile) { - $good = true; - $good &= str_starts_with($q, $profile[0]); - $nq = substr($q, strlen($profile[0])); - foreach (str_split($nq) as $c) { - $good &= in_array($c, $profile[1]); - } - if ($good) { - return true; - } - } - return false; - } - public function generate_response($q) { - $n = 0; - if (str_starts_with($q, "0x")) { - $nq = substr($q, strlen("0x")); - $n = hexdec($nq); - } - elseif (str_starts_with($q, "b")) { - $nq = substr($q, strlen("b")); - $n = bindec($nq); - } - else { - $n = (int)$q; - } - return [ - "decimal (base 10)" => (string)$n, - "hexadecimal (base 16)" => "0x".(string)dechex($n), - "binary (base 2)" => "b".(string)decbin($n), - "" => "binary inputs should be prefixed with 'b', hex with '0x'." - ]; - } -} -?> \ No newline at end of file diff --git a/oracles/time.php b/oracles/time.php deleted file mode 100644 index 954bc60..0000000 --- a/oracles/time.php +++ /dev/null @@ -1,45 +0,0 @@ - "what time is it?" - ]; - public function check_query($q) { - $prompts = [ - "what", "time", "is", "it", - "right", "now", "the", "current", - "get", "date" - ]; - $q = str_replace(",", "", $q); - $q = str_replace("?", "", $q); - $q = str_replace("what's", "what is", $q); - $oq = $q; - $q = explode(" ", $q); - $count = 0; - foreach ($q as $word) { - if (in_array($word, $prompts)) { - $count++; - } - } - // remove one from total count if a timezone is specified - return ($count/(count($q) + (str_contains($oq, "tz:") ? -1 : 0))) > 3/4; - } - public function generate_response($q) { - $timezone = timezone_name_from_abbr("UTC"); - foreach (explode(" ", $q) as $word) { - if (str_starts_with($word, "tz:")) { - $decltz = timezone_name_from_abbr(substr($word, 3, 3)); - if ($decltz) { - $timezone = $decltz; - } - } - } - date_default_timezone_set($timezone); - return [ - "The time in ".$timezone => date("H:i:s"), - " " => date("l, F jS"), - "" => "include the string \"tz:XXX\" to use timezone XXX" - ]; - } -} -?> \ No newline at end of file diff --git a/web.php b/web.php index 3641bb6..8fd35a2 100644 --- a/web.php +++ b/web.php @@ -37,35 +37,6 @@ try{ $frontend->drawscrapererror($error->getMessage(), $get, "web", $payload["timetaken"]); } -/* - Prepend Oracle output, if applicable -*/ -include("oracles/encoder.php"); -include("oracles/calc.php"); -include("oracles/time.php"); -include("oracles/numerics.php"); -$oracles = [new calculator(), new encoder(), new time(), new numerics()]; -$fortune = ""; -foreach ($oracles as $oracle) { - if ($oracle->check_query($_GET["s"])) { - $resp = $oracle->generate_response($_GET["s"]); - if ($resp != "") { - $fortune .= "
"; - foreach ($resp as $title => $r) { - if ($title) { - $fortune .= "

".htmlspecialchars($title)."

".htmlspecialchars($r)."
"; - } - else { - $fortune .= "".$r."
"; - } - } - $fortune .= "Answer provided by oracle: ".$oracle->info["name"]."
"; - } - break; - } -} -$payload["left"] = $fortune; - $answerlen = 0; /*