1 | <?php |
||
30 | class MessageRegexCommand extends BasicCommand |
||
31 | { |
||
32 | /** @} */ |
||
33 | |||
34 | /** |
||
35 | * \brief Add a function that will be executed everytime a message contain a command |
||
36 | * that match the regular expression. |
||
37 | * |
||
38 | * \details Use this syntax: |
||
39 | * |
||
40 | * addMessageCommandRegex("number\d", function($bot, $message, $result) { |
||
41 | * $bot->sendMessage("You sent me a number"); }); |
||
42 | * @param string $regex_rule Regex rule that will called for evalueting the command received. |
||
43 | * @param callable $script The function that will be triggered by a command. |
||
44 | * Must take an object(the bot) and an array(the message received). |
||
45 | */ |
||
46 | public function __construct(string $regex_rule, callable $script) |
||
51 | |||
52 | /** |
||
53 | * @internal |
||
54 | * \brief Process the message to check if it triggers a command of this type. |
||
55 | * @param array $message Message to process. |
||
56 | * @return bool True if the message triggered a command. |
||
57 | */ |
||
58 | public function checkCommand(array $message) : bool |
||
70 | } |
||
71 |
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: