Commit 899b79ba authored by Jack'lul's avatar Jack'lul

Improve code readability

parent b2e1c34c
...@@ -1029,21 +1029,30 @@ class Request ...@@ -1029,21 +1029,30 @@ class Request
'editMessageReplyMarkup', 'editMessageReplyMarkup',
]; ];
if ((isset($data['chat_id']) || isset($data['inline_message_id'])) && in_array($action, $limited_methods)) { $chat_id = isset($data['chat_id']) ? $data['chat_id'] : null;
$inline_message_id = isset($data['inline_message_id']) ? $data['inline_message_id'] : null;
if (($chat_id || $inline_message_id) && in_array($action, $limited_methods)) {
$timeout = 60; $timeout = 60;
while (true) { while (true) {
if ($timeout <= 0) { if ($timeout <= 0) {
throw new TelegramException('Timed out while waiting for a request slot!'); throw new TelegramException('Timed out while waiting for a request spot!');
} }
$requests = DB::getTelegramRequestCount((isset($data['chat_id']) ? $data['chat_id'] : null), (isset($data['inline_message_id']) ? $data['inline_message_id'] : null)); $requests = DB::getTelegramRequestCount($chat_id, $inline_message_id);
if ($requests['LIMIT_PER_SEC'] <= 0 && ((isset($data['inline_message_id']) && $requests['LIMIT_PER_SEC_ALL'] < 30) || (isset($data['chat_id']) && $data['chat_id'] > 0 && $requests['LIMIT_PER_SEC_ALL'] < 30) || (isset($data['chat_id']) && $data['chat_id'] < 0 && $requests['LIMIT_PER_MINUTE'] < 20))) { if (
$requests['LIMIT_PER_SEC'] == 0 && // No more than one message per second inside a particular chat
(
(($chat_id > 0 || $inline_message_id) && $requests['LIMIT_PER_SEC_ALL'] < 30) || // No more than 30 messages per second globally
($chat_id < 0 && $requests['LIMIT_PER_MINUTE'] < 20) // No more than 20 messages per minute for group chats
)
) {
break; break;
} }
$timeout = $timeout - 1; $timeout--;
sleep(1); sleep(1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment