1
0
mirror of https://github.com/danog/telerpc.git synced 2024-11-30 04:38:57 +01:00

Add global codes

This commit is contained in:
Daniil Gentili 2024-06-15 17:59:41 +02:00
parent 591f2e1e3f
commit 25c45d62de

View File

@ -4,6 +4,10 @@ use danog\MadelineProto\RPCErrorException;
final class Main final class Main
{ {
private const GLOBAL_CODES = [
'FLOOD_WAIT_%d' => 420,
];
private ?\PDO $pdo = null; private ?\PDO $pdo = null;
private function connect(): \PDO private function connect(): \PDO
@ -98,6 +102,7 @@ final class Main
$q = $this->pdo->prepare('SELECT method, code, error FROM errors'); $q = $this->pdo->prepare('SELECT method, code, error FROM errors');
$q->execute(); $q->execute();
$r = []; $r = [];
$errors = [];
$bot_only = []; $bot_only = [];
$q->fetchAll(PDO::FETCH_FUNC, function ($method, $code, $error) use (&$r, &$bot_only, $core) { $q->fetchAll(PDO::FETCH_FUNC, function ($method, $code, $error) use (&$r, &$bot_only, $core) {
if ($core && ($error === 'UPDATE_APP_TO_LOGIN' || $error === 'UPDATE_APP_REQUIRED')) { if ($core && ($error === 'UPDATE_APP_TO_LOGIN' || $error === 'UPDATE_APP_REQUIRED')) {
@ -108,6 +113,7 @@ final class Main
if (!\in_array($method, $r[$code][$error] ?? [])) { if (!\in_array($method, $r[$code][$error] ?? [])) {
$r[$code][$error][] = $method; $r[$code][$error][] = $method;
} }
$errors[$error] = true;
if (\in_array($error, ['USER_BOT_REQUIRED', 'USER_BOT_INVALID']) && !\in_array($method, $bot_only) && !in_array($method, ['bots.setBotInfo', 'bots.getBotInfo'])) { if (\in_array($error, ['USER_BOT_REQUIRED', 'USER_BOT_INVALID']) && !\in_array($method, $bot_only) && !in_array($method, ['bots.setBotInfo', 'bots.getBotInfo'])) {
$bot_only[] = $method; $bot_only[] = $method;
} }
@ -129,6 +135,16 @@ final class Main
$hr['FLOOD_WAIT_%d'] = 'Please wait %d seconds before repeating the action.'; $hr['FLOOD_WAIT_%d'] = 'Please wait %d seconds before repeating the action.';
foreach ($hr as $err => $_) {
if (isset($errors[$err])) {
continue;
}
if (!isset(self::GLOBAL_CODES[$err])) {
throw new AssertionError("Missing code for $err!");
}
$r[self::GLOBAL_CODES[$err]][$err] = [];
}
return [$r, $hr, $bot_only]; return [$r, $hr, $bot_only];
} }