diff --git a/requirements.txt b/requirements.txt index 47259f29..d9726c0e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ websockets>=7.0 pytest>=4.3.1 psycopg2-binary>=2.8 aiohttp>=3.5.4 +sqlalchemy>=1.3.2 diff --git a/royalnet/bots/telegram.py b/royalnet/bots/telegram.py index 2d32564d..181650fc 100644 --- a/royalnet/bots/telegram.py +++ b/royalnet/bots/telegram.py @@ -3,7 +3,6 @@ import asyncio import typing import logging as _logging import sys -import re from ..commands import NullCommand from ..utils import asyncify, Call, Command from ..network import RoyalnetLink, Message @@ -89,7 +88,10 @@ class TelegramBot: self.should_run = True while self.should_run: # Get the latest 100 updates - last_updates: typing.List[telegram.Update] = await asyncify(self.bot.get_updates, offset=self.offset) + try: + last_updates: typing.List[telegram.Update] = await asyncify(self.bot.get_updates, offset=self.offset, timeout=60) + except telegram.error.TimedOut: + continue # Handle updates for update in last_updates: # noinspection PyAsyncCall @@ -99,8 +101,6 @@ class TelegramBot: self.offset = last_updates[-1].update_id + 1 except IndexError: pass - # Wait for a while TODO: use long polling - await asyncio.sleep(1) async def handle_update(self, update: telegram.Update): # Skip non-message updates diff --git a/royalnet/database/tables/telegram.py b/royalnet/database/tables/telegram.py index 20f3d7e1..c0934362 100644 --- a/royalnet/database/tables/telegram.py +++ b/royalnet/database/tables/telegram.py @@ -33,4 +33,3 @@ class Telegram: return f"{self.tg_first_name} {self.tg_last_name}" else: return self.tg_first_name -