((^состояние).*)|(^статус$)|(^как ты)|((^как).*(дела))|(^что у нас)
Код
say("Дела как сажа бела...",2);
say("Это я так шучу...",2);
rs(reportStatus);
$w1=getGlobal('Sensor_power02.value');
$t2=getGlobal('Sensor_temp03.value');
say ('Кошка опять нагадила...морда...');
say ('Холодильник на балконе жрет как не в себе...'.$t1.' кВт уже накушал. Температура на балконе '.$t2.' градусов',1);
|
(start|play) music
Код
runScript('playFavoriteMusic');
|
(Д|д)авай приготовим (.+)
Код
$queryString = $matches[2];
/*
$findParams = array(
'aerogrill' => '22', // Рецепты для аэрогриля
'waffle' => '27', // Для вафельницы
'yoghurt' => '28', // Для йогуртиницы
'multivarka' => '25', //Рецепты для мультиварки
'steamer' => '15', //Для пароварки
'pressureCooker' => '46', //Для скороварки
'breadMaker' => '23', //Для хлебопечки
'fondue' => '24' //Рецепты фондю
);
*/
$findParams = array();
$recipeNumber = rand(0, 1);
$recipesList = findRecipes($queryString, $findParams);
if (!empty($recipesList)) {
$recipe = getRecipes($recipesList[$recipeNumber]['link']);
$recipe['link'] = $recipesList[$recipeNumber]['link'];
$recipe['name'] = $recipesList[$recipeNumber]['text'];
sayRecipe($recipe);
sg('ThisComputer.KitchenUrl',$recipe['link']);
} else {
say('Ничего не найдено.');
}
function sayRecipe($recipe) {
say($recipe['name']);
if (!empty($recipe['description'])) {
foreach ($recipe['description'] as $e) {
say($e);
}
}
$ingrstr = 'Нам понадобится: ';
foreach ($recipe['ingredients'] as $e) {
$ingrstr .= $e . ', ';
}
say($ingrstr);
say('Способ приготовления:');
foreach ($recipe['preparing'] as $e) {
say($e);
}
$rec=array();
$rec['EVENT_TYPE']='openurl'; // команда может быть ещё newwindow
$rec['WINDOW']='alice';
$rec['TERMINAL_TO']='*'; //здесь можно конкретный терминал указать
$rec['ADDED']=date('Y-m-d H:i:s');
$rec['EXPIRE']=date('Y-m-d H:i:s', time()+10);
$rec['DETAILS']=$recipe['link'];
$rec['ID']=SQLInsert('events', $rec);
}
function getRecipes($recipeLink) {
if (empty($recipeLink)) {
return FALSE;
}
$html = @file_get_contents($recipeLink);
$doc = new DOMDocument();
@$doc->loadHTML($html);
$xpath = new DOMXpath($doc);
$ingredients = array();
$description = array();
$ingredientsDom = $xpath->query('//table[@class="rec-ingred-table"]/tr');
if ($ingredientsDom->length > 0) {
foreach ($ingredientsDom as $item) {
$ingredients[] = trim(preg_replace("/[\r\n]+/", " ", $item->nodeValue));
}
$descriptionDom = $xpath->query('//div[@class="b-page_block__outside"]/p');
foreach ($descriptionDom as $item) {
$description[] = trim(preg_replace("/[\r\n]+/", " ", $item->nodeValue));
}
} else {
$ingredientsDom = $xpath->query('//div[@class="b-page_block__outside"]/p');
foreach ($ingredientsDom as $item) {
$ingredients[] = trim(preg_replace("/[\r\n]+/", " ", $item->nodeValue));
}
}
$preparingDom = $xpath->query('//div[@class="b-list__clause__text"]/p');
$preparing = array();
foreach ($preparingDom as $item) {
$preparing[] = trim(preg_replace("/[\r\n]+/", " ", $item->nodeValue));
}
$recipe = array(
'description' => $description,
'ingredients' => $ingredients,
'preparing' => $preparing
);
return $recipe;
}
function findRecipes($queryString, $params) {
if (empty($queryString)) {
return FALSE;
}
$url = 'http://www.edimdoma.ru/search?utf8=%E2%9C%93&asset=recipes&index=title_search&query=' . urlencode($queryString) . '&search%5Bmain_category_id%5D=&search%5Bcuisine_id%5D=';
if (!empty($params)) {
foreach ($params as &$value) {
$url .= '&cooking_method_ids%5B%5D=' . $value;
}
}
$url .= '&user_name=';
$html = @file_get_contents($url);
$doc = new DOMDocument();
@$doc->loadHTML($html);
$xpath = new DOMXpath($doc);
$articles = $xpath->query('//div[@class="b-page_block__header"]');
$links = array();
foreach ($articles as $container) {
$arr = $container->getElementsByTagName("a");
foreach ($arr as $item) {
if ($item->parentNode->tagName == "h2") {
$href = $item->getAttribute("href");
$text = trim(preg_replace("/[\r\n]+/", " ", $item->nodeValue));
$links[] = array(
'link' => $href,
'text' => $text
);
}
}
}
return $links;
}
|
(день недели|какой сегодня день недели|какое сегодня число)
Код
sayReply('Сегодня '.gg('ThisComputer.Date').' '.gg('ThisComputer.Day'),4);
|
(Кто ты|как тебя зовут|кто это говорит|это еще кто)
Код
say('Меня зовут Алиса. Я по мере возможности управляю автоматикой и информационными системами дома',2);
|
(поставь|установи|заведи) будильник на (\d+)(\s*)(часов|:)*(\s*)(\d*)
Код
$h=$matches[2];
$m=$matches[6];
if ($h>24) {
sayReply('Непонятно на который час завести будильник, определитесь и сообщите снова.',2);
return;
}
if (($m>59)|(!$m)) {
sayReply('Непонятно на сколько минут завести будильник, поэтому пусть будет ровно 00.',2);
$m='00';
}
sayReply('Ставлю будильник на '.$h.' часов '.$m.' минут. Постарайтесь не проспать.',2);
setGlobal('AlarmOne.AlarmOn',1);
setGlobal('AlarmOne.AlarmTime',$h.':'.$m);
|
(температура).*(дом)
Код
$t1=getGlobal('TempSensor2.temp1');
$t2=getGlobal('TempSensor1.temp1');
say ('В гостинной '.$t1.' градусов, в зале второго этажа '.$t2.' градусов',1);
|
(Что сейчас на улице)|(что за бортом)|(что на улице)
Код
$status="";
$status.="Сегодня ".gg("ow_fact.weather_type").".";
say($status,2);
$status="";
$w=round(gg("ow_fact.temperature"));
$tempw=$w;
if($tempw >= 11 and $tempw <= 14){
$tempcels=" градусов ";
}
else{
while ($tempw > 9){
$tempw=$tempw-10;
}
if($tempw == 0 or $tempw >= 5 and $tempw <= 9){
$tempcels= градусов ; }
if($tempw == 1){
$tempcels= градус ; }
if($tempw >= 2 and $tempw <= 4){
$tempcels= градуса ; }
}
$tNew = abs((float)getGlobal('ow_fact.temperature'));
$status.=' Температура '.getGlobal('ow_fact.temperature')." ".$tempcels." цельсия";
say($status,2);
$tempw="";
$tempcels="";
$status="";
$h=round(gg("ow_fact.humidity"));
$tempw=$h;
if($tempw >= 11 and $tempw <= 14){
$tempcels=" процентов ";
}
else{
while ($tempw > 9){
$tempw=$tempw-10;
}
if($tempw == 0 or $tempw >= 5 and $tempw <= 9){
$tempcels= процентов ; }
if($tempw == 1){
$tempcels= процент ; }
if($tempw >= 2 and $tempw <= 4){
$tempcels= процента ; }
}
$status.="Относительная влажность ".gg("ow_fact.humidity")." ".$tempcels. ".";
say($status,2);
$tempw="";
$tempcels="";
$status="";
$pressure=(float)gg("ow_fact.pressure_mmhg");
if ($pressure<730) {
$status.=' Атмосферное давление пониженное';
} elseif ($pressure>750) {
$status.=' Атмосферное давление повышенное.';
} else {
$status.=' Атмосферное давление нормальное.';
}
say($status,2);
$status="";
//ветер
$WindSpeed=(float)gg("ow_fact.wind_speed");
if ($WindSpeed<1) {
$status.=' Ветра нет.';
} elseif ($WindSpeed<3) {
$status.=' Ветер слабый.';
} elseif ($WindSpeed<6) {
$status.=' Ветер сильный.';
} elseif ($WindSpeed<9) {
$status.=' Ветер очень сильный.';
} else {
$status.=' Ветер очень! Очень сильный.';
}
say($status,2);
|
(Ш|ш|Ч|ч|К|к|Х|х)то тако(е|й) (.+)
Код
debmes('1 '.$matches[1]);
//debmes('2 '.$matches[2]);
runScript('wiki', array('zapros' => $matches[2]));
|
ip
|
report system state
|
Лампа
Код
callMethod('Relay07.turnOn');
say('Включаю лампу',1);
|
напомни через (\d+) минут (.+)
Код
say("Хорошо.",1);
setTimeOut('timer','say("'.$matches[2].'",2);',$matches[1]*60);
|
Отправь в Телегу
|
повтори (.+)
Код
|
Погода
|
Привет
Код
if(timeBetween("05:00", "11:00")){
sayReply("Доброе утро!",5);
}elseif(timeBetween("11:00", "17:00")){
sayReply("Добрый день!",5);
}elseif(timeBetween("17:00", "23:00")){
sayReply("Добрый вечер!",5);
}elseif(timeBetween("23:00", "05:00")){
sayReply("Доброй ночи!",5);
}else{ // Новое, неизвестное время суток.
sayReply('Привет!',1);
}
|
расскажи
Код
say("Что именно рассказать?",2);
|
(сказ(.*)
Код
if (preg_match('/включи/uis',$original)) {
runScript('playSkazki');
say(LANG_DONE,1);
} elseif (preg_match('/выключи/uis',$original)) {
runScript('RadioStop');
say(LANG_DONE,1);
} else {
say('Непонятно что делать: '.$original,1);
}
|
анекдот
|
рассказ
|
тост
Код
/*
1 - Анекдот;
2 - Рассказы;
3 - Стишки;
4 - Афоризмы;
5 - Цитаты;
6 - Тосты;
8 - Статусы;
11 - Анекдот (+18);
12 - Рассказы (+18);
13 - Стишки (+18);
14 - Афоризмы (+18);
15 - Цитаты (+18);
16 - Тосты (+18);
18 - Статусы (+18);
*/
function GetJoke($ctype = 6) {
$pretext = array("Слушай", "Слушай тост", "Один мудрый человек говорит", "Вот еще тост", "Нууу....");
$number = mt_rand(0, count($pretext) - 1);
$res = geturl('http://rzhunemogu.ru/Rand.aspx?CType=' . $ctype, 0);
$res = win2utf($res);
$xml = new SimpleXMLElement($res);
$joke = trim(preg_replace('/\s{2,}/', ' ', $xml->content));
$joke = $pretext[$number] . ': ' . $joke;
if (strlen($joke) > 500) {
sleep(10);
GetJoke();
} else {
//return $joke;
//say($pretext[$number].':', 1);
say($joke, 1);
}
}
//if (gg('ThisComputer.SayJokes') != 0) {
GetJoke();
//}
|
|
сколько будет (.*)
Код
$command=$matches[1];
$com=str_replace(',','.',$command);
$com=str_replace('разделить на','/',$com);
$com=str_replace('делить на','/',$com);
$com=str_replace('умножить на','*',$com);
$com=str_replace('на','*',$com);
$com=str_replace('плюс','+',$com);
$com=str_replace('минус','-',$com);
$com='$result=' . $com .';';
eval($com);
$result=str_replace('.',',',$result);
say($command.' равно '.$result,2);
|