From 860ebcce8b14d263f5f7a291d7caacbab3315c27 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 24 Sep 2017 22:24:04 +0000 Subject: [PATCH] Readable errors --- magna.php | 13 +++++++++---- src/danog/MadelineProto/Exception.php | 2 +- src/danog/MadelineProto/MTProto.php | 2 +- src/danog/MadelineProto/TL/Exception.php | 2 +- src/danog/MadelineProto/TL/PrettyException.php | 2 +- tests/testing.php | 1 - 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/magna.php b/magna.php index 1458f85f..6a71536d 100755 --- a/magna.php +++ b/magna.php @@ -111,9 +111,9 @@ $users = []; //'audio_bitrate_step_incr' => 2000, ]; $call->parseConfig(); + $call->playOnHold($songs); $calls[$call->getOtherID()] = $call; $times[$call->getOtherID()] = [time(), $MadelineProto->messages->sendMessage(['peer' => $call->getOtherID(), 'message' => 'Total running calls: '.count($calls).PHP_EOL.PHP_EOL.$call->getDebugString()])['id']]; - $call->playOnHold($songs); } catch (\danog\MadelineProto\RPCErrorException $e) { echo $e; @@ -125,7 +125,7 @@ echo $e; foreach ($calls as $key => $call) { if ($call->getCallState() === \danog\MadelineProto\VoIP::CALL_STATE_ENDED) { unset($calls[$key]); - } else if ($times[$call->getOtherID()][0] < time()) { + } else if (isset($times[$call->getOtherID()])&&$times[$call->getOtherID()][0] < time()) { $times[$call->getOtherID()][0] += 10; try { $MadelineProto->messages->editMessage(['id' => $times[$call->getOtherID()][1], 'peer' => $call->getOtherID(), 'message' => 'Total running calls: '.count($calls).PHP_EOL.PHP_EOL.$call->getDebugString()]); @@ -179,11 +179,11 @@ Propic art by @magnaluna on deviantart.", 'parse_mode' => 'Markdown']); //'audio_bitrate_step_incr' => 2000, ]; $call->parseConfig(); + $call->playOnHold($songs); $calls[$call->getOtherID()] = $call; $times[$call->getOtherID()] = [time(), $MadelineProto->messages->sendMessage(['peer' => $call->getOtherID(), 'message' => 'Total running calls: '.count($calls).PHP_EOL.PHP_EOL.$call->getDebugString()])['id']]; - $call->playOnHold($songs); } if (isset($update['update']['message']['message']) && strpos($update['update']['message']['message'], '/program') === 0) { $time = strtotime(str_replace('/program ', '', $update['update']['message']['message'])); @@ -196,7 +196,12 @@ Propic art by @magnaluna on deviantart.", 'parse_mode' => 'Markdown']); } } catch (\danog\MadelineProto\RPCErrorException $e) { try { - if (strpos($e->rpc, 'FLOOD_WAIT_') === 0) $MadelineProto->programmed_call[]= [$update['update']['message']['from_id'], time()+1+str_replace('FLOOD_WAIT_', '', $e->rpc)]; + if ($e->rpc === 'USER_PRIVACY_RESTRICTED') { $e = 'Please disable call privacy settings to make me call you'; + } else if (strpos($e->rpc, 'FLOOD_WAIT_') === 0) { + $t = str_replace('FLOOD_WAIT_', '', $e->rpc); + $MadelineProto->programmed_call[]= [$update['update']['message']['from_id'], time()+1+$t]; + $e = "Too many people used the /call function. I'll call you back in $t seconds.\nYou can also call me right now."; + } $MadelineProto->messages->sendMessage(['peer' => $update['update']['message']['from_id'], 'message' => (string) $e]); } catch (\danog\MadelineProto\RPCErrorException $e) { } diff --git a/src/danog/MadelineProto/Exception.php b/src/danog/MadelineProto/Exception.php index dc29ce20..4b7f8f08 100644 --- a/src/danog/MadelineProto/Exception.php +++ b/src/danog/MadelineProto/Exception.php @@ -18,7 +18,7 @@ class Exception extends \Exception public function __toString() { - return $this->file === 'MadelineProto' ? $this->message : '\danog\MadelineProto\Exception'.($this->message !== '' ? ': ' : '').$this->message.' in '.$this->file.':'.$this->line.PHP_EOL.'TL Trace:'.PHP_EOL.$this->getTLTrace(); + return $this->file === 'MadelineProto' ? $this->message : '\danog\MadelineProto\Exception'.($this->message !== '' ? ': ' : '').$this->message.' in '.$this->file.':'.$this->line.PHP_EOL.'TL Trace (YOU ABSOLUTELY MUST READ THE TEXT BELOW):'.PHP_EOL.$this->getTLTrace(); } public function __construct($message = null, $code = 0, Exception $previous = null, $file = null, $line = null) diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index c12d4e64..5def5505 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -46,7 +46,7 @@ class MTProto /* const V = 71; */ - const V = 72; + const V = 73; const NOT_LOGGED_IN = 0; const WAITING_CODE = 1; diff --git a/src/danog/MadelineProto/TL/Exception.php b/src/danog/MadelineProto/TL/Exception.php index 82e96c1c..dfad843c 100644 --- a/src/danog/MadelineProto/TL/Exception.php +++ b/src/danog/MadelineProto/TL/Exception.php @@ -18,7 +18,7 @@ class Exception extends \Exception public function __toString() { - return get_class($this).($this->message !== '' ? ': ' : '').$this->message.PHP_EOL.'TL Trace:'.PHP_EOL.PHP_EOL.$this->getTLTrace().PHP_EOL; + return get_class($this).($this->message !== '' ? ': ' : '').$this->message.PHP_EOL.'TL Trace (YOU ABSOLUTELY MUST READ THE TEXT BELOW):'.PHP_EOL.PHP_EOL.$this->getTLTrace().PHP_EOL; } public function __construct($message, $file = '') diff --git a/src/danog/MadelineProto/TL/PrettyException.php b/src/danog/MadelineProto/TL/PrettyException.php index 95e2a278..8a1b278c 100644 --- a/src/danog/MadelineProto/TL/PrettyException.php +++ b/src/danog/MadelineProto/TL/PrettyException.php @@ -27,7 +27,7 @@ trait PrettyException foreach (array_reverse($this->getTrace()) as $k => $frame) { if (isset($frame['function']) && in_array($frame['function'], ['serialize_params', 'serialize_object'])) { if ($frame['args'][2] !== '') { - $this->tl_trace .= $tl ? "['".$frame['args'][2]."']" : "While serializing: \t".$frame['args'][2]; + $this->tl_trace .= $tl ? "['".$frame['args'][2]."']" : "While serializing: \t".$frame['args'][2].PHP_EOL; $tl = true; } } else { diff --git a/tests/testing.php b/tests/testing.php index e2f0f7c8..a7f61aed 100755 --- a/tests/testing.php +++ b/tests/testing.php @@ -92,7 +92,6 @@ echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL; echo 'Wrote '.\ $m = new \danog\MadelineProto\API($settings); $m->import_authorization($MadelineProto->export_authorization()); */ -die; if (stripos(readline('Do you want to make a call? (y/n): '), 'y') !== false) { $controller = $MadelineProto->request_call(getenv('TEST_SECRET_CHAT'))->play('input.raw')->then('input.raw')->playOnHold(['input.raw'])->setOutputFile('output.raw'); while ($controller->getCallState() < \danog\MadelineProto\VoIP::CALL_STATE_READY) {