Readable errors

This commit is contained in:
Daniil Gentili 2017-09-24 22:24:04 +00:00
parent 2e3551e218
commit 860ebcce8b
6 changed files with 13 additions and 9 deletions

View File

@ -111,9 +111,9 @@ $users = [];
//'audio_bitrate_step_incr' => 2000, //'audio_bitrate_step_incr' => 2000,
]; ];
$call->parseConfig(); $call->parseConfig();
$call->playOnHold($songs);
$calls[$call->getOtherID()] = $call; $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']]; $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) { } catch (\danog\MadelineProto\RPCErrorException $e) {
echo $e; echo $e;
@ -125,7 +125,7 @@ echo $e;
foreach ($calls as $key => $call) { foreach ($calls as $key => $call) {
if ($call->getCallState() === \danog\MadelineProto\VoIP::CALL_STATE_ENDED) { if ($call->getCallState() === \danog\MadelineProto\VoIP::CALL_STATE_ENDED) {
unset($calls[$key]); 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; $times[$call->getOtherID()][0] += 10;
try { try {
$MadelineProto->messages->editMessage(['id' => $times[$call->getOtherID()][1], 'peer' => $call->getOtherID(), 'message' => 'Total running calls: '.count($calls).PHP_EOL.PHP_EOL.$call->getDebugString()]); $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, //'audio_bitrate_step_incr' => 2000,
]; ];
$call->parseConfig(); $call->parseConfig();
$call->playOnHold($songs);
$calls[$call->getOtherID()] = $call; $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']]; $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) { if (isset($update['update']['message']['message']) && strpos($update['update']['message']['message'], '/program') === 0) {
$time = strtotime(str_replace('/program ', '', $update['update']['message']['message'])); $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) { } catch (\danog\MadelineProto\RPCErrorException $e) {
try { 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]); $MadelineProto->messages->sendMessage(['peer' => $update['update']['message']['from_id'], 'message' => (string) $e]);
} catch (\danog\MadelineProto\RPCErrorException $e) { } catch (\danog\MadelineProto\RPCErrorException $e) {
} }

View File

@ -18,7 +18,7 @@ class Exception extends \Exception
public function __toString() 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) public function __construct($message = null, $code = 0, Exception $previous = null, $file = null, $line = null)

View File

@ -46,7 +46,7 @@ class MTProto
/* /*
const V = 71; const V = 71;
*/ */
const V = 72; const V = 73;
const NOT_LOGGED_IN = 0; const NOT_LOGGED_IN = 0;
const WAITING_CODE = 1; const WAITING_CODE = 1;

View File

@ -18,7 +18,7 @@ class Exception extends \Exception
public function __toString() 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 = '') public function __construct($message, $file = '')

View File

@ -27,7 +27,7 @@ trait PrettyException
foreach (array_reverse($this->getTrace()) as $k => $frame) { foreach (array_reverse($this->getTrace()) as $k => $frame) {
if (isset($frame['function']) && in_array($frame['function'], ['serialize_params', 'serialize_object'])) { if (isset($frame['function']) && in_array($frame['function'], ['serialize_params', 'serialize_object'])) {
if ($frame['args'][2] !== '') { 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; $tl = true;
} }
} else { } else {

View File

@ -92,7 +92,6 @@ echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL; echo 'Wrote '.\
$m = new \danog\MadelineProto\API($settings); $m = new \danog\MadelineProto\API($settings);
$m->import_authorization($MadelineProto->export_authorization()); $m->import_authorization($MadelineProto->export_authorization());
*/ */
die;
if (stripos(readline('Do you want to make a call? (y/n): '), 'y') !== false) { 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'); $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) { while ($controller->getCallState() < \danog\MadelineProto\VoIP::CALL_STATE_READY) {