diff --git a/README.md b/README.md index c3b47e24b..2347a9ddc 100644 --- a/README.md +++ b/README.md @@ -677,6 +677,7 @@ Want to add your own open-source project to this list? [Click here!](https://doc * Report a profile photo of a dialog: account.reportProfilePhoto * Report a secret chat for spam: messages.reportEncryptedSpam * Report an error to the previously set peer: report + * Report: reportMemoryProfile * Reports some messages from a user in a supergroup as spam; requires administrator rights in the supergroup: channels.reportSpam * Represents a list of emoji categories, to be used when selecting custom emojis: messages.getEmojiGroups * Represents a list of emoji categories, to be used when selecting custom emojis to set as custom emoji status: messages.getEmojiStatusGroups diff --git a/docs b/docs index 2a68e556a..b19027991 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 2a68e556a694b0f87168afb4a2a6915d7962ca8c +Subproject commit b190279913a2383235d7af8b6947067fbb5b956d diff --git a/src/InternalDoc.php b/src/InternalDoc.php index 73451b444..d842185b8 100644 --- a/src/InternalDoc.php +++ b/src/InternalDoc.php @@ -1395,6 +1395,13 @@ abstract class InternalDoc { $this->wrapper->getAPI()->report($message, $parseMode); } + /** + * Report memory profile with memprof. + */ + public function reportMemoryProfile(): void + { + $this->wrapper->getAPI()->reportMemoryProfile(); + } /** * Request VoIP call. * @@ -1717,12 +1724,12 @@ abstract class InternalDoc /** * Upload file. * - * @param FileCallbackInterface|string|array $file File, URL or Telegram file to upload - * @param string $fileName File name - * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) - * @param boolean $encrypted Whether to encrypt file for secret chats + * @param FileCallbackInterface|string|array|resource $file File, URL or Telegram file to upload + * @param string $fileName File name + * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) + * @param boolean $encrypted Whether to encrypt file for secret chats */ - public function upload(\danog\MadelineProto\FileCallbackInterface|array|string $file, string $fileName = '', ?callable $cb = null, bool $encrypted = false) + public function upload($file, string $fileName = '', ?callable $cb = null, bool $encrypted = false) { return $this->wrapper->getAPI()->upload($file, $fileName, $cb, $encrypted); } diff --git a/src/Ipc/Runner/WebRunner.php b/src/Ipc/Runner/WebRunner.php index b920038c5..31158aa9a 100644 --- a/src/Ipc/Runner/WebRunner.php +++ b/src/Ipc/Runner/WebRunner.php @@ -88,6 +88,9 @@ final class WebRunner extends RunnerAbstract 'argv' => ['madeline-ipc', $session, $startupId], 'cwd' => Magic::getcwd(), ]; + if (\function_exists('memprof_enabled') && \memprof_enabled()) { + $params['MEMPROF_PROFILE'] = '1'; + } self::selfStart(self::$runPath.'?'.\http_build_query($params)); diff --git a/src/MTProto.php b/src/MTProto.php index d62487ab8..78eeb7dca 100644 --- a/src/MTProto.php +++ b/src/MTProto.php @@ -1695,6 +1695,37 @@ final class MTProto implements TLCallback, LoggerGetter $lock->release(); } } + /** + * Report memory profile with memprof. + */ + public function reportMemoryProfile(): void + { + if (!\extension_loaded('memprof')) { + throw Exception::extension('memprof'); + } + if (!\memprof_enabled()) { + throw new Exception("Memory profiling is not enabled in the database settings, set the MEMPROF_PROFILE=1 environment variable or GET parameter to enable it."); + } + + $current = "Current memory usage: ".\round(\memory_get_usage()/1024/1024, 1) . " MB"; + $file = \fopen('php://memory', 'r+'); + \memprof_dump_pprof($file); + \fseek($file, 0); + $file = [ + '_' => 'inputMediaUploadedDocument', + 'file' => $file, + 'attributes' => [ + ['_' => 'documentAttributeFilename', 'file_name' => 'report.pprof'], + ], + ]; + foreach ($this->reportDest as $id) { + try { + $this->methodCallAsyncRead('messages.sendMedia', ['peer' => $id, 'message' => $current, 'media' => $file]); + } catch (Throwable $e) { + $this->logger("While reporting memory profile to $id: $e", Logger::FATAL_ERROR); + } + } + } /** * Get full list of MTProto and API methods. */ diff --git a/src/MTProtoTools/FilesLogic.php b/src/MTProtoTools/FilesLogic.php index 13bb8c87f..408ac2a97 100644 --- a/src/MTProtoTools/FilesLogic.php +++ b/src/MTProtoTools/FilesLogic.php @@ -229,12 +229,12 @@ trait FilesLogic /** * Upload file. * - * @param FileCallbackInterface|string|array $file File, URL or Telegram file to upload - * @param string $fileName File name - * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) - * @param boolean $encrypted Whether to encrypt file for secret chats + * @param FileCallbackInterface|string|array|resource $file File, URL or Telegram file to upload + * @param string $fileName File name + * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) + * @param boolean $encrypted Whether to encrypt file for secret chats */ - public function upload(FileCallbackInterface|string|array $file, string $fileName = '', ?callable $cb = null, bool $encrypted = false) + public function upload($file, string $fileName = '', ?callable $cb = null, bool $encrypted = false) { if (\is_object($file) && $file instanceof FileCallbackInterface) { $cb = $file; diff --git a/src/MTProtoTools/UpdateHandler.php b/src/MTProtoTools/UpdateHandler.php index d7962bbc7..17a7e4bf3 100644 --- a/src/MTProtoTools/UpdateHandler.php +++ b/src/MTProtoTools/UpdateHandler.php @@ -215,7 +215,9 @@ trait UpdateHandler if (!$this->updates) { try { $this->update_deferred = new DeferredFuture(); - $this->update_deferred->getFuture()->await(new TimeoutCancellation($timeout)); + $this->update_deferred->getFuture()->await( + $timeout === INF ? null : new TimeoutCancellation($timeout) + ); } catch (CancelledException $e) { if (!$e->getPrevious() instanceof TimeoutException) { throw $e; diff --git a/src/Namespace/Messages.php b/src/Namespace/Messages.php index 41400dd8f..9917b4c5a 100644 --- a/src/Namespace/Messages.php +++ b/src/Namespace/Messages.php @@ -853,7 +853,7 @@ interface Messages * @param bool $update_stickersets_order Whether to move used stickersets to top, [see here for more info on this flag ยป](https://core.telegram.org/api/stickers#recent-stickersets) * @param int $reply_to_msg_id The message to reply to * @param int $top_msg_id This field must contain the topic ID **only** when replying to messages in [forum topics](https://core.telegram.org/api/forum#forum-topics) different from the "General" topic (i.e. `reply_to_msg_id` is set and `reply_to_msg_id != topicID` and `topicID != 1`).
If the replied-to message is deleted before the method finishes execution, the value in this field will be used to send the message to the correct topic, instead of the "General" topic. - * @param list}>|array $multi_media Array of The medias to send: note that they must be separately uploaded using [messages.uploadMedia](https://docs.madelineproto.xyz/API_docs/methods/messages.uploadMedia.html) first, using raw `inputMediaUploaded*` constructors is not supported. @see https://docs.madelineproto.xyz/API_docs/types/InputSingleMedia.html + * @param list}>|array $multi_media Array of The medias to send @see https://docs.madelineproto.xyz/API_docs/types/InputSingleMedia.html * @param int $schedule_date Scheduled message date for scheduled messages * @param array|int|string $send_as Send this message as the specified peer @see https://docs.madelineproto.xyz/API_docs/types/InputPeer.html * @return array @see https://docs.madelineproto.xyz/API_docs/types/Updates.html diff --git a/tools/build_docs/merge.php b/tools/build_docs/merge.php index 380c98feb..6a7843a0e 100644 --- a/tools/build_docs/merge.php +++ b/tools/build_docs/merge.php @@ -12,6 +12,9 @@ function mergeExtracted(): void return; } foreach (json_decode(file_get_contents('extracted.json'), true) as $key => $value) { + if ($key === 'method_messages.sendMultiMedia_param_multi_media_type_Vector') { + $value = 'The medias to send'; + } $key = preg_replace(['|flags\.\d+[?]|', '/Vector[<].*/'], ['', 'Vector t'], $key); $key = str_replace('param_hash_type_int', 'param_hash_type_Vector t', $key); Lang::$lang['en'][$key] = $value;