Skip to content

Custom namespace fixes #1115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 13 additions & 7 deletions src/Telegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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' => [
Expand All @@ -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());
}
Expand Down