Skip to content

Commit df45ffc

Browse files
authored
Merge branch 'develop' into patch-1
2 parents bdc5e68 + 83436f8 commit df45ffc

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
99
### Deprecated
1010
### Removed
1111
### Fixed
12+
- `Telegram::enableAdmin()` now handles duplicate additions properly.
13+
- `Request::getMe()` failure doesn't break cron execution any more.
1214
### Security
1315

1416
## [0.46.0] - 2017-07-15

src/Telegram.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,10 @@ protected function sanitizeCommand($command)
520520
*/
521521
public function enableAdmin($admin_id)
522522
{
523-
if (is_int($admin_id) && $admin_id > 0 && !in_array($admin_id, $this->admins_list, true)) {
524-
$this->admins_list[] = $admin_id;
525-
} else {
523+
if (!is_int($admin_id) || $admin_id <= 0) {
526524
TelegramLog::error('Invalid value "%s" for admin.', $admin_id);
525+
} elseif (!in_array($admin_id, $this->admins_list, true)) {
526+
$this->admins_list[] = $admin_id;
527527
}
528528

529529
return $this;
@@ -904,15 +904,20 @@ public function runCommands($commands)
904904
$this->run_commands = true;
905905
$this->botan_enabled = false; // Force disable Botan.io integration, we don't want to track self-executed commands!
906906

907-
$result = Request::getMe()->getResult();
907+
$result = Request::getMe();
908908

909-
if (!$result->getId()) {
910-
throw new TelegramException('Received empty/invalid getMe result!');
909+
if ($result->isOk()) {
910+
$result = $result->getResult();
911+
912+
$bot_id = $result->getId();
913+
$bot_name = $result->getFirstName();
914+
$bot_username = $result->getUsername();
915+
} else {
916+
$bot_id = $this->getBotId();
917+
$bot_name = $this->getBotUsername();
918+
$bot_username = $this->getBotUsername();
911919
}
912920

913-
$bot_id = $result->getId();
914-
$bot_name = $result->getFirstName();
915-
$bot_username = $result->getUsername();
916921

917922
$this->enableAdmin($bot_id); // Give bot access to admin commands
918923
$this->getCommandsList(); // Load full commands list

0 commit comments

Comments
 (0)