From 1b349d93da600c31c4e129122beca2ee19f0410a Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 20 Mar 2018 14:47:34 +0000 Subject: [PATCH] Update docs --- README.md | 12 ++++++++ build_docs_index.php | 28 ++++++++++++------- docs/docs/FLOOD_WAIT.md | 12 ++++++++ docs/docs/REQUIREMENTS.md | 2 +- docs/index.md | 12 +++++++- .../MTProtoTools/AuthKeyHandler.php | 4 +++ 6 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 docs/docs/FLOOD_WAIT.md diff --git a/README.md b/README.md index 8fd19a9c..74f98069 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,13 @@ $MadelineProto->start(); $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => "Hi!\nThanks for creating MadelineProto! <3"]); $MadelineProto->channels->joinChannel(['channel' => '@MadelineProto']); + +try { + $MadelineProto->messages->importChatInvite(['hash' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg']); +} catch (\danog\MadelineProto\RPCErrorException $e) { +} + +$MadelineProto->messages->sendMessage(['peer' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg', 'message' => 'Testing MadelineProto!']); ``` Run this code in a browser or in a console. @@ -66,6 +73,7 @@ Tip: if you receive an error (or nothing), [send us](https://t.me/pwrtelegramgro * [List of exception types](https://docs.madelineproto.xyz/docs/EXCEPTIONS.html#list-of-exception-types) * [Pretty TL trace](https://docs.madelineproto.xyz/docs/EXCEPTIONS.html#pretty-tl-trace) * [Getting the TL trace](https://docs.madelineproto.xyz/docs/EXCEPTIONS.html#getting-the-tl-trace) +* [Avoiding FLOOD_WAITs](https://docs.madelineproto.xyz/docs/FLOOD_WAIT.html) * [Logging](https://docs.madelineproto.xyz/docs/LOGGING.html) * [Using methods](https://docs.madelineproto.xyz/docs/USING_METHODS.html) * [Peers](https://docs.madelineproto.xyz/docs/USING_METHODS.html#peers) @@ -116,6 +124,10 @@ Tip: if you receive an error (or nothing), [send us](https://t.me/pwrtelegramgro * [Sending secret messages](https://docs.madelineproto.xyz/docs/SECRET_CHATS.html#sending-secret-messages) * [Lua binding](https://docs.madelineproto.xyz/docs/LUA.html) * [Using a proxy](https://docs.madelineproto.xyz/docs/PROXY.html) +* [Contributing](https://docs.madelineproto.xyz/docs/CONTRIBUTING.html) + * [Translation](https://docs.madelineproto.xyz/docs/CONTRIBUTING.html#translation) + * [Contribution guide](https://docs.madelineproto.xyz/docs/CONTRIBUTING.html#contribution-guide) + * [Credits](https://docs.madelineproto.xyz/docs/CONTRIBUTING.html#credits) ## Very complex and complete examples diff --git a/build_docs_index.php b/build_docs_index.php index bc555305..f3f0486a 100644 --- a/build_docs_index.php +++ b/build_docs_index.php @@ -21,32 +21,40 @@ foreach ($files as $file) { $orderedfiles[7] = $file; } else if ($base === 'EXCEPTIONS') { $orderedfiles[8] = $file; - } else if ($base === 'LOGGING') { + } else if ($base === 'FLOOD_WAIT') { $orderedfiles[9] = $file; - } else if ($base === 'USING_METHODS') { + } else if ($base === 'LOGGING') { $orderedfiles[10] = $file; - } else if ($base === 'FILES') { + } else if ($base === 'USING_METHODS') { $orderedfiles[11] = $file; - } else if ($base === 'CHAT_INFO') { + } else if ($base === 'FILES') { $orderedfiles[12] = $file; - } else if ($base === 'DIALOGS') { + } else if ($base === 'CHAT_INFO') { $orderedfiles[13] = $file; - } else if ($base === 'INLINE_BUTTONS') { + } else if ($base === 'DIALOGS') { $orderedfiles[14] = $file; - } else if ($base === 'CALLS') { + } else if ($base === 'INLINE_BUTTONS') { $orderedfiles[15] = $file; - } else if ($base === 'SECRET_CHATS') { + } else if ($base === 'CALLS') { $orderedfiles[16] = $file; - } else if ($base === 'LUA') { + } else if ($base === 'SECRET_CHATS') { $orderedfiles[17] = $file; - } else if ($base === 'PROXY') { + } else if ($base === 'LUA') { $orderedfiles[18] = $file; + } else if ($base === 'PROXY') { + $orderedfiles[19] = $file; + } else if ($base === 'CONTRIBUTING') { + $orderedfiles[20] = $file; } else { $orderedfiles[] = $file; } + ksort($orderedfiles); } ksort($orderedfiles); foreach ($orderedfiles as $filename) { + $lines = explode("\n", file_get_contents($filename)); + if (strpos(end($lines), "Next")) unset($lines[count($lines)-1]); + preg_match('|^# (.*)|', $file = file_get_contents($filename), $matches); $title = $matches[1]; preg_match_all('|( *)\* \[(.*)\]\(#(.*)\)|', $file, $matches); diff --git a/docs/docs/FLOOD_WAIT.md b/docs/docs/FLOOD_WAIT.md new file mode 100644 index 00000000..805a575b --- /dev/null +++ b/docs/docs/FLOOD_WAIT.md @@ -0,0 +1,12 @@ +# Avoiding FLOOD_WAITs + +If you make too many requests to telegram, you might get FLOOD_WAITed for a while. +To avoid these flood waits, you must calculate the flood wait rate. + +Calculate it by making N of method calls until you get a FLOOD_WAIT_X + +``` +floodwaitrate = time it took you to make the method calls + X +``` + +Use sleep to execute max N calls in `floodwaitrate` seconds, this way you won't get flood waited! diff --git a/docs/docs/REQUIREMENTS.md b/docs/docs/REQUIREMENTS.md index 39ae7883..1055d53b 100644 --- a/docs/docs/REQUIREMENTS.md +++ b/docs/docs/REQUIREMENTS.md @@ -1,6 +1,6 @@ # Requirements -MadelineProto requires the `xml`, `gmp` extensions to function properly. +MadelineProto requires the `xml`, `gmp`, `curl` extensions to function properly. To install MadelineProto dependencies on `Ubuntu`, `Debian`, `Devuan`, or any other `Debian-based` distro, run the following command in your command line: diff --git a/docs/index.md b/docs/index.md index ab0ff7ba..a300e3b5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -33,9 +33,19 @@ $MadelineProto->start(); $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => "Hi!\nThanks for creating MadelineProto! <3"]); $MadelineProto->channels->joinChannel(['channel' => '@MadelineProto']); + +try { + $MadelineProto->messages->importChatInvite(['hash' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg']); +} catch (\danog\MadelineProto\RPCErrorException $e) { +} + +$MadelineProto->messages->sendMessage(['peer' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg', 'message' => 'Testing MadelineProto!']); ``` -Run this code in a browser or in a console. +Run this code in a browser or in a console. + + +Tip: if you receive an error (or nothing), [send us](https://t.me/pwrtelegramgroup) the error message and the `Madeline.log` file that was created in the same directory (if running from a browser). ## Documentation diff --git a/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php b/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php index 0131cb01..f26025ba 100644 --- a/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php @@ -122,6 +122,10 @@ trait AuthKeyHandler if (!$pq->equals($p->multiply($q))) { \danog\MadelineProto\Logger::log('Automatic factorization failed, trying wolfram module', \danog\MadelineProto\Logger::ERROR); + if (!extension_loaded('xml')) { + throw new Exception(['extension', 'curl']); + } + $p = new \phpseclib\Math\BigInteger(\danog\PrimeModule::wolfram_single($pq->__toString())); if (!$p->equals($this->zero)) { $q = $pq->divide($p)[0];