1 | <?php |
||
7 | trait MessageCommand { |
||
8 | |||
9 | /** |
||
10 | * \addtogroup Commands |
||
11 | * \brief What commands are |
||
12 | * @{ |
||
13 | */ |
||
14 | |||
15 | /** \brief (<i>Internal</i>)Store the command triggered on message. */ |
||
16 | protected $_message_commands; |
||
17 | |||
18 | /** |
||
19 | * \brief Add a function that will be executed everytime a message contain the selected command |
||
20 | * \details Use this syntax: |
||
21 | * |
||
22 | * addMessageCommand("start", function($bot, $message) { |
||
23 | * $bot->sendMessage("Hi"); }); |
||
24 | * @param $command The command that will trigger this function (without slash). Eg: "start", "help", "about" |
||
25 | * @param $script The function that will be triggered by a command. Must take an object(the bot) and an array(the message received). |
||
26 | */ |
||
27 | public function addMessageCommand(string $command, callable $script) { |
||
36 | |||
37 | /** |
||
38 | * \brief (<i>Internal</i>)Process a message checking if it trigger any MessageCommand. |
||
39 | * @param $message Message to process. |
||
40 | * @return True if the message triggered any command. |
||
41 | */ |
||
42 | protected function processMessageCommand(array $message) : bool { |
||
77 | |||
78 | } |
||
79 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: