1 | <?php |
||
7 | trait MessageRegexCommand { |
||
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_regex_commands; |
||
17 | |||
18 | /** |
||
19 | * \brief Add a function that will be executed everytime a message contain a command that match the regex |
||
20 | * \details Use this syntax: |
||
21 | * |
||
22 | * addMessageCommandRegex("number\d", function($bot, $message, $result) { |
||
23 | * $bot->sendMessage("You sent me a number"); }); |
||
24 | * @param $regex_rule Regex rule that will called for evalueting the command received. |
||
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 addMessageCommandRegex(string $regex_rule, callable $script) { |
||
35 | |||
36 | /** |
||
37 | * \brief (<i>Internal</i>) Process the message to check if it triggers a command of this type. |
||
38 | * @param $message Message to process. |
||
39 | * @return True if the message triggered a command. |
||
40 | */ |
||
41 | protected function processMessageRegexCommand(array $message) : bool { |
||
76 | |||
77 | } |
||
78 |
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: