1
Fork 1
mirror of https://git.lolcat.ca/lolcat/4get.git synced 2024-11-08 17:43:07 -05:00
4get/oracles/time.php
cynic 24cfc5136e some misc. oracles stuff (fixes/features) (#15)
fix a small calc.php bug, and add date information to the time module. the changes have been sitting on a branch for like a week, so I figured I'd cherry-pick them over to this branch for a PR.
[as always, these changes are live on my instance.](https://4get.silly.computer/web?s=what+is+the+date&scraper=yandex&nsfw=yes)

Reviewed-on: https://git.lolcat.ca/lolcat/4get/pulls/15
Co-authored-by: cynic <admin@cynic.moe>
Co-committed-by: cynic <admin@cynic.moe>
2023-09-22 21:44:33 -05:00

45 lines
No EOL
1.1 KiB
PHP

<?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", "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"
];
}
}
?>