mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-27 01:14:39 +01:00
Report errors right away
This commit is contained in:
parent
0ae923c29a
commit
396cd6fa83
2
docs
2
docs
@ -1 +1 @@
|
||||
Subproject commit bc9a62cd766e4e44f5d27a0a3857e7785eaabb7a
|
||||
Subproject commit e853188c1d86ef9f41b183eed61c6cce56575cd5
|
@ -394,10 +394,6 @@ class MTProto extends AsyncConstruct implements TLCallback
|
||||
* Autoserialization loop.
|
||||
*/
|
||||
private ?PeriodicLoopInternal $serializeLoop = null;
|
||||
/**
|
||||
* RPC reporting loop.
|
||||
*/
|
||||
private ?PeriodicLoopInternal $rpcLoop = null;
|
||||
/**
|
||||
* SEQ update loop.
|
||||
*/
|
||||
@ -927,9 +923,6 @@ class MTProto extends AsyncConstruct implements TLCallback
|
||||
if (!$this->configLoop) {
|
||||
$this->configLoop = new PeriodicLoopInternal($this, [$this, 'getConfig'], 'config', 24 * 3600 * 1000);
|
||||
}
|
||||
if (!$this->rpcLoop) {
|
||||
$this->rpcLoop = new PeriodicLoopInternal($this, [$this, 'rpcReport'], 'config', 60 * 1000);
|
||||
}
|
||||
if (!$this->ipcServer) {
|
||||
try {
|
||||
$this->ipcServer = new Server($this);
|
||||
@ -944,7 +937,6 @@ class MTProto extends AsyncConstruct implements TLCallback
|
||||
$this->phoneConfigLoop->start();
|
||||
$this->configLoop->start();
|
||||
$this->checkTosLoop->start();
|
||||
$this->rpcLoop->start();
|
||||
try {
|
||||
$this->ipcServer->start();
|
||||
} catch (\Throwable $e) {
|
||||
@ -981,38 +973,11 @@ class MTProto extends AsyncConstruct implements TLCallback
|
||||
$this->checkTosLoop->signal(true);
|
||||
$this->checkTosLoop = null;
|
||||
}
|
||||
if ($this->rpcLoop) {
|
||||
$this->rpcLoop->signal(true);
|
||||
$this->rpcLoop = null;
|
||||
}
|
||||
if ($this->ipcServer) {
|
||||
$this->ipcServer->signal(null);
|
||||
$this->ipcServer = null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Report RPC errors.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function rpcReport(): \Generator
|
||||
{
|
||||
$toReport = RPCErrorException::$toReport;
|
||||
RPCErrorException::$toReport = [];
|
||||
foreach ($toReport as [$method, $code, $error, $time]) {
|
||||
try {
|
||||
$res = \json_decode(yield from $this->fileGetContents('https://rpc.pwrtelegram.xyz/?method='.$method.'&code='.$code.'&error='.$error.'&t='.$time), true);
|
||||
if (isset($res['ok']) && $res['ok'] && isset($res['result'])) {
|
||||
$description = $res['result'];
|
||||
RPCErrorException::$descriptions[$error] = $description;
|
||||
RPCErrorException::$errorMethodMap[$code][$method][$error] = $error;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Clean up properties from previous versions of MadelineProto.
|
||||
*
|
||||
|
@ -19,6 +19,9 @@
|
||||
|
||||
namespace danog\MadelineProto;
|
||||
|
||||
use Amp\Http\Client\HttpClientBuilder;
|
||||
use Amp\Http\Client\Request;
|
||||
|
||||
/**
|
||||
* Indicates an error returned by Telegram's API.
|
||||
*/
|
||||
@ -32,7 +35,6 @@ class RPCErrorException extends \Exception
|
||||
private $fetched = false;
|
||||
public static $descriptions = ['RPC_MCGET_FAIL' => 'Telegram is having internal issues, please try again later.', 'RPC_CALL_FAIL' => 'Telegram is having internal issues, please try again later.', 'USER_PRIVACY_RESTRICTED' => "The user's privacy settings do not allow you to do this", 'CHANNEL_PRIVATE' => "You haven't joined this channel/supergroup", 'USER_IS_BOT' => "Bots can't send messages to other bots", 'BOT_METHOD_INVALID' => 'This method cannot be run by a bot', 'PHONE_CODE_EXPIRED' => 'The phone code you provided has expired, this may happen if it was sent to any chat on telegram (if the code is sent through a telegram chat (not the official account) to avoid it append or prepend to the code some chars)', 'USERNAME_INVALID' => 'The provided username is not valid', 'ACCESS_TOKEN_INVALID' => 'The provided token is not valid', 'ACTIVE_USER_REQUIRED' => 'The method is only available to already activated users', 'FIRSTNAME_INVALID' => 'The first name is invalid', 'LASTNAME_INVALID' => 'The last name is invalid', 'PHONE_NUMBER_INVALID' => 'The phone number is invalid', 'PHONE_CODE_HASH_EMPTY' => 'phone_code_hash is missing', 'PHONE_CODE_EMPTY' => 'phone_code is missing', 'API_ID_INVALID' => 'The api_id/api_hash combination is invalid', 'PHONE_NUMBER_OCCUPIED' => 'The phone number is already in use', 'PHONE_NUMBER_UNOCCUPIED' => 'The phone number is not yet being used', 'USERS_TOO_FEW' => 'Not enough users (to create a chat, for example)', 'USERS_TOO_MUCH' => 'The maximum number of users has been exceeded (to create a chat, for example)', 'TYPE_CONSTRUCTOR_INVALID' => 'The type constructor is invalid', 'FILE_PART_INVALID' => 'The file part number is invalid', 'FILE_PARTS_INVALID' => 'The number of file parts is invalid', 'MD5_CHECKSUM_INVALID' => 'The MD5 checksums do not match', 'PHOTO_INVALID_DIMENSIONS' => 'The photo dimensions are invalid', 'FIELD_NAME_INVALID' => 'The field with the name FIELD_NAME is invalid', 'FIELD_NAME_EMPTY' => 'The field with the name FIELD_NAME is missing', 'MSG_WAIT_FAILED' => 'A waiting call returned an error', 'USERNAME_NOT_OCCUPIED' => 'The provided username is not occupied', 'PHONE_NUMBER_BANNED' => 'The provided phone number is banned from telegram', 'AUTH_KEY_UNREGISTERED' => 'The authorization key has expired', 'INVITE_HASH_EXPIRED' => 'The invite link has expired', 'USER_DEACTIVATED' => 'The user was deactivated', 'USER_ALREADY_PARTICIPANT' => 'The user is already in the group', 'MESSAGE_ID_INVALID' => 'The provided message id is invalid', 'PEER_ID_INVALID' => 'The provided peer id is invalid', 'CHAT_ID_INVALID' => 'The provided chat id is invalid', 'MESSAGE_DELETE_FORBIDDEN' => "You can't delete one of the messages you tried to delete, most likely because it is a service message.", 'CHAT_ADMIN_REQUIRED' => 'You must be an admin in this chat to do this', -429 => 'Too many requests', 'PEER_FLOOD' => "You are spamreported, you can't do this"];
|
||||
public static $errorMethodMap = [];
|
||||
public static $toReport = [];
|
||||
private $caller = '';
|
||||
public static function localizeMessage($method, int $code, string $error)
|
||||
{
|
||||
@ -42,12 +44,20 @@ class RPCErrorException extends \Exception
|
||||
$error = \preg_replace('/\\d+$/', "X", $error);
|
||||
$description = self::$descriptions[$error] ?? '';
|
||||
if (!isset(self::$errorMethodMap[$code][$method][$error]) || !isset(self::$descriptions[$error]) || $code === 500) {
|
||||
if (\count(self::$toReport) > 100) {
|
||||
self::$toReport = \array_slice(self::$toReport, -100);
|
||||
}
|
||||
self::$toReport []= [
|
||||
$method, $code, $error, \time()
|
||||
];
|
||||
Tools::callFork((function () use ($method, $code, $error) {
|
||||
$res = \json_decode(
|
||||
yield
|
||||
(yield HttpClientBuilder::buildDefault()
|
||||
->request(new Request('https://rpc.pwrtelegram.xyz/?method='.$method.'&code='.$code.'&error='.$error))
|
||||
)->getBody()->buffer(),
|
||||
true
|
||||
);
|
||||
if (isset($res['ok']) && $res['ok'] && isset($res['result'])) {
|
||||
$description = $res['result'];
|
||||
RPCErrorException::$descriptions[$error] = $description;
|
||||
RPCErrorException::$errorMethodMap[$code][$method][$error] = $error;
|
||||
}
|
||||
})());
|
||||
}
|
||||
if (!$description) {
|
||||
return $error;
|
||||
|
@ -162,12 +162,13 @@ fi
|
||||
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||
git config --global user.name "Github Actions"
|
||||
|
||||
[ ! -d MadelineProtoPhar ] && git clone git@github.com:danog/MadelineProtoPhar
|
||||
cd MadelineProtoPhar
|
||||
input=$PWD
|
||||
|
||||
cd ~/MadelineProtoPhar
|
||||
git pull
|
||||
|
||||
cp "../madeline$php$branch.phar" .
|
||||
cp ../tools/phar.php ../examples/mtproxyd .
|
||||
cp "$input/madeline$php$branch.phar" .
|
||||
cp "$input/tools/phar.php" "$input/examples/mtproxyd" .
|
||||
echo -n "$COMMIT-$php" > release$php$branch
|
||||
|
||||
[ "$IS_RELEASE" == "y" ] && {
|
||||
@ -184,9 +185,6 @@ while :; do
|
||||
}
|
||||
done
|
||||
|
||||
cd ..
|
||||
echo "$COMMIT_MESSAGE" | grep "Apply fixes from StyleCI" && exit
|
||||
|
||||
for chat_id in $DESTINATIONS;do
|
||||
curl -s https://api.telegram.org/bot$BOT_TOKEN/sendMessage -F disable_web_page_preview=1 -F text=" <b>Recent Commits to MadelineProto:$BRANCH</b>
|
||||
<a href=\"https://github.com/danog/MadelineProto/commit/$COMMIT\">$COMMIT_MESSAGE (PHP $PHP_MAJOR_VERSION.$PHP_MINOR_VERSION)</a>
|
||||
|
Loading…
Reference in New Issue
Block a user