Skip to content
This repository has been archived by the owner on May 20, 2023. It is now read-only.

Commit

Permalink
Enhance: richer logs and better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatan1609 committed Sep 26, 2021
1 parent 3dd859c commit 7ef5eda
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions bot/handlers/VerifyButtons.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from pyrogram import Client, types
from pyrogram import Client, types, errors
from ..filters import human, bot
from .. import futures, strings
from ..database import Group
from pony.orm import db_session
from loguru import logger


@Client.on_callback_query(human)
async def i_am_a_human(_: Client, callback: types.CallbackQuery):
async def get_future(client, callback):
future = futures.get(
(
callback.message.chat.id,
Expand All @@ -18,7 +17,23 @@ async def i_am_a_human(_: Client, callback: types.CallbackQuery):
with db_session:
group = Group.get(id=callback.message.chat.id)
if not group:
return logger.error(f"Group {callback.message.chat.id} not found!")
logger.error(f"Group {callback.message.chat.id} not found!")
try:
return await client.send_message(
callback.message.chat.id,
strings.readd_group
)
except errors.RPCError as e:
return logger.error(e.MESSAGE)
return future, group


@Client.on_callback_query(human)
async def i_am_a_human(client: Client, callback: types.CallbackQuery):
future, *group = await get_future(client, callback)
group, = group
if not group:
return
if future:
future.set_result(True)
else:
Expand All @@ -28,18 +43,11 @@ async def i_am_a_human(_: Client, callback: types.CallbackQuery):


@Client.on_callback_query(bot)
async def i_am_a_bot(_: Client, callback: types.CallbackQuery):
future = futures.get(
(
callback.message.chat.id,
callback.from_user.id,
callback.message.message_id
)
)
with db_session:
group = Group.get(id=callback.message.chat.id)
if not group:
return logger.error(f"Group {callback.message.chat.id} not found!")
async def i_am_a_bot(client: Client, callback: types.CallbackQuery):
future, *group = await get_future(client, callback)
group, = group
if not group:
return
if future:
future.set_result(False)
else:
Expand Down

0 comments on commit 7ef5eda

Please sign in to comment.