mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Use long polling
This commit is contained in:
parent
94980b3d15
commit
eb821a6259
3 changed files with 5 additions and 5 deletions
|
@ -3,3 +3,4 @@ websockets>=7.0
|
||||||
pytest>=4.3.1
|
pytest>=4.3.1
|
||||||
psycopg2-binary>=2.8
|
psycopg2-binary>=2.8
|
||||||
aiohttp>=3.5.4
|
aiohttp>=3.5.4
|
||||||
|
sqlalchemy>=1.3.2
|
||||||
|
|
|
@ -3,7 +3,6 @@ import asyncio
|
||||||
import typing
|
import typing
|
||||||
import logging as _logging
|
import logging as _logging
|
||||||
import sys
|
import sys
|
||||||
import re
|
|
||||||
from ..commands import NullCommand
|
from ..commands import NullCommand
|
||||||
from ..utils import asyncify, Call, Command
|
from ..utils import asyncify, Call, Command
|
||||||
from ..network import RoyalnetLink, Message
|
from ..network import RoyalnetLink, Message
|
||||||
|
@ -89,7 +88,10 @@ class TelegramBot:
|
||||||
self.should_run = True
|
self.should_run = True
|
||||||
while self.should_run:
|
while self.should_run:
|
||||||
# Get the latest 100 updates
|
# 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
|
# Handle updates
|
||||||
for update in last_updates:
|
for update in last_updates:
|
||||||
# noinspection PyAsyncCall
|
# noinspection PyAsyncCall
|
||||||
|
@ -99,8 +101,6 @@ class TelegramBot:
|
||||||
self.offset = last_updates[-1].update_id + 1
|
self.offset = last_updates[-1].update_id + 1
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
# Wait for a while TODO: use long polling
|
|
||||||
await asyncio.sleep(1)
|
|
||||||
|
|
||||||
async def handle_update(self, update: telegram.Update):
|
async def handle_update(self, update: telegram.Update):
|
||||||
# Skip non-message updates
|
# Skip non-message updates
|
||||||
|
|
|
@ -33,4 +33,3 @@ class Telegram:
|
||||||
return f"{self.tg_first_name} {self.tg_last_name}"
|
return f"{self.tg_first_name} {self.tg_last_name}"
|
||||||
else:
|
else:
|
||||||
return self.tg_first_name
|
return self.tg_first_name
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue