mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Improved debug loop
This commit is contained in:
parent
65caeb9cea
commit
5f16353fbd
1 changed files with 6 additions and 8 deletions
14
telegram.py
14
telegram.py
|
@ -16,10 +16,10 @@ class Bot:
|
||||||
self.user_data = None
|
self.user_data = None
|
||||||
self.updates = list()
|
self.updates = list()
|
||||||
self.chats = list()
|
self.chats = list()
|
||||||
self.commands = list()
|
self.commands = dict()
|
||||||
self.offset = 0
|
self.offset = 0
|
||||||
# Update user_data
|
# Update user_data
|
||||||
loop.run_until_complete(self.update_bot_data())
|
loop.create_task(self.update_bot_data())
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Bot {self.user_data.first_name}>"
|
return f"<Bot {self.user_data.first_name}>"
|
||||||
|
@ -35,7 +35,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", offset=self.offset, timeout=0)
|
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:
|
||||||
|
@ -46,7 +46,7 @@ class Bot:
|
||||||
if len(data) > 0:
|
if len(data) > 0:
|
||||||
self.offset = self.updates[-1].update_id + 1
|
self.offset = self.updates[-1].update_id + 1
|
||||||
|
|
||||||
def parse_update(self):
|
async def parse_update(self):
|
||||||
"""Parse the first update in the list."""
|
"""Parse the first update in the list."""
|
||||||
update = self.updates[0]
|
update = self.updates[0]
|
||||||
if update.message.chat not in self.chats:
|
if update.message.chat not in self.chats:
|
||||||
|
@ -63,8 +63,6 @@ class Bot:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
chat.messages[i] = update.message
|
chat.messages[i] = update.message
|
||||||
|
|
||||||
|
|
||||||
del self.updates[0]
|
del self.updates[0]
|
||||||
|
|
||||||
def find_chat(self, chat_id):
|
def find_chat(self, chat_id):
|
||||||
|
@ -325,9 +323,9 @@ class Venue:
|
||||||
raise NotImplementedError("Not yet.")
|
raise NotImplementedError("Not yet.")
|
||||||
|
|
||||||
|
|
||||||
b = Bot("369842636:AAGfCd1ZNIgmU5w2ltmpSjMFt2c7O8tHvaU")
|
b = Bot("infopz pls non sono così stupido")
|
||||||
while True:
|
while True:
|
||||||
loop.run_until_complete(b.get_updates())
|
loop.run_until_complete(b.get_updates())
|
||||||
while len(b.updates) > 0:
|
while len(b.updates) > 0:
|
||||||
b.parse_update()
|
loop.create_task(b.parse_update())
|
||||||
print("Completed.")
|
print("Completed.")
|
Loading…
Reference in a new issue