@@ 69-97 (lines=29) @@ | ||
66 | * @param string $message Message to process. |
|
67 | * @return bool True if the message triggered any command. |
|
68 | */ |
|
69 | protected function processMessageCommand(array $message) : bool |
|
70 | { |
|
71 | // If the message contains a bot command at the start |
|
72 | if (isset($message['entities']) && $message['entities'][0]['type'] === 'bot_command') { |
|
73 | // For each command added by the user |
|
74 | foreach ($this->_message_commands as $trigger) { |
|
75 | // If we found a valid command (check first lenght, then use strpos) |
|
76 | if ($trigger['length'] == $message['entities'][0]['length'] && mb_strpos($trigger['command'], $message['text'], $message['entities'][0]['offset']) !== false) { |
|
77 | // Set chat_id |
|
78 | $this->_chat_id = $message['chat']['id']; |
|
79 | ||
80 | // Execute script, |
|
81 | $trigger['script']($this, new Message($message)); |
|
82 | ||
83 | // Return |
|
84 | return true; |
|
85 | } |
|
86 | } |
|
87 | } |
|
88 | ||
89 | // No command were triggered, return false |
|
90 | return false; |
|
91 | } |
|
92 | } |
|
93 |
@@ 70-98 (lines=29) @@ | ||
67 | * @param array $message Message to process. |
|
68 | * @return bool True if the message triggered a command. |
|
69 | */ |
|
70 | protected function processMessageRegexCommand(array $message) : bool |
|
71 | { |
|
72 | // and there are bot commands in the message, checking message entities |
|
73 | if (isset($message['entities']) && $message['entities'][0]['type'] === 'bot_command') { |
|
74 | // For each command added by the user |
|
75 | foreach ($this->_message_commands as $trigger) { |
|
76 | // Use preg_match to check if it is true |
|
77 | if (preg_match("/{$trigger['regex_rule']}/", substr($message['text'], $message['entities'][0]['offset'] + 1, $message['entities'][0]['length']))) { |
|
78 | $this->_chat_id = $message['chat']['id']; |
|
79 | ||
80 | // Trigger the script |
|
81 | $trigger['script']($this, new Message($message)); |
|
82 | return true; |
|
83 | } |
|
84 | } |
|
85 | } |
|
86 | ||
87 | return false; |
|
88 | } |
|
89 | } |
|
90 |