From 93ff2ccab935e6c9359e71f5afd6098fc3c77978 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 27 Dec 2019 15:25:33 +0100 Subject: [PATCH] Misc bugfixes --- examples/bot.php | 2 +- src/danog/MadelineProto/MTProto.php | 30 +++++++++++-------- .../MadelineProto/MTProtoTools/Files.php | 20 ++++++------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/examples/bot.php b/examples/bot.php index b424aa1a..fb391461 100755 --- a/examples/bot.php +++ b/examples/bot.php @@ -85,7 +85,7 @@ $settings = [ ], ]; -$MadelineProto = new \danog\MadelineProto\API('bot.madeline', $settings); +$MadelineProto = new \danog\MadelineProto\API('/home/daniil/lmao.session', $settings); $MadelineProto->async(true); $MadelineProto->loop(function () use ($MadelineProto) { yield $MadelineProto->start(); diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index f82dc268..1398637b 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -918,15 +918,6 @@ class MTProto extends AsyncConstruct implements TLCallback if (Lang::$lang[$this->settings['app_info']['lang_code'] ?? 'en'] ?? false) { Lang::$current_lang = &Lang::$lang[$this->settings['app_info']['lang_code']]; } - // Cleanup old properties, init new stuffs - $this->cleanupProperties(); - - // Update TL callbacks - $callbacks = [$this, $this->referenceDatabase]; - if (!($this->authorization['user']['bot'] ?? false)) { - $callbacks []= $this->minDatabase; - } - $this->TL->updateCallbacks($callbacks); $this->settings['connection_settings']['all']['ipv6'] = Magic::$ipv6; if ($this->authorized === true) { @@ -940,19 +931,32 @@ class MTProto extends AsyncConstruct implements TLCallback } } - if ($this->event_handler && \class_exists($this->event_handler) && \is_subclass_of($this->event_handler, EventHandler::class)) { - $this->setEventHandler($this->event_handler); - } - if (($this->settings['tl_schema']['src']['botAPI'] ?? '') !== __DIR__.'/TL_botAPI.tl') { unset($this->v); } + if (!\file_exists($this->settings['tl_schema']['src']['telegram'])) { + unset($this->v); + } if (!isset($this->v) || $this->v !== self::V) { yield $this->upgradeMadelineProto(); $force = true; } + // Cleanup old properties, init new stuffs + $this->cleanupProperties(); + + // Update TL callbacks + $callbacks = [$this, $this->referenceDatabase]; + if (!($this->authorization['user']['bot'] ?? false)) { + $callbacks []= $this->minDatabase; + } + $this->TL->updateCallbacks($callbacks); + + if ($this->event_handler && \class_exists($this->event_handler) && \is_subclass_of($this->event_handler, EventHandler::class)) { + $this->setEventHandler($this->event_handler); + } + yield $this->connectToAllDcs(); foreach ($this->calls as $id => $controller) { if (!\is_object($controller)) { diff --git a/src/danog/MadelineProto/MTProtoTools/Files.php b/src/danog/MadelineProto/MTProtoTools/Files.php index 0262aa90..56af1c80 100644 --- a/src/danog/MadelineProto/MTProtoTools/Files.php +++ b/src/danog/MadelineProto/MTProtoTools/Files.php @@ -1087,17 +1087,17 @@ trait Files break; } catch (\danog\MadelineProto\RPCErrorException $e) { if (\strpos($e->rpc, 'FLOOD_WAIT_') === 0) { - if (isset($message_media['MessageMedia']) && !$this->authorization['user']['bot'] && $this->settings['download']['report_broken_media']) { - try { - yield $this->methodCallAsyncRead('messages.sendMedia', ['peer' => 'support', 'media' => $message_media['MessageMedia'], 'message' => "I can't download this file, could you please help?"], ['datacenter' => $this->datacenter->curdc]); - } catch (RPCErrorException $e) { - $this->logger->logger('An error occurred while reporting the broken file: '.$e->rpc, Logger::FATAL_ERROR); - } catch (Exception $e) { - $this->logger->logger('An error occurred while reporting the broken file: '.$e->getMessage(), Logger::FATAL_ERROR); - } - } - if ($x++ === 5) { + if (isset($message_media['MessageMedia']) && !$this->authorization['user']['bot'] && $this->settings['download']['report_broken_media']) { + try { + yield $this->methodCallAsyncRead('messages.sendMedia', ['peer' => 'support', 'media' => $message_media['MessageMedia'], 'message' => "I can't download this file, could you please help?"], ['datacenter' => $this->datacenter->curdc]); + } catch (RPCErrorException $e) { + $this->logger->logger('An error occurred while reporting the broken file: '.$e->rpc, Logger::FATAL_ERROR); + } catch (Exception $e) { + $this->logger->logger('An error occurred while reporting the broken file: '.$e->getMessage(), Logger::FATAL_ERROR); + } + } + throw new \danog\MadelineProto\Exception('The media server where this file is hosted is offline/overloaded, please try again later. Send the media to the telegram devs or to @danogentili to fix this.'); } yield Tools::sleep(1);