mirror of
https://github.com/civsocit/olgram.git
synced 2023-07-22 01:29:12 +03:00
inline cache
This commit is contained in:
parent
7c3069ccb8
commit
767cfe64ee
@ -7,19 +7,18 @@ from olgram.models.models import Bot
|
|||||||
import typing as ty
|
import typing as ty
|
||||||
|
|
||||||
|
|
||||||
@cached(ttl=1)
|
@cached(ttl=60)
|
||||||
async def get_phrases(bot: Bot) -> ty.List:
|
async def get_phrases(bot: Bot) -> ty.List:
|
||||||
objects = await bot.answers
|
objects = await bot.answers
|
||||||
return [obj.text for obj in objects]
|
return [obj.text for obj in objects]
|
||||||
|
|
||||||
|
|
||||||
@cached(ttl=1)
|
|
||||||
async def check_chat_member(chat_id: int, user_id: int, bot: AioBot) -> bool:
|
async def check_chat_member(chat_id: int, user_id: int, bot: AioBot) -> bool:
|
||||||
member = await bot.get_chat_member(chat_id, user_id)
|
member = await bot.get_chat_member(chat_id, user_id)
|
||||||
return member.is_chat_member()
|
return member.is_chat_member()
|
||||||
|
|
||||||
|
|
||||||
@cached(ttl=1)
|
@cached(ttl=60)
|
||||||
async def check_permissions(inline_query: InlineQuery, bot: Bot):
|
async def check_permissions(inline_query: InlineQuery, bot: Bot):
|
||||||
user_id = inline_query.from_user.id
|
user_id = inline_query.from_user.id
|
||||||
super_chat_id = await bot.super_chat_id()
|
super_chat_id = await bot.super_chat_id()
|
||||||
@ -38,7 +37,7 @@ async def inline_handler(inline_query: InlineQuery, bot: Bot):
|
|||||||
# Check permissions at first
|
# Check permissions at first
|
||||||
allow = await check_permissions(inline_query, bot)
|
allow = await check_permissions(inline_query, bot)
|
||||||
if not allow:
|
if not allow:
|
||||||
return await inline_query.answer([], cache_time=1) # forbidden
|
return await inline_query.answer([]) # forbidden
|
||||||
|
|
||||||
all_phrases = await get_phrases(bot)
|
all_phrases = await get_phrases(bot)
|
||||||
phrases = [phrase for phrase in all_phrases if inline_query.query.lower() in phrase.lower()]
|
phrases = [phrase for phrase in all_phrases if inline_query.query.lower() in phrase.lower()]
|
||||||
@ -54,4 +53,4 @@ async def inline_handler(inline_query: InlineQuery, bot: Bot):
|
|||||||
)
|
)
|
||||||
items.append(item)
|
items.append(item)
|
||||||
|
|
||||||
await inline_query.answer(results=items, cache_time=1)
|
await inline_query.answer(results=items)
|
||||||
|
Loading…
Reference in New Issue
Block a user