From cdf958d29333d448f4521f4d2faa2592b58e9b27 Mon Sep 17 00:00:00 2001 From: lolcat Date: Sun, 10 Aug 2025 21:55:15 -0400 Subject: fix wikipedia crash --- oracles/time.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 oracles/time.php (limited to 'oracles/time.php') diff --git a/oracles/time.php b/oracles/time.php new file mode 100644 index 0000000..954bc60 --- /dev/null +++ b/oracles/time.php @@ -0,0 +1,45 @@ + "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 -- cgit v1.2.3