1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 11:34:18 +00:00

🐞 Fix find_author not working in callbacks

This commit is contained in:
Steffo 2020-09-04 03:21:35 +02:00
parent 7d81510fed
commit 17b0b1ee9a

View file

@ -184,21 +184,18 @@ class TelegramSerf(Serf):
await self.api_call(data.cbq.answer,
escape(text))
async def get_author(data, error_if_none=False):
user = data.cbq.from_user
if user is None:
if error_if_none:
raise rc.CommandError("No command caller for this message")
return None
async with data.session_acm() as session:
query = session.query(self.master_table)
for link in self.identity_chain:
query = query.join(link.mapper.class_)
query = query.filter(self.identity_column == user.id)
result = await ru.asyncify(query.one_or_none)
if result is None and error_if_none:
raise rc.CommandError("Command caller is not registered")
return result
async def find_author(data,
*,
session,
required: bool = False) -> Optional[rbt.User]:
user: "telegram.User" = data.cbq.from_user
TelegramT = data.alchemy.get(rbt.Telegram)
result = await ru.asyncify(
session.query(TelegramT).filter(TelegramT.tg_id == user.id).one_or_none
)
if result is None and required:
raise rc.CommandError("You must be registered to use this command.")
return result.user
return TelegramKeyboardData