@link http://blog.idleman.fr @licence CC by nc sa @version 1.0.0 @description Permet la récuperations d'informations locales ou sur le web comme la météo, les séries TV, l'heure, la date et l'état des GPIO */ define('VOCALINFO_COMMAND_FILE','cmd.json'); function vocalinfo_vocal_command(&$response,$actionUrl){ global $conf; $commands = json_decode(file_get_contents(__ROOT__.'/'.Plugin::path().'/'.VOCALINFO_COMMAND_FILE),true); foreach($commands as $key=>$command){ if($command['disabled']=='true') continue; $response['commands'][] = array( 'command'=>$conf->get('VOCAL_ENTITY_NAME').' '.$command['command'], 'url'=>$actionUrl.$command['url'], 'confidence'=>($command['confidence']+$conf->get('VOCAL_SENSITIVITY')) ); } $response['commands'][] = array( 'command'=>$conf->get('VOCAL_ENTITY_NAME').' imite le bruit de la poule', 'callback'=>'vocalinfo_chicken', 'parameters' => array('un','deux'), 'confidence'=>0.8); $response['commands'][] = array( 'command'=>$conf->get('VOCAL_ENTITY_NAME').' Définit le mot', 'callback'=>'vocalinfo_define_word', 'confidence'=>0.8); $response['commands'][] = array( 'command'=>$conf->get('VOCAL_ENTITY_NAME').' présente toi', 'callback'=>'vocalinfo_give_me_all', 'confidence'=>0.8); $response['commands'][] = array( 'command'=>$conf->get('VOCAL_ENTITY_NAME').' enerve toi', 'callback'=>'vocalinfo_emotion_angry', 'confidence'=>0.8); $response['commands'][] = array( 'command'=>$conf->get('VOCAL_ENTITY_NAME').' montre toi', 'callback'=>'vocalinfo_show_you', 'confidence'=>0.8); $response['commands'][] = array( 'command'=>$conf->get('VOCAL_ENTITY_NAME').' lance le programme', 'callback'=>'vocalinfo_launch_program', 'confidence'=>0.8); $response['commands'][] = array( 'command'=>$conf->get('VOCAL_ENTITY_NAME').' test des variables', 'callback'=>'vocalinfo_test_variables', 'confidence'=>0.8); } function vocalinfo_test_variables($text,$confidence,$parameters,$myUser){ global $conf; $cli = new Client(); $cli->connect(); $cli->talk("Utilisateur: ".$myUser->getLogin()); $cli->talk("configuration: ".$conf->get('UPDATE_URL')); $cli->disconnect(); } function vocalinfo_define_word($text,$confidence,$parameters){ $cli = new Client(); $cli->connect(); if($text=='bistro'){ $cli->talk("Un bistro est un lieu de cultes, ou les sages de ce siècle vont se recueillir"); }else{ $json = json_decode(file_get_contents('https://fr.wikipedia.org/w/api.php?action=opensearch&search='.$text),true); $define = $json[2][0]; if($json==false || trim($define)==""){$cli->talk("Le mot ".$text." ne fait pas partie de mot vocabulaire, essayez plutot avec le mot bistro"); $cli->disconnect(); return; } $cli->talk($define); } $cli->disconnect(); //Client::execute("D:\Programme_installes\Qt\Tools\QtCreator\bin\qtcreator.exe"); } function vocalinfo_show_you($text,$confidence,$parameters){ $cli = new Client(); $cli->connect(); $cli->image(YANA_URL."/plugins/vocal_infos/img/yana.jpg"); $cli->talk("Est ce que tu me trouve jolie?"); $cli->disconnect(); } function vocalinfo_emotion_angry($text,$confidence,$parameters){ $cli = new Client(); $cli->connect(); $cli->talk("Tu vois ce qui se passe quand tu me prend la tête ?"); $cli->emotion("angry"); $cli->disconnect(); } function vocalinfo_chicken($text,$confidence,$parameters){ $cli = new Client(); $cli->connect(); $cli->sound("C:/poule.wav"); $cli->disconnect(); } function vocalinfo_launch_program($text,$confidence,$parameters){ $cli = new Client(); $cli->connect(); switch($text){ case 'sublime texte': $cli->execute("C:\Program Files\Sublime Text 2\sublime_text.exe"); $cli->talk("Programme en cours de lancement"); break; default: $cli->talk("Je ne connais pas le programme : ".$text); break; } $cli->disconnect(); } function vocalinfo_give_me_all($text,$confidence,$parameters){ $cli = new Client(); $cli->connect(); $cli->talk("Je peux parler, evidemment, et t\'écouter plus précisément qu\'avant"); $cli->talk("Je peux eprouver et montrer des sentiments"); $cli->talk("Comme la colère"); $cli->emotion("angry"); $cli->talk("Ou la timidité"); $cli->emotion("shy"); $cli->talk("Et tout un tas d\'autres lubies humaines"); $cli->talk("Je peux aussi exécuter un programme"); $cli->execute("D:\Programme_installes\Qt\Tools\QtCreator\bin\qtcreator.exe"); $cli->talk("ou un son"); $cli->sound("C:/poule.wav"); $cli->talk("ou te montrer des images"); $cli->image("yana.jpg"); $cli->talk("ou executer une commande domotique"); //system('gpio write 1 1'); //$cli->talk("ou executer un humain"); //$cli->talk("non je déconne."); $cli->disconnect(); } function vocalinfo_action(){ global $_,$conf; switch($_['action']){ case 'plugin_vocalinfo_save': $commands = json_decode(file_get_contents(Plugin::path().'/'.VOCALINFO_COMMAND_FILE),true); foreach($_['config'] as $key=>$config){ $commands[$key]['confidence'] = $config['confidence']; $commands[$key]['disabled'] = $config['disabled']; } file_put_contents(Plugin::path().'/'.VOCALINFO_COMMAND_FILE,json_encode($commands)); echo 'Enregistré'; break; case 'vocalinfo_plugin_setting': $conf->put('plugin_vocalinfo_place',$_['weather_place']); $conf->put('plugin_vocalinfo_woeid',$_['woeid']); header('location:setting.php?section=preference&block=vocalinfo'); break; case 'vocalinfo_sound': global $_; $response = array('responses'=>array( array('type'=>'sound','file'=>$_['sound']) ) ); $json = json_encode($response); echo ($json=='[]'?'{}':$json); break; case 'vocalinfo_devmod': $response = array('responses'=>array( array('type'=>'command','program'=>'C:\Program Files\Sublime Text 2\sublime_text.exe'), array('type'=>'talk','sentence'=>'Sublim text lancé.') ) ); $json = json_encode($response); echo ($json=='[]'?'{}':$json); break; case 'vocalinfo_gpio_diag': $sentence = ''; $gpio = array('actif'=>array(),'inactif'=>array()); for ($i=0;$i<26;$i++) { $commands = array(); exec("/usr/local/bin/gpio read ".$i,$commands,$return); if(trim($commands[0])=="1"){ $gpio['actif'][] = $i; }else{ $gpio['inactif'][] = $i; } } if(count($gpio['actif'])==0){ $sentence .= 'Tous les GPIO sont inactifs.'; }else if(count($gpio['inactif'])==0){ $sentence .= 'Tous les GPIO sont actifs.'; }else{ $sentence .= 'GPIO actifs: '.implode(', ', $gpio['actif']).'. GPIO inactifs: '.implode(', ', $gpio['inactif']).'.'; } $response = array('responses'=>array( array('type'=>'talk','sentence'=>$sentence) ) ); $json = json_encode($response); echo ($json=='[]'?'{}':$json); break; case 'vocalinfo_commands': $actionUrl = 'http://'.$_SERVER['SERVER_ADDR'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI']; $actionUrl = substr($actionUrl,0,strpos($actionUrl , '?')); $commands = array(); Plugin::callHook("vocal_command", array(&$commands,$actionUrl)); $sentence ='Je répond aux commandes suivantes: '; foreach ($commands['commands'] as $command) { $sentence .=$command['command'].'. '; } $response = array('responses'=>array( array('type'=>'talk','sentence'=>$sentence) ) ); $json = json_encode($response); echo ($json=='[]'?'{}':$json); break; case 'vocalinfo_meteo': global $_; if($conf->get('plugin_vocalinfo_woeid')!=''){ $contents = file_get_contents('http://weather.yahooapis.com/forecastrss?w='.$conf->get('plugin_vocalinfo_woeid').'&u=c'); $xml = simplexml_load_string($contents); if( (isset($_['today']))) { $weekdays = $xml->xpath('/rss/channel/item/yweather:condition'); } else { $weekdays = $xml->xpath('/rss/channel/item/yweather:forecast'); } //Codes disponibles ici: http://developer.yahoo.com/weather/#codes $textTranslate = array( 'Showers'=>'des averses', 'Tornado' => 'Attention: Tornade!', 'Hurricane' => 'Attention: Ouragan!', 'Severe thunderstorms' => 'Orages violents', 'Mixed rain and snow' => 'Pluie et neiges', 'Mixed rain and sleet' => 'Pluie et neige fondue', 'Mixed snow and sleet' => 'Neige et neige fondue', 'Freezing drizzle' => 'Bruine verglassant', 'Drizzle' => 'Bruine', 'Freezing rain' => 'Pluie verglassant', 'Showers' => 'Averse', 'Snow flurries' => 'Bourrasque de neige', 'Light snow showers' => 'Averse de neige lègére', 'Blowing snow' => 'Chasse neige', 'Snow' => 'Neige', 'Hail' => 'Grêle', 'Sleet' => 'Neige fondue', 'Dust' => 'Poussière', 'Foggy' => 'Brouillard', 'Smoky' => 'Fumée', 'Blustery' => 'Froid et venteux', 'Windy' => 'Venteux', 'Cold' => 'Froid', 'Cloudy' => 'Nuageux', 'Fair' => 'Ciel dégagé', 'Mixed rain and hail' => 'Pluie et grêle', 'Hot' => 'Chaud', 'Isolated thunderstorms' => 'Orages isolées', 'Scattered showers' => 'Averse éparse', 'Heavy snow' => 'Fortes chutes de neige', 'Scattered snow showers' => 'Averse de neige éparse', 'Thunderstorms' => 'Orages', 'Thundershowers' => 'Grain sous orage violents', 'Isolated thundershowers' => 'Grain sous orage isolées', 'Not available' => 'Non disponible', 'Scattered Thunderstorms' => 'Orages éparses', 'Partly Cloudy'=>'Partiellement nuageux', 'Mostly Sunny'=>'plutot ensoleillé', 'Mostly Cloudy'=>'plutot Nuageux', 'Light Rain'=>'Pluie fine', 'Clear'=>'Temps clair', 'Sunny'=>'ensoleillé', 'Rain/Wind'=>'Pluie et vent', 'Rain'=>'Pluie', 'Wind'=>'Vent', 'Partly Cloudy/Wind'=>'Partiellement nuageux avec du vent' ); $dayTranslate = array('Wed'=>'mercredi', 'Sat'=>'samedi', 'Mon'=>'lundi', 'Tue'=>'mardi', 'Thu'=>'jeudi', 'Fri'=>'vendredi', 'Sun'=>'dimanche'); $affirmation = ''; foreach($weekdays as $day){ if (substr($day['text'],0,2) == "AM") { $sub_condition = substr($day['text'],3); $condition = (isset($textTranslate[''.$sub_condition])?$textTranslate[''.$sub_condition]:$sub_condition)." dans la matinée"; } elseif (substr($day['text'],0,2) == "PM") { $sub_condition = substr($day['text'],3); $condition = (isset($textTranslate[''.$sub_condition])?$textTranslate[''.$sub_condition]:$sub_condition)." dans l'après midi"; } elseif (substr($day['text'],-4) == "Late") { $sub_condition = substr($day['text'],0,-5); $condition = (isset($textTranslate[''.$sub_condition])?$textTranslate[''.$sub_condition]:$sub_condition)." en fin de journée"; } else { $condition = isset($textTranslate[''.$day['text']])?$textTranslate[''.$day['text']]:$day['text']; } if( (isset($_['today']))) { $affirmation .= 'Aujourd\'hui '.$day['temp'].' degrés, '.$condition.', '; } else { $affirmation .= $dayTranslate[''.$day['day']].' de '.$day['low'].' à '.$day['high'].' degrés, '.$condition.', '; } } }else{ $affirmation = 'Vous devez renseigner votre ville dans les préférences de l\'interface oueb, je ne peux rien vous dire pour le moment.'; } $response = array('responses'=>array( array('type'=>'talk','sentence'=>$affirmation) ) ); $json = json_encode($response); echo ($json=='[]'?'{}':$json); break; case 'vocalinfo_tv': global $_; libxml_use_internal_errors(true); $contents = file_get_contents('http://webnext.fr/epg_cache/programme-tv-rss_'.date('Y-m-d').'.xml'); $xml = simplexml_load_string($contents); $emissions = $xml->xpath('/rss/channel/item'); $focus = array(); $time = time(); $date = date('m/d/Y ',$time); $focusedCanals = array('TF1','France 2','France 3','France 4','Canal+','Arte','France 5','M6'); foreach($emissions as $emission){ $item = array(); list($item['canal'],$item['hour'],$item['title']) = explode(' | ',$emission->title); $itemTime = strtotime($date.$item['hour']); if($itemTime>=$time-3600 && $itemTime<=$time+3600 && in_array($item['canal'], $focusedCanals)){ if( (isset($_['category']) && $_['category']==''.$emission->category) || !isset($_['category']) ){ $item['category'] = ''.$emission->category; $item['description'] = strip_tags(''.$emission->description); $focus[$item['title'].$item['canal']][] = $item; } } } $affirmation = ''; $response = array(); foreach($focus as $emission){ $nb = count($emission); $emission = $emission[0]; $affirmation = array(); $affirmation['type'] = 'talk'; //$affirmation['style'] = 'slow'; $affirmation['sentence'] = ($nb>1?$nb.' ':'').ucfirst($emission['category']).', '.$emission['title'].' à '.$emission['hour'].' sur '.$emission['canal']; $response['responses'][] = $affirmation; } $json = json_encode($response); echo ($json=='[]'?'{}':$json); break; case 'vocalinfo_hour': global $_; $affirmation = 'Il est '.date('H:i'); $response = array('responses'=>array( array('type'=>'talk','sentence'=>$affirmation) ) ); $json = json_encode($response); echo ($json=='[]'?'{}':$json); break; case 'vocalinfo_day': global $_; $affirmation = 'Nous sommes le '.date('d/m/Y'); $response = array('responses'=>array( array('type'=>'talk','sentence'=>$affirmation) ) ); $json = json_encode($response); echo ($json=='[]'?'{}':$json); break; case 'vocalinfo_wikipedia': global $_; $url = 'http://fr.wikipedia.org/w/api.php?action=parse&page='.$_['word'].'&format=json&prop=text§ion=0'; $ch = curl_init($url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr-FR; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1" ); // required by wikipedia.org server; use YOUR user agent with YOUR contact information. (otherwise your IP might get blocked) $c = curl_exec($ch); $json = json_decode($c); $content = $json->{'parse'}->{'text'}->{'*'}; // get the main text content of the query (it's parsed HTML) $affirmation = strip_tags(str_replace(' ', ' ', $content)); // ' ' is a space, but is not recognized by yana trying to read "160" $response = array('responses'=>array( array('type'=>'talk','sentence'=>$affirmation) ) ); $json = json_encode($response); echo ($json=='[]'?'{}':$json); break; case 'vocalinfo_mood': global $_; $possible_answers = array( 'parfaitement' ,'ça pourrait aller mieux' ,'ça roule mon pote !' ,'nickel' ,'pourquoi cette question ?' ); $affirmation = $possible_answers[rand(0,count($possible_answers)-1)]; $response = array('responses'=>array( array('type'=>'talk','sentence'=>$affirmation) ) ); $json = json_encode($response); echo ($json=='[]'?'{}':$json); break; } } function vocalinfo_event(&$response){ if(date('d/m H:i')=='24/01 15:00'){ if(date('s')<45){ $response['responses']= array( array('type'=>'sound','file'=>'sifflement.wav'), array('type'=>'talk','sentence'=>'C\'est l\'anniversaire de mon créateur, pensez à lui offrir une bière!') ); } } } function vocalinfo_plugin_preference_menu(){ global $_; echo '
  • Informations Vocales
  • '; } function vocalinfo_plugin_preference_page(){ global $myUser,$_,$conf; if((isset($_['section']) && $_['section']=='preference' && @$_['block']=='vocalinfo' ) ){ if($myUser!=false){ Plugin::addjs("/js/woeid.js",true); Plugin::addJs('/js/main.js',true); $commands = json_decode(file_get_contents(Plugin::path().'/'.VOCALINFO_COMMAND_FILE),true); ?>
    Commandes $command){ ?>
    Commande Confidence
    class="enabled">get('VOCAL_ENTITY_NAME').' '.$command['command']; ?>
    Enregistrer
    Météo Chercher

    Vous devez être connecté