Readable errors

This commit is contained in:
Daniil Gentili 2017-09-24 22:26:06 +00:00
parent 860ebcce8b
commit 9267d711f3
7 changed files with 52 additions and 55 deletions

View File

@ -1,4 +1,3 @@
MTPROTO_NUMBER=+39394838932
MTPROTO_SETTINGS={"app_info":{"api_id":6,"api_hash":"eb06d4abfb49dc3eeb1aeb98ae0f581e"}}
TEST_USERNAME=@danogentili
TEST_DESTINATION_GROUPS=["@pwrtelegramgroup","@pwrtelegramgroupita"]

View File

@ -41,14 +41,7 @@ if ($MadelineProto === false) {
echo 'Loading MadelineProto...'.PHP_EOL;
$MadelineProto = new \danog\MadelineProto\API($settings);
if (getenv('TRAVIS_COMMIT') == '') {
$checkedPhone = $MadelineProto->auth->checkPhone(// auth.checkPhone becomes auth->checkPhone
[
'phone_number' => getenv('MTPROTO_NUMBER'),
]
);
\danog\MadelineProto\Logger::log([$checkedPhone], \danog\MadelineProto\Logger::NOTICE);
$sentCode = $MadelineProto->phone_login(getenv('MTPROTO_NUMBER'));
$sentCode = $MadelineProto->phone_login(readline('Enter your phone number: '));
\danog\MadelineProto\Logger::log([$sentCode], \danog\MadelineProto\Logger::NOTICE);
echo 'Enter the code you received: ';
$code = fgets(STDIN, (isset($sentCode['type']['length']) ? $sentCode['type']['length'] : 5) + 1);
@ -80,7 +73,9 @@ if ($MadelineProto === false) {
\danog\MadelineProto\Logger::log(['hey'], \danog\MadelineProto\Logger::FATAL_ERROR);
$message = (getenv('TRAVIS_COMMIT') == '') ? 'I iz works always (io laborare sembre) (yo lavorar siempre) (mi labori ĉiam) (я всегда работать) (Ik werkuh altijd) (Ngimbonga ngaso sonke isikhathi ukusebenza)' : ('Travis ci tests in progress: commit '.getenv('TRAVIS_COMMIT').', job '.getenv('TRAVIS_JOB_NUMBER').', PHP version: '.getenv('TRAVIS_PHP_VERSION'));
if (!isset($MadelineProto->programmed_call)) $MadelineProto->programmed_call = [];
if (!isset($MadelineProto->programmed_call)) {
$MadelineProto->programmed_call = [];
}
echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL; echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL;
/*
@ -98,25 +93,24 @@ $users = [];
if ($time < time()) {
if (!isset($calls[$user])) {
try {
include 'songs.php';
$call = $MadelineProto->request_call($user);
$call->configuration['enable_NS'] = false;
$call->configuration['enable_AGC'] = false;
$call->configuration['enable_AEC'] = false;
$call->configuration['shared_config'] = [
include 'songs.php';
$call = $MadelineProto->request_call($user);
$call->configuration['enable_NS'] = false;
$call->configuration['enable_AGC'] = false;
$call->configuration['enable_AEC'] = false;
$call->configuration['shared_config'] = [
'audio_init_bitrate' => 70 * 1000,
'audio_max_bitrate' => 100 * 1000,
'audio_min_bitrate' => 15 * 1000,
//'audio_bitrate_step_decr' => 0,
//'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->parseConfig();
$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;
echo $e;
}
}
unset($MadelineProto->programmed_call[$key]);
@ -127,10 +121,11 @@ echo $e;
unset($calls[$key]);
} 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()]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
echo $e;
echo $e;
}
}
}
@ -145,7 +140,7 @@ echo $e;
}
try {
if (!isset($users[$update['update']['message']['from_id']]) ||isset($update['update']['message']['message']) && $update['update']['message']['message'] === '/start') {
if (!isset($users[$update['update']['message']['from_id']]) || isset($update['update']['message']['message']) && $update['update']['message']['message'] === '/start') {
$users[$update['update']['message']['from_id']] = true;
$update['update']['message']['message'] = '/call';
$MadelineProto->messages->sendMessage(['peer' => $update['update']['message']['from_id'], 'message' => "Hi, I'm @magnaluna the webradio.
@ -183,15 +178,14 @@ Propic art by @magnaluna on deviantart.", 'parse_mode' => 'Markdown']);
$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']];
}
if (isset($update['update']['message']['message']) && strpos($update['update']['message']['message'], '/program') === 0) {
$time = strtotime(str_replace('/program ', '', $update['update']['message']['message']));
if ($time === false) {
$MadelineProto->messages->sendMessage(['peer' => $update['update']['message']['from_id'], 'message' => "Invalid time provided"]);
$MadelineProto->messages->sendMessage(['peer' => $update['update']['message']['from_id'], 'message' => 'Invalid time provided']);
} else {
$MadelineProto->programmed_call[]= [$update['update']['message']['from_id'], $time];
$MadelineProto->messages->sendMessage(['peer' => $update['update']['message']['from_id'], 'message' => "OK"]);
$MadelineProto->programmed_call[] = [$update['update']['message']['from_id'], $time];
$MadelineProto->messages->sendMessage(['peer' => $update['update']['message']['from_id'], 'message' => 'OK']);
}
}
} catch (\danog\MadelineProto\RPCErrorException $e) {
@ -228,9 +222,11 @@ Propic art by @magnaluna on deviantart.", 'parse_mode' => 'Markdown']);
echo 'DID NOT ACCEPT A CALL';
}
$calls[$update['update']['phone_call']->getOtherID()] = $update['update']['phone_call'];
try {
$times[$update['update']['phone_call']->getOtherID()] = [time(), $MadelineProto->messages->sendMessage(['peer' => $update['update']['phone_call']->getOtherID(), 'message' => 'Total running calls: '.count($calls).PHP_EOL.PHP_EOL.$update['update']['phone_call']->getDebugString()])['id']];
} catch (\danog\MadelineProto\RPCErrorException $e) { ; }
} catch (\danog\MadelineProto\RPCErrorException $e) {
}
$update['update']['phone_call']->playOnHold($songs);
}

View File

@ -37,14 +37,7 @@ if ($MadelineProto === false) {
echo 'Loading MadelineProto...'.PHP_EOL;
$MadelineProto = new \danog\MadelineProto\API($settings);
if (getenv('TRAVIS_COMMIT') == '') {
$checkedPhone = $MadelineProto->auth->checkPhone(// auth.checkPhone becomes auth->checkPhone
[
'phone_number' => getenv('MTPROTO_NUMBER'),
]
);
\danog\MadelineProto\Logger::log([$checkedPhone], \danog\MadelineProto\Logger::NOTICE);
$sentCode = $MadelineProto->phone_login(getenv('MTPROTO_NUMBER'));
$sentCode = $MadelineProto->phone_login(readline('Enter your phone number: '));
\danog\MadelineProto\Logger::log([$sentCode], \danog\MadelineProto\Logger::NOTICE);
echo 'Enter the code you received: ';
$code = fgets(STDIN, (isset($sentCode['type']['length']) ? $sentCode['type']['length'] : 5) + 1);

View File

@ -42,7 +42,7 @@ class Lua
$this->Lua->registerCallback('tdcli_function', [$this, 'tdcli_function']);
$this->Lua->registerCallback('madeline_function', [$this, 'madeline_function']);
foreach (get_class_methods($this->MadelineProto->API) as $method) {
$this->Lua->registerCallback($method, [$this->MadelineProto->API, $method]);
$this->Lua->registerCallback($method, [$this->MadelineProto, $method]);
}
$methods = [];
foreach ($this->MadelineProto->get_methods_namespaced() as $pair) {
@ -159,7 +159,7 @@ class Lua
public static function convert_objects(&$data)
{
array_walk_recursive($data, function (&$value, $key) {
if (is_object($value)) {
if (is_object($value) && !($value instanceof \phpseclib\Math\BigInteger)) {
$newval = [];
foreach (get_class_methods($value) as $name) {
$newval[$name] = [$value, $name];

View File

@ -362,6 +362,7 @@ class MTProto
if ($this->authorized === self::LOGGED_IN) {
$this->get_self();
$this->get_cdn_config($this->datacenter->curdc);
$this->setup_logger();
}
if ($this->authorized === self::LOGGED_IN && !$this->authorization['user']['bot']) {
$this->get_dialogs($force);

View File

@ -21,6 +21,9 @@ trait PeerHandler
{
foreach ($users as $key => $user) {
if (!isset($user['access_hash'])) {
if (isset($user['username']) && !isset($this->chats[$user['id']])) {
$this->get_pwr_chat($user['username'], false, true);
}
continue;
}
switch ($user['_']) {
@ -71,10 +74,13 @@ trait PeerHandler
break;
case 'channel':
case 'channelForbidden':
$bot_api_id = $this->to_supergroup($chat['id']);
if (!isset($chat['access_hash'])) {
if (isset($chat['username']) && !isset($this->chats[$bot_api_id])) {
$this->get_pwr_chat($chat['username'], true, true);
}
continue;
}
$bot_api_id = $this->to_supergroup($chat['id']);
if (!isset($this->chats[$bot_api_id]) || $this->chats[$bot_api_id] !== $chat) {
$this->chats[$bot_api_id] = $chat;
@ -130,7 +136,7 @@ trait PeerHandler
if (isset($fwd['user_id']) && !$this->peer_isset($fwd['user_id'])) {
return false;
}
if (isset($fwd['channel_id']) && !$this->peer_isset('channel#'.$fwd['channel_id'])) {
if (isset($fwd['channel_id']) && !$this->peer_isset($this->to_supergroup($fwd['channel_id']))) {
return false;
}
} catch (\danog\MadelineProto\Exception $e) {
@ -161,19 +167,16 @@ trait PeerHandler
break;
case 'chat':
$id = -$id['id'];
break;
case 'chatFull':
$id = -$id['id'];
break;
case 'inputPeerChat':
case 'inputPeerChat':
case 'peerChat':
$id = -$id['chat_id'];
break;
case 'channel':
$id = $this->to_supergroup($id['id']);
break;
case 'channelFull':
$id = $this->to_supergroup($id['id']);
break;
@ -204,15 +207,12 @@ trait PeerHandler
if (is_string($id)) {
$id = \danog\MadelineProto\Logger::$bigint ? ((float) $id) : ((int) $id);
}
if (!isset($this->chats[$id]) && $id < 0 && !preg_match('/^-100/', $id)) {
$this->method_call('messages.getFullChat', ['chat_id' => -$id], ['datacenter' => $this->datacenter->curdc]);
}
if (isset($this->chats[$id])) {
return $this->gen_all($this->chats[$id]);
}
if ($id < 0 && !preg_match('/^-100/', $id)) {
$this->method_call('messages.getFullChat', ['chat_id' => -$id], ['datacenter' => $this->datacenter->curdc]);
if (isset($this->chats[$id])) {
return $this->gen_all($this->chats[$id]);
}
}
if (!isset($this->settings['pwr']['requests']) || $this->settings['pwr']['requests'] === true) {
$dbres = json_decode(@file_get_contents('https://id.pwrtelegram.xyz/db/getusername?id='.$id, false, stream_context_create(['http'=> [
'timeout' => 2,
@ -225,9 +225,9 @@ trait PeerHandler
throw new \danog\MadelineProto\Exception('This peer is not present in the internal peer database');
}
$id = str_replace('@', '', $id);
$id = strtolower(str_replace('@', '', $id));
foreach ($this->chats as $chat) {
if (isset($chat['username']) && strtolower($chat['username']) === strtolower($id)) {
if (isset($chat['username']) && strtolower($chat['username']) === $id) {
return $this->gen_all($chat);
}
}

View File

@ -79,7 +79,15 @@ trait UpdateHandler
});
$time = microtime(true);
$this->get_updates_difference();
try {
$this->get_updates_difference();
} catch (\danog\MadelineProto\RPCErrorException $e) {
if ($e->rpc !== 'RPC_CALL_FAIL') {
throw $e;
}
}
$default_params = ['offset' => 0, 'limit' => null, 'timeout' => 0];
foreach ($default_params as $key => $default) {
if (!isset($params[$key])) {