1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-26 23:34:44 +01:00

Reuse same filtering logic

This commit is contained in:
Daniil Gentili 2024-01-20 19:07:36 +01:00
parent e80993324a
commit ad91942cd3
2 changed files with 99 additions and 13 deletions

2
docs

@ -1 +1 @@
Subproject commit 51c4faa86734ee842fd02d8bfa7fa1facd38593d
Subproject commit 3c3ad496453cd3bc693bebb88edcdaf3745df6f1

View File

@ -43,26 +43,113 @@ class RPCErrorException extends \Exception
private string $caller = '';
private ?string $localized = null;
private static function isBad(string $error, int $code): bool
private const BAD = [
'PEER_FLOOD' => true,
'USER_DEACTIVATED_BAN' => true,
'INPUT_METHOD_INVALID' => true,
'INPUT_FETCH_ERROR' => true,
'AUTH_KEY_UNREGISTERED' => true,
'SESSION_REVOKED' => true,
'USER_DEACTIVATED' => true,
'RPC_SEND_FAIL' => true,
'RPC_CALL_FAIL' => true,
'RPC_MCGET_FAIL' => true,
'INTERDC_5_CALL_ERROR' => true,
'INTERDC_4_CALL_ERROR' => true,
'INTERDC_3_CALL_ERROR' => true,
'INTERDC_2_CALL_ERROR' => true,
'INTERDC_1_CALL_ERROR' => true,
'INTERDC_5_CALL_RICH_ERROR' => true,
'INTERDC_4_CALL_RICH_ERROR' => true,
'INTERDC_3_CALL_RICH_ERROR' => true,
'INTERDC_2_CALL_RICH_ERROR' => true,
'INTERDC_1_CALL_RICH_ERROR' => true,
'AUTH_KEY_DUPLICATED' => true,
'CONNECTION_NOT_INITED' => true,
'LOCATION_NOT_AVAILABLE' => true,
'AUTH_KEY_INVALID' => true,
'LANG_CODE_EMPTY' => true,
'memory limit exit' => true,
'memory limit(?)' => true,
'INPUT_REQUEST_TOO_LONG' => true,
'SESSION_PASSWORD_NEEDED' => true,
'INPUT_FETCH_FAIL' => true,
'CONNECTION_SYSTEM_EMPTY' => true,
'FILE_WRITE_FAILED' => true,
'STORAGE_CHOOSE_VOLUME_FAILED' => true,
'xxx' => true,
'AES_DECRYPT_FAILED' => true,
'Timedout' => true,
'SEND_REACTION_RESULT1_INVALID' => true,
'BOT_POLLS_DISABLED' => true,
'TEMPNAM_FAILED' => true,
'MSG_WAIT_TIMEOUT' => true,
'MEMBER_CHAT_ADD_FAILED' => true,
'CHAT_FROM_CALL_CHANGED' => true,
'MTPROTO_CLUSTER_INVALID' => true,
'CONNECTION_DEVICE_MODEL_EMPTY' => true,
'AUTH_KEY_PERM_EMPTY' => true,
'UNKNOWN_METHOD' => true,
'ENCRYPTION_OCCUPY_FAILED' => true,
'ENCRYPTION_OCCUPY_ADMIN_FAILED' => true,
'CHAT_OCCUPY_USERNAME_FAILED' => true,
'REG_ID_GENERATE_FAILED' => true,
'CONNECTION_LANG_PACK_INVALID' => true,
'MSGID_DECREASE_RETRY' => true,
'API_CALL_ERROR' => true,
'STORAGE_CHECK_FAILED' => true,
'INPUT_LAYER_INVALID' => true,
'NEED_MEMBER_INVALID' => true,
'NEED_CHAT_INVALID' => true,
'HISTORY_GET_FAILED' => true,
'CHP_CALL_FAIL' => true,
'IMAGE_ENGINE_DOWN' => true,
'MSG_RANGE_UNSYNC' => true,
'PTS_CHANGE_EMPTY' => true,
'CONNECTION_SYSTEM_LANG_CODE_EMPTY' => true,
'WORKER_BUSY_TOO_LONG_RETRY' => true,
'WP_ID_GENERATE_FAILED' => true,
'ARR_CAS_FAILED' => true,
'CHANNEL_ADD_INVALID' => true,
'CHANNEL_ADMINS_INVALID' => true,
'CHAT_OCCUPY_LOC_FAILED' => true,
'GROUPED_ID_OCCUPY_FAILED' => true,
'GROUPED_ID_OCCUPY_FAULED' => true,
'LOG_WRAP_FAIL' => true,
'MEMBER_FETCH_FAILED' => true,
'MEMBER_OCCUPY_PRIMARY_LOC_FAILED' => true,
'MEMBER_NO_LOCATION' => true,
'MEMBER_OCCUPY_USERNAME_FAILED' => true,
'MT_SEND_QUEUE_TOO_LONG' => true,
'POSTPONED_TIMEOUT' => true,
'RPC_CONNECT_FAILED' => true,
'SHORTNAME_OCCUPY_FAILED' => true,
'STORE_INVALID_OBJECT_TYPE' => true,
'STORE_INVALID_SCALAR_TYPE' => true,
'TMSG_ADD_FAILED' => true,
'UNKNOWN_ERROR' => true,
'UPLOAD_NO_VOLUME' => true,
'USER_NOT_AVAILABLE' => true,
'VOLUME_LOC_NOT_FOUND' => true,
];
/** @internal */
public static function isBad(string $error, int $code, string $method): 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',
'BOT_POLLS_DISABLED', 'TEMPNAM_FAILED', 'MSG_WAIT_TIMEOUT',
'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',
], true)
return isset(self::BAD[$error])
|| 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);
|| preg_match('/FILE_PART_\d*_MISSING/', $error)
|| ($error === 'Timeout' && !\in_array(strtolower($method), ['messages.getbotcallbackanswer', 'messages.getinlinebotresults'], true))
|| ($error === 'BOT_MISSING' && \in_array($method, ['stickers.changeStickerPosition', 'stickers.createStickerSet', 'messages.uploadMedia'], true));
}
public static function localizeMessage($method, int $code, string $error): string
@ -73,8 +160,7 @@ 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]))
&& !self::isBad($error, $code)
&& !($error === 'Timeout' && !\in_array(strtolower($method), ['messages.getbotcallbackanswer', 'messages.getinlinebotresults'], true))
&& !self::isBad($error, $code, $method)
) {
try {
$res = json_decode(