mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
🐞 Fix find_author not working in callbacks
This commit is contained in:
parent
7d81510fed
commit
17b0b1ee9a
1 changed files with 12 additions and 15 deletions
|
@ -184,21 +184,18 @@ class TelegramSerf(Serf):
|
||||||
await self.api_call(data.cbq.answer,
|
await self.api_call(data.cbq.answer,
|
||||||
escape(text))
|
escape(text))
|
||||||
|
|
||||||
async def get_author(data, error_if_none=False):
|
async def find_author(data,
|
||||||
user = data.cbq.from_user
|
*,
|
||||||
if user is None:
|
session,
|
||||||
if error_if_none:
|
required: bool = False) -> Optional[rbt.User]:
|
||||||
raise rc.CommandError("No command caller for this message")
|
user: "telegram.User" = data.cbq.from_user
|
||||||
return None
|
TelegramT = data.alchemy.get(rbt.Telegram)
|
||||||
async with data.session_acm() as session:
|
result = await ru.asyncify(
|
||||||
query = session.query(self.master_table)
|
session.query(TelegramT).filter(TelegramT.tg_id == user.id).one_or_none
|
||||||
for link in self.identity_chain:
|
)
|
||||||
query = query.join(link.mapper.class_)
|
if result is None and required:
|
||||||
query = query.filter(self.identity_column == user.id)
|
raise rc.CommandError("You must be registered to use this command.")
|
||||||
result = await ru.asyncify(query.one_or_none)
|
return result.user
|
||||||
if result is None and error_if_none:
|
|
||||||
raise rc.CommandError("Command caller is not registered")
|
|
||||||
return result
|
|
||||||
|
|
||||||
return TelegramKeyboardData
|
return TelegramKeyboardData
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue