1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JarvisPHP\Plugins\Info_plugin; |
4
|
|
|
|
5
|
|
|
use JarvisPHP\Core\JarvisSession; |
6
|
|
|
use JarvisPHP\Core\JarvisPHP; |
7
|
|
|
use JarvisPHP\Core\JarvisLanguage; |
8
|
|
|
use JarvisPHP\Core\JarvisTTS; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Info plugin |
12
|
|
|
* @author Stefano Bianchini |
13
|
|
|
* @website http://www.stefanobianchini.net |
14
|
|
|
*/ |
15
|
|
|
class Info_plugin implements \JarvisPHP\Core\JarvisPluginInterface{ |
16
|
|
|
/** |
17
|
|
|
* Priority of plugin |
18
|
|
|
* @var int |
19
|
|
|
*/ |
20
|
|
|
var $priority = 1; |
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* the behaviour of plugin |
24
|
|
|
* @param string $command |
25
|
|
|
*/ |
26
|
|
|
function answer($command) { |
|
|
|
|
27
|
|
|
$answer = ''; |
|
|
|
|
28
|
|
|
if(preg_match(JarvisLanguage::translate('preg_match_tell_more',get_called_class()), $command)) { |
29
|
|
|
//Testing session |
30
|
|
|
JarvisPHP::getLogger()->debug('User says: '.$command); |
31
|
|
|
$answer = 'Ok, i am on '. php_uname(); |
32
|
|
|
JarvisSession::terminate(); |
33
|
|
|
} |
34
|
|
|
else { |
35
|
|
|
JarvisPHP::getLogger()->debug('Answering to command: "'.$command.'"'); |
36
|
|
|
$answer = sprintf(JarvisLanguage::translate('my_name_is',get_called_class()),_SYSTEM_NAME, $_SERVER['SERVER_NAME'],$_SERVER['SERVER_ADDR']); |
37
|
|
|
|
38
|
|
|
} |
39
|
|
|
JarvisTTS::speak($answer); |
40
|
|
|
$response = new \JarvisPHP\Core\JarvisResponse($answer, JarvisPHP::getRealClassName(get_called_class()), true); |
41
|
|
|
$response->send(); |
42
|
|
|
} |
43
|
|
|
/** |
44
|
|
|
* Get plugin's priority |
45
|
|
|
* @return int |
46
|
|
|
*/ |
47
|
|
|
function getPriority() { |
|
|
|
|
48
|
|
|
return $this->priority; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Is it the right plugin for the command? |
53
|
|
|
* @param string $command |
54
|
|
|
* @return boolean |
55
|
|
|
*/ |
56
|
|
|
function isLikely($command) { |
|
|
|
|
57
|
|
|
return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Does the plugin need a session? |
62
|
|
|
* @return boolean |
63
|
|
|
*/ |
64
|
|
|
function hasSession() { |
|
|
|
|
65
|
|
|
return true; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.