From 6c6d257880c9ca669921e5a40ed482d28e3a53a5 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 20 Jan 2024 19:13:43 +0100 Subject: [PATCH] Use same checks --- composer.json | 4 ++++ src/Main.php | 55 +++++++++++++++++---------------------------------- 2 files changed, 22 insertions(+), 37 deletions(-) diff --git a/composer.json b/composer.json index 66e7e59..e54b2a7 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,10 @@ "name": "danog/telerpc", "description": "RPC Error reporting API", "type": "project", + "require": { + "danog/madelineproto": "^8" + }, + "minimum-stability": "dev", "require-dev": { "amphp/php-cs-fixer-config": "dev-master", "friendsofphp/php-cs-fixer": "^2.16" diff --git a/src/Main.php b/src/Main.php index 0cc01c4..f0cb9ff 100644 --- a/src/Main.php +++ b/src/Main.php @@ -1,5 +1,7 @@ true, 'result' => $result]); } - private static function isBad(string $error, int $code): bool - { - return \in_array($error, ['PEER_FLOOD', 'INPUT_CONSTRUCTOR_INVALID_X', 'USER_DEACTIVATED_BAN', 'INPUT_METHOD_INVALID', 'INPUT_FETCH_ERROR', 'AUTH_KEY_UNREGISTERED', 'SESSION_REVOKED', 'USER_DEACTIVATED', 'RPC_SEND_FAIL', 'RPC_CALL_FAIL', 'RPC_MCGET_FAIL', 'INTERDC_5_CALL_ERROR', 'INTERDC_4_CALL_ERROR', 'INTERDC_3_CALL_ERROR', 'INTERDC_2_CALL_ERROR', 'INTERDC_1_CALL_ERROR', 'INTERDC_5_CALL_RICH_ERROR', 'INTERDC_4_CALL_RICH_ERROR', 'INTERDC_3_CALL_RICH_ERROR', 'INTERDC_2_CALL_RICH_ERROR', 'INTERDC_1_CALL_RICH_ERROR', 'AUTH_KEY_DUPLICATED', 'CONNECTION_NOT_INITED', 'LOCATION_NOT_AVAILABLE', 'AUTH_KEY_INVALID', 'LANG_CODE_EMPTY', 'memory limit exit', 'memory limit(?)', 'INPUT_REQUEST_TOO_LONG', 'SESSION_PASSWORD_NEEDED', 'INPUT_FETCH_FAIL', - 'CONNECTION_SYSTEM_EMPTY', - 'FILE_WRITE_FAILED', - 'STORAGE_CHOOSE_VOLUME_FAILED', - 'CONNECTION_SYSTEM_EMPTY', 'xxx', - 'FILE_WRITE_FAILED', 'AES_DECRYPT_FAILED', - 'STORAGE_CHOOSE_VOLUME_FAILED', - 'Timedout', 'SEND_REACTION_RESULT1_INVALID', - 'BOT_POLLS_DISABLED', 'TEMPNAM_FAILED', 'MSG_WAIT_TIMEOUT', 'MEMBER_CHAT_ADD_FAILED', - 'CHAT_FROM_CALL_CHANGED', 'MTPROTO_CLUSTER_INVALID', - 'CONNECTION_DEVICE_MODEL_EMPTY', 'AUTH_KEY_PERM_EMPTY', 'UNKNOWN_METHOD', 'ENCRYPTION_OCCUPY_FAILED', 'ENCRYPTION_OCCUPY_ADMIN_FAILED', 'CHAT_OCCUPY_USERNAME_FAILED', 'REG_ID_GENERATE_FAILED', - 'CONNECTION_LANG_PACK_INVALID', 'MSGID_DECREASE_RETRY', 'API_CALL_ERROR', 'STORAGE_CHECK_FAILED', 'INPUT_LAYER_INVALID', 'NEED_MEMBER_INVALID', 'NEED_CHAT_INVALID', 'HISTORY_GET_FAILED', 'CHP_CALL_FAIL', 'IMAGE_ENGINE_DOWN', 'MSG_RANGE_UNSYNC', 'PTS_CHANGE_EMPTY', - 'CONNECTION_SYSTEM_LANG_CODE_EMPTY', 'WORKER_BUSY_TOO_LONG_RETRY', 'WP_ID_GENERATE_FAILED', 'ARR_CAS_FAILED', 'CHANNEL_ADD_INVALID', 'CHANNEL_ADMINS_INVALID', 'CHAT_OCCUPY_LOC_FAILED', 'GROUPED_ID_OCCUPY_FAILED', 'GROUPED_ID_OCCUPY_FAULED', 'LOG_WRAP_FAIL', 'MEMBER_FETCH_FAILED', 'MEMBER_OCCUPY_PRIMARY_LOC_FAILED', 'MEMBER_FETCH_FAILED', 'MEMBER_NO_LOCATION', 'MEMBER_OCCUPY_USERNAME_FAILED', 'MT_SEND_QUEUE_TOO_LONG', 'POSTPONED_TIMEOUT', 'RPC_CONNECT_FAILED', 'SHORTNAME_OCCUPY_FAILED', 'STORE_INVALID_OBJECT_TYPE', 'STORE_INVALID_SCALAR_TYPE', 'TMSG_ADD_FAILED', 'UNKNOWN_ERROR', 'UPLOAD_NO_VOLUME', 'USER_NOT_AVAILABLE', 'VOLUME_LOC_NOT_FOUND', ]) - || \str_contains($error, 'Received bad_msg_notification') - || \str_contains($error, 'FLOOD_WAIT_') - || \str_contains($error, '_MIGRATE_') - || \str_contains($error, 'INPUT_METHOD_INVALID') - || \str_contains($error, 'INPUT_CONSTRUCTOR_INVALID') - || \str_contains($error, 'INPUT_FETCH_ERROR_') - || \str_contains($error, 'https://telegram.org/dl') - || \str_starts_with($error, 'Received bad_msg_notification') - || \str_starts_with($error, 'No workers running') - || \str_starts_with($error, 'All workers are busy. Active_queries ') - || \preg_match('/FILE_PART_\d*_MISSING/', $error); - } - private static function sanitize(string $error): string { $error = \preg_replace('/_XMIN$/', '_%dMIN', $error); @@ -210,12 +184,17 @@ final class Main $q->execute(); $r = $q->fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_GROUP); foreach ($r as $error => $methods) { - if (self::isBad($error, 0)) { - $q = $this->pdo->prepare('DELETE FROM errors WHERE error=?'); - $q->execute([$error]); - $q = $this->pdo->prepare('DELETE FROM error_descriptions WHERE error=?'); - $q->execute([$error]); - echo 'Delete '.$error."\n"; + $anyok = false; + foreach ($methods as $method) { + if (RPCErrorException::isBad($error, 0, $method)) { + $q = $this->pdo->prepare('DELETE FROM errors WHERE error=? AND method=?'); + $q->execute([$error, $method]); + echo "Delete $error for $method\n"; + continue; + } + $anyok = true; + } + if (!$anyok) { continue; } $allowed[$error] = true; @@ -284,9 +263,11 @@ final class Main && $_REQUEST['error'] !== '' && $_REQUEST['method'] !== '' && \is_numeric($_REQUEST['code']) - && !self::isBad($_REQUEST['error'], (int) $_REQUEST['code']) - && !($_REQUEST['error'] === 'Timeout' && !\in_array(\strtolower($_REQUEST['method']), ['messages.getbotcallbackanswer', 'messages.getinlinebotresults'])) - && !($_REQUEST['error'] === 'BOT_MISSING' && \in_array($_REQUEST['method'], ['stickers.changeStickerPosition', 'stickers.createStickerSet', 'messages.uploadMedia'])) + && !RPCErrorException::isBad( + $_REQUEST['error'], + (int) $_REQUEST['code'], + $_REQUEST['method'] + ) ) { $error = self::sanitize($_REQUEST['error']); $method = $_REQUEST['method'];