static function Process($message) { $message_words = explode(" ", $message); $session = Session::getInstance(); $prompt_session = $session->get('_PROMPT_'); if (is_array($prompt_session)) { // Check if cancel Prompt echo "System Prompt: " . $prompt_session['question'] . "\n"; echo "Answered: " . $message . "\n"; $search = array(); foreach (self::$cancel_keywords as $key => $sentences) { $search[$key] = 0; foreach ($sentences as $word) { if (in_array($word, $message_words)) { $search[$key] += 1; } } if ($search[$key] >= count($sentences)) { //Cancel Prompt TTS::Speak('Okay, i wont ask anymore!'); self::Clear(); return; } } // Forward prompt to Class::Method $class = ""; eval('$class = new ' . $prompt_session['class'] . '();'); $function = $prompt_session['function']; //$class->setTriggered( array("keywords"=>$parameters, "trigger"=>$data) ); $class->{$function}($message); } }
public function check_schedules() { $today = $this->getUpcomingScheduleToday(); $response = array(); if ($today) { foreach ($today as $key => $event) { $start = new DateTime($event['start']); //var_dump($start->format('h:i')); if (strpos($event['summary'], 'CODING:') !== false) { $car = str_replace("CODING:", "", $event['summary']); $response[] = "Your " . $car . " is on coding today! Make sure you don't forget to bring parking pass keys."; } else { $newevent = $event['summary'] . " at " . $start->format('h:i'); if ($event['location'] != "") { $newevent .= " in " . $event['location']; } $response[] = $newevent . "."; } } $today_response = implode(" Then ", $response) . " "; } else { $today_response = "No upcoming events for today. "; } $response_tom = array(); $tomorrow = $this->getUpcomingScheduleTomorrow(); if ($tomorrow) { foreach ($tomorrow as $key => $event) { $start = new DateTime($event['start']); //var_dump($start->format('h:i')); if (strpos($event['summary'], 'CODING:') !== false) { $car = str_replace("CODING:", "", $event['summary']); $response_tom[] = "Your " . $car . " is on coding tomorrow."; } else { $newevent = $event['summary'] . " at " . $start->format('h:i'); if ($event['location'] != "") { $newevent .= " in " . $event['location']; } $response_tom[] = $newevent . "."; } } $tomorrow_response = "For tomorrow: " . implode(" Then ", $response_tom) . " "; } TTS::Speak($today_response . $tomorrow_response); }
/** * protected $inputs = array( 'PC', 'HDMI2', 'HDMI1', 'YPBPR', 'AV2', 'AV1', 'ATV', ); * @return boolean */ public function set_source_toggle() { $state = $this->state->Get($this->StateStorage); $current = $state['input']; $maxmode = count($this->inputs); if (in_array("pc", $this->triggered['triggered']) || in_array("computer", $this->triggered['triggered']) || in_array("vga", $this->triggered['triggered'])) { $target = 0; } elseif (in_array("hdmi", $this->triggered['triggered'])) { if (in_array("two", $this->triggered['triggered']) || in_array("2", $this->triggered['triggered'])) { $target = 1; } else { $target = 2; } } elseif (in_array("for", $this->triggered['triggered'])) { if (in_array("game", $this->triggered['triggered'])) { $target = 1; } elseif (in_array("cable", $this->triggered['triggered'])) { $target = 2; } } elseif (in_array("composite", $this->triggered['triggered'])) { $target = 3; } elseif (in_array("av", $this->triggered['triggered']) || in_array("video", $this->triggered['triggered'])) { if (in_array("two", $this->triggered['triggered']) || in_array("2", $this->triggered['triggered'])) { $target = 4; } else { $target = 5; } } elseif (in_array("analog", $this->triggered['triggered'])) { $target = 6; } elseif (in_array("7f794e63c61e2b6eb6e59a52b68f8f13", $this->triggered['triggered'])) { //Do toggle only if ($current >= $maxmode - 1) { $target = 0; } else { $target = $current + 1; } } if ($target == $current) { return true; } if ($target > $current) { $function = "KEY_DOWN"; $distance = $target - $current; } else { $function = "KEY_UP"; $distance = $current - $target; //$distance += 1; //Add for zero } $runfunc = "sleep .5; irsend SEND_ONCE " . $this->Device . " KEY_MENU;"; $runfunc .= "sleep .5; irsend SEND_ONCE " . $this->Device . " KEY_RIGHT;"; $runfunc .= "sleep .5; irsend SEND_ONCE " . $this->Device . " KEY_UP;"; /** Loop how many counts of distance to target * */ for ($i = 1; $i <= $distance; $i++) { $runfunc .= "sleep .5; irsend SEND_ONCE " . $this->Device . " " . $function . ";"; } $runfunc .= "sleep .5; irsend SEND_ONCE " . $this->Device . " KEY_OK;"; $runfunc .= "sleep .5; irsend SEND_ONCE " . $this->Device . " KEY_BACK;"; $runfunc .= "sleep .5; irsend SEND_ONCE " . $this->Device . " KEY_BACK;"; $runfunc .= "sleep .5; irsend SEND_ONCE " . $this->Device . " KEY_BACK;"; if ($this->speak) { TTS::Speak('Setting TV source to: ' . $this->inputs[$target]); } $state['input'] = $target; shell_exec($runfunc); $this->state->Set($this->StateStorage, $state); }
/** * * 0'extreme stereo' * 1'FS Advance', 2'Action', 3'Drama', 4'Entertianment Show', 5'Advanced Game', 6'Sports', 7'Classical', 8'Pop/Rock', 9'Unplugged' */ public function set_advance_surround() { $state = $this->state->Get('AVR'); $current = $state['surround']; $maxmode = count($this->advance_surround); $function = "KEY_F4"; if (in_array("stereo", $this->triggered['triggered'])) { $target = 0; } elseif (in_array("fs", $this->triggered['triggered']) || in_array("front", $this->triggered['triggered'])) { $target = 1; } elseif (in_array("action", $this->triggered['triggered'])) { $target = 2; } elseif (in_array("drama", $this->triggered['triggered'])) { $target = 3; } elseif (in_array("entertainment", $this->triggered['triggered'])) { $target = 4; } elseif (in_array("game", $this->triggered['triggered'])) { $target = 5; } elseif (in_array("sports", $this->triggered['triggered']) || in_array("sport", $this->triggered['triggered'])) { $target = 6; } elseif (in_array("classical", $this->triggered['triggered'])) { $target = 7; } elseif (in_array("pop", $this->triggered['triggered']) || in_array("rock", $this->triggered['triggered'])) { $target = 8; } elseif (in_array("unplugged", $this->triggered['triggered'])) { $target = 9; } elseif (in_array("be1cae78e00bc6118ba62904d892ef61", $this->triggered['triggered'])) { //Do toggle only if ($current >= $maxmode - 1) { $target = 0; } else { $target = $current + 1; } } if ($target == $current) { return true; } /** Get looping keys based on current selected */ $toggleCount = 0; for ($i = $current + 1; $i <= count($this->advance_surround); $i++) { //if $i reaches the max array count go back to 0 if ($i == $maxmode) { $i = 0; } $toggleCount += 1; if ($i == $target) { // Do action $runfunc = "sleep .5; irsend SEND_ONCE PIONEER_AVR " . $function . ";"; for ($s = 0; $s < $toggleCount; $s++) { $runfunc .= "sleep .5; irsend SEND_ONCE PIONEER_AVR " . $function . ";"; } if ($this->speak) { TTS::Speak($this->response_set_general('surround: ' . $this->advance_surround[$target])); } $state['surround'] = $target; shell_exec($runfunc); //var_dump($this->advance_surround[$target]); $this->state->Set('AVR', $state); break; } //Stop when counter goes back to current audio mode if ($i == $current) { break; } } }
public function read_new_email_subject() { $GoogleAPI = GoogleAppsAPI::getInstance(); $client = $GoogleAPI->getClient(); $service = new Google_Service_Gmail($client); $pageToken = NULL; $userId = 'me'; $messages = array(); $opt_param = array('labelIds' => 'UNREAD'); do { try { if ($pageToken) { $opt_param['pageToken'] = $pageToken; } $messagesResponse = $service->users_messages->listUsersMessages($userId, $opt_param); if ($messagesResponse->getMessages()) { $messages = array_merge($messages, $messagesResponse->getMessages()); $pageToken = $messagesResponse->getNextPageToken(); } } catch (Exception $e) { print 'An error occurred: ' . $e->getMessage(); } } while ($pageToken); $speak_emails = array(); $mail_key = 1; foreach ($messages as $message) { $message = $service->users_messages->get($userId, $message->getId()); $headers = $message->payload['modelData']['headers']; foreach ($headers as $key => $header) { if ($header['name'] == 'Subject') { $subject = $header['value']; } if ($header['name'] == 'From') { $from = $header['value']; } if ($header['name'] == 'Date') { $from = $header['value']; } } $speak_emails[$mail_key] = "mail " . $mail_key . ": " . $subject . " Sent by " . $from . " "; $mail_key += 1; } $responses = array("Okay, here we go. ", "Here are your new mails. "); $response = $responses[array_rand($responses, 1)] . implode(": ", $speak_emails); if ($this->speak) { TTS::Speak($response); } }
public function make_coffee() { $date = getdate(); $remind = true; $coffeecount = 1; /** * by default, avy will delay coffee maker for 2 minutes + cron job minute which is probably * less than a minute. and will then remind to manually setup coffeemaker such as water and coffee * including power sources. */ if ($this->triggered['key'] == 0 || $this->triggered['key'] == 1) { $startTime = mktime($date['hours'], $date['minutes'] + 2, 0, $date['mon'], $date['mday'], $date['year']); } /** * if you said now, then set start time pass current time to start as soon as possible. */ if (in_array('now', $this->triggered['triggered'])) { $startTime = mktime($date['hours'], $date['minutes'], $date['seconds'] - 10, $date['mon'], $date['mday'], $date['year']); } /** * schedule coffee maker for tomorrow, add +1 to mday */ if (in_array('tomorrow', $this->triggered['triggered'])) { $date['mday'] += 1; } /** * at start specific time */ if (in_array('at', $this->triggered['triggered'])) { preg_match('/(?<=at )\\S+/i', $this->triggered['keywords'], $timematch); $numbers = implode("", $timematch); if (strlen($numbers) > 2) { if (strlen($numbers) == 3) { $hour = substr($numbers, 0, 1); $minutes = substr($numbers, 1, 2); } else { $hour = substr($numbers, 0, 2); $minutes = substr($numbers, 2, 2); } } else { $hour = $numbers; $minutes = 0; } if (in_array('pm', $this->triggered['filtered'])) { $hour += 12; } $startTime = mktime($hour, $minutes, 0, $date['mon'], $date['mday'], $date['year']); } /** * set schedule when to stop coffee maker */ if (in_array('for', $this->triggered['triggered'])) { preg_match('/(?<=for )\\S+/i', $this->triggered['keywords'], $formatch); $coffeecount = implode("", $formatch); } $stopTime = $startTime + $this->CoffeeTimer * $coffeecount; /** * Print and do action */ if ($startTime <= time()) { $schedule = 'now'; $this->start_coffee_machine(); } else { $schedule = 'at ' . date('h:i A', $startTime); if (in_array('tomorrow', $this->triggered['triggered'])) { $schedule .= " tomorrow."; } else { $schedule .= " today."; } $this->schedule_start_coffee_machine($startTime); } // Schedule stop $this->schedule_stop_coffee_machine($stopTime); TTS::Speak("I will make coffee for " . $coffeecount . " " . $schedule); //echo "The coffee maker should stop at ". date('h:i A Y/m/d', $stopTime)."\n"; }
public function setvolume() { echo "Function: setvolume \n"; $state = $this->state->Get($this->StateStorage); // Check if device is powered ON if ($state['power'] == 1) { $current_volume = $state['volume']; /** * @todo add a function for this */ $name = implode(" ", $this->primarytriggers[array_rand($this->primarytriggers, 1)]); $filtered = $this->removeKeywords($this->triggered['filtered']); if (isset($_GET['vol'])) { $state['volume'] = $_GET['vol']; $value = $_GET['vol']; } if ($findkey = array_search('to', $this->triggered['triggered'])) { if (!isset($value)) { $numberwords = implode(" ", $filtered); $value = $this->wordsToNumber($numberwords); } if ($value > $current_volume) { if ($value <= $this->volume['max']) { $valuediff = $value - $current_volume; $state['volume'] = $value; } else { $valuediff = $this->volume['max'] - $current_volume; $state['volume'] = $this->volume['max']; } $volume_function = 'KEY_VOLUMEUP'; //Do volume up $valuediff number of press } elseif ($value < $current_volume) { /** * @todo add if negative value is used */ if ($value >= $this->volume['min']) { $valuediff = $current_volume - $value; $state['volume'] = $value; } $volume_function = 'KEY_VOLUMEDOWN'; //Do volume up $valuediff number of press } $runfunc = ""; /* * sleep .5; irsend SEND_ONCE PIONEER_AVR KEY_VOLUMEDOWN; */ for ($i = 1; $i <= $valuediff; $i++) { $runfunc .= "sleep .5; irsend SEND_ONCE " . $this->Device . " " . $volume_function . ";"; } TTS::Speak("Setting " . $name . " volume to " . $state['volume']); shell_exec($runfunc); $this->state->Set($this->StateStorage, $state); } } else { TTS::Speak("TV box is currently off."); } }
public function update_core() { $random_response = array('Please wait while I perform system updates!', 'Updating source codes', 'Core files are being updated.'); TTS::Speak($random_response); $output = shell_exec('cd /var/www/Avy && sudo git pull'); echo "\n---OUTPUT---\n"; var_dump($output); }