Commit 0dee13b0 authored by Jack'lul's avatar Jack'lul

Changes...

parent ac29f07a
......@@ -1079,7 +1079,7 @@ class DB
$date = self::getTimestamp(time());
$date_minute = self::getTimestamp(strtotime('-1 minute'));
$sth->bindParam(':chat_id', $chat_id, \PDO::PARAM_INT);
$sth->bindParam(':chat_id', $chat_id, \PDO::PARAM_STR);
$sth->bindParam(':inline_message_id', $inline_message_id, \PDO::PARAM_STR);
$sth->bindParam(':date', $date, \PDO::PARAM_STR);
$sth->bindParam(':date_minute', $date_minute, \PDO::PARAM_STR);
......@@ -1095,8 +1095,8 @@ class DB
/**
* Insert Telegram API request in db
*
* @param string $method
* @param array $data
* @param string $method
* @param array $data
*
* @return bool If the insert was successful
* @throws \Longman\TelegramBot\Exception\TelegramException
......@@ -1107,7 +1107,7 @@ class DB
return false;
}
$chat_id = ((isset($data['chat_id']) && $data['chat_id'] != 0) ? $data['chat_id'] : null);
$chat_id = ((isset($data['chat_id'])) ? $data['chat_id'] : null);
$inline_message_id = (isset($data['inline_message_id']) ? $data['inline_message_id'] : null);
try {
......@@ -1122,7 +1122,7 @@ class DB
$created_at = self::getTimestamp();
$sth->bindParam(':chat_id', $chat_id, \PDO::PARAM_INT);
$sth->bindParam(':chat_id', $chat_id, \PDO::PARAM_STR);
$sth->bindParam(':inline_message_id', $inline_message_id, \PDO::PARAM_STR);
$sth->bindParam(':method', $method, \PDO::PARAM_STR);
$sth->bindParam(':date', $created_at, \PDO::PARAM_STR);
......
......@@ -1027,11 +1027,7 @@ class Request
if ((isset($data['chat_id']) || isset($data['inline_message_id'])) && in_array($action, $limited_methods)) {
$timeout = 60;
$tick = 500000; //msec
if (!is_numeric($data['chat_id'])) {
$data['chat_id'] = 0;
}
$retry = false;
while (true) {
$requests = DB::getTelegramRequestCount((isset($data['chat_id']) ? $data['chat_id'] : null), (isset($data['inline_message_id']) ? $data['inline_message_id'] : null));
......@@ -1040,12 +1036,18 @@ class Request
break;
}
usleep($tick);
$timeout = $timeout - ($tick / 1000000);
sleep(1);
$timeout = $timeout - 1;
if ($timeout <= 0) {
TelegramLog::debug('Timed out while waiting for a request slot, retrying with 10 seconds delay!' . PHP_EOL . 'Request data:' . PHP_EOL . print_r($data, true) . PHP_EOL . PHP_EOL);
$timeout = 10;
if ($retry) {
throw new TelegramException('Timed out while waiting for a request slot after 2 tries!');
} else {
$timeout = 60;
$retry = true;
TelegramLog::debug('Timed out while waiting for a request slot, retrying! Request data:' . PHP_EOL . print_r($data, true) . PHP_EOL . PHP_EOL);
}
}
}
......
......@@ -214,12 +214,10 @@ CREATE TABLE IF NOT EXISTS `botan_shortener` (
CREATE TABLE IF NOT EXISTS `request_limiter` (
`id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry',
`chat_id` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier',
`chat_id` char(255) NULL DEFAULT NULL COMMENT 'Unique chat identifier',
`inline_message_id` char(255) NULL DEFAULT NULL COMMENT 'Identifier of the sent inline message',
`method` char(255) DEFAULT NULL COMMENT 'Request method',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
PRIMARY KEY (`id`),
FOREIGN KEY (`chat_id`) REFERENCES `chat` (`id`)
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT charSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
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