@@ 70-98 (lines=29) @@ | ||
67 | * @param string $message Message to process. |
|
68 | * @return bool True if the message trigger any command. |
|
69 | */ |
|
70 | protected function processMessageCommand(array $message) : bool |
|
71 | { |
|
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 length, then use strpos) |
|
76 | if ($trigger['length'] == $message['entities'][0]['length'] && |
|
77 | mb_strpos($trigger['command'], $message['text'], $message['entities'][0]['offset']) !== false) { |
|
78 | // Execute the script. |
|
79 | $this->_chat_id = $message['chat']['id']; |
|
80 | $trigger['script']($this, new Message($message)); |
|
81 | ||
82 | return true; |
|
83 | } |
|
84 | } |
|
85 | } |
|
86 | ||
87 | return false; |
|
88 | } |
|
89 | } |
|
90 |
@@ 71-99 (lines=29) @@ | ||
68 | * @param array $message Message to process. |
|
69 | * @return bool True if the message triggered a command. |
|
70 | */ |
|
71 | protected function processMessageRegexCommand(array $message) : bool |
|
72 | { |
|
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 | if (preg_match("/{$trigger['regex_rule']}/", substr($message['text'], $message['entities'][0]['offset'] + 1, $message['entities'][0]['length']))) { |
|
77 | $this->_chat_id = $message['chat']['id']; |
|
78 | ||
79 | $trigger['script']($this, new Message($message)); |
|
80 | return true; |
|
81 | } |
|
82 | } |
|
83 | } |
|
84 | ||
85 | return false; |
|
86 | } |
|
87 | } |
|
88 |