mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-30 15:04:18 +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):
|
async def get_updates(self):
|
||||||
"""Get the latest updates from the Telegram API with /getUpdates."""
|
"""Get the latest updates from the Telegram API with /getUpdates."""
|
||||||
try:
|
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:
|
except asyncio.TimeoutError:
|
||||||
return
|
return
|
||||||
for update in data:
|
for update in data:
|
||||||
|
@ -129,10 +129,13 @@ class Bot:
|
||||||
if chat.chat_id == chat_id:
|
if chat.chat_id == chat_id:
|
||||||
return chat
|
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."""
|
"""Send a request to the Telegram API at the specified endpoint."""
|
||||||
# Request timeout is 10 seconds.
|
if "timeout" in params:
|
||||||
# TODO: get rid of that t variable
|
t = params["timeout"] + 5
|
||||||
|
else:
|
||||||
|
# Default timeout is 5 seconds.
|
||||||
|
t = 5
|
||||||
with async_timeout.timeout(t):
|
with async_timeout.timeout(t):
|
||||||
# Create a new session for each request.
|
# Create a new session for each request.
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
|
|
Loading…
Reference in a new issue