Inline query decorator refactored
This commit is contained in:
parent
d6b7b3002e
commit
367b112809
@ -1421,45 +1421,27 @@ class Bot(TelegramBot, ObjectWithDatabase):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def decorator(func):
|
def query_decorator(handler):
|
||||||
if asyncio.iscoroutinefunction(func):
|
async def decorated_query_handler(bot, update, user_record):
|
||||||
async def decorated(message, user_record, bot):
|
logging.info(
|
||||||
logging.info(
|
f"Inline query matching condition "
|
||||||
"QUERY MATCHING CONDITION({c}) @{n} FROM({f})".format(
|
f"`{condition.__name__}@{bot.name}` from "
|
||||||
c=condition.__name__,
|
f"`{update['from']}`"
|
||||||
n=self.name,
|
)
|
||||||
f=message['from']
|
if self.authorization_function(
|
||||||
)
|
update=update,
|
||||||
)
|
user_record=user_record,
|
||||||
if self.authorization_function(
|
authorization_level=authorization_level
|
||||||
update=message,
|
):
|
||||||
user_record=user_record,
|
return await handler(bot=self, update=update,
|
||||||
authorization_level=authorization_level
|
user_record=user_record)
|
||||||
):
|
return self.unauthorized_message
|
||||||
return await func(message)
|
|
||||||
return self.unauthorized_message
|
|
||||||
else:
|
|
||||||
def decorated(message, user_record, bot):
|
|
||||||
logging.info(
|
|
||||||
"QUERY MATCHING CONDITION({c}) @{n} FROM({f})".format(
|
|
||||||
c=condition.__name__,
|
|
||||||
n=self.name,
|
|
||||||
f=message['from']
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if self.authorization_function(
|
|
||||||
update=message,
|
|
||||||
user_record=user_record,
|
|
||||||
authorization_level=authorization_level
|
|
||||||
):
|
|
||||||
return func(message)
|
|
||||||
return self.unauthorized_message
|
|
||||||
self.inline_query_handlers[condition] = dict(
|
self.inline_query_handlers[condition] = dict(
|
||||||
function=decorated,
|
handler=decorated_query_handler,
|
||||||
description=description,
|
description=description,
|
||||||
authorization_level=authorization_level
|
authorization_level=authorization_level
|
||||||
)
|
)
|
||||||
return decorator
|
return query_decorator
|
||||||
|
|
||||||
def set_chat_id_getter(self, getter):
|
def set_chat_id_getter(self, getter):
|
||||||
"""Set chat_id getter.
|
"""Set chat_id getter.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user