diff --git a/CHANGELOG.md b/CHANGELOG.md index fdd6565c0..7ce0c6908 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ### Deprecated ### Removed ### Fixed +- Regex in `getFileNamespace()` that introduced a breaking bug (#1114) +- Fixed `runCommands()` not working due to custom namespace feature ### Security ## [0.63.0] - 2020-06-17 diff --git a/src/Telegram.php b/src/Telegram.php index a582149df..71c104511 100644 --- a/src/Telegram.php +++ b/src/Telegram.php @@ -345,7 +345,7 @@ public function getCommandObject($command, $filepath = null) protected function getFileNamespace($src) { $content = file_get_contents($src); - if (preg_match('#^namespace\s+(.+?);$#sm', $content, $m)) { + if (preg_match('#^namespace\s+(.+?);#m', $content, $m)) { return $m[1]; } return null; @@ -1012,12 +1012,11 @@ public function runCommands($commands) $bot_username = $this->getBotUsername(); } + // Give bot access to admin commands + $this->enableAdmin($bot_id); - $this->enableAdmin($bot_id); // Give bot access to admin commands - $this->getCommandsList(); // Load full commands list - - foreach ($commands as $command) { - $this->update = new Update( + $newUpdate = static function ($text = '') use ($bot_id, $bot_name, $bot_username) { + return new Update( [ 'update_id' => 0, 'message' => [ @@ -1032,10 +1031,17 @@ public function runCommands($commands) 'id' => $bot_id, 'type' => 'private', ], - 'text' => $command, + 'text' => $text, ], ] ); + }; + + $this->update = $newUpdate(); // Required for isAdmin() check inside getCommandObject() + $this->commands_objects = $this->getCommandsList(); // Load up-to-date commands list + + foreach ($commands as $command) { + $this->update = $newUpdate($command); $this->executeCommand($this->update->getMessage()->getCommand()); }