diff options
| author | cynic <admin@cynic.moe> | 2023-09-13 22:24:02 -0500 |
|---|---|---|
| committer | lolcat <lolcat@no-reply@lolcat.ca> | 2023-09-13 22:24:02 -0500 |
| commit | 8762d68466b825382f4708a0eebbd3074e32c5c5 (patch) | |
| tree | 11cd604ee79c4b83769b56cc39bb0db137379e97 /oracles/time.php | |
| parent | d312674df74affb9f22b2a02e54549006f26d056 (diff) | |
add structure for `Oracles' (special answers depending on queries + a few implementations (#10)
incl. a calculator, a hash encoder + rot13 and b64!, and a "what time is it" with timezone selection
frontend injected in $payload["left"] in web.php
you can see this live [on my instance](https://4get.silly.computer/web?s=7%2B8(9%5E2)&scraper=brave&nsfw=yes) (there are some issues that aren't related to this PR. favicons, etc. I'll fix them later.)
Reviewed-on: https://git.lolcat.ca/lolcat/4get/pulls/10
Co-authored-by: cynic <admin@cynic.moe>
Co-committed-by: cynic <admin@cynic.moe>
Diffstat (limited to 'oracles/time.php')
| -rw-r--r-- | oracles/time.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/oracles/time.php b/oracles/time.php new file mode 100644 index 0000000..57af093 --- /dev/null +++ b/oracles/time.php @@ -0,0 +1,44 @@ +<?php +include_once("oracles/base.php"); +class time extends oracle { + public $info = [ + "name" => "what time is it?" + ]; + public function check_query($q) { + $prompts = [ + "what", "time", "is", "it", + "right", "now", "the", "current", + "get" + ]; + $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"), + "" => "include the string \"tz:XXX\" to use timezone XXX" + ]; + } +} +?>
\ No newline at end of file |
