mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Fixed timeout
This commit is contained in:
parent
60876e92b2
commit
fd76f5b432
1 changed files with 13 additions and 10 deletions
11
telegram.py
11
telegram.py
|
@ -49,7 +49,7 @@ class Bot:
|
|||
async def get_updates(self):
|
||||
"""Get the latest updates from the Telegram API with /getUpdates."""
|
||||
try:
|
||||
data = await self.api_request("getUpdates", 300, offset=self.offset, timeout=300)
|
||||
data = await self.api_request("getUpdates", offset=self.offset, timeout=300)
|
||||
except asyncio.TimeoutError:
|
||||
return
|
||||
for update in data:
|
||||
|
@ -129,10 +129,13 @@ class Bot:
|
|||
if chat.chat_id == chat_id:
|
||||
return chat
|
||||
|
||||
async def api_request(self, endpoint, t=10, **params):
|
||||
async def api_request(self, endpoint, **params):
|
||||
"""Send a request to the Telegram API at the specified endpoint."""
|
||||
# Request timeout is 10 seconds.
|
||||
# TODO: get rid of that t variable
|
||||
if "timeout" in params:
|
||||
t = params["timeout"] + 5
|
||||
else:
|
||||
# Default timeout is 5 seconds.
|
||||
t = 5
|
||||
with async_timeout.timeout(t):
|
||||
# Create a new session for each request.
|
||||
async with aiohttp.ClientSession() as session:
|
||||
|
|
Loading…
Reference in a new issue