Enka_Panel_Bot/plugins/inline.py

40 lines
1.2 KiB
Python
Raw Normal View History

2022-09-03 14:50:36 +00:00
from pyrogram import Client, emoji
from pyrogram.types import InlineQuery, InlineQueryResultCachedPhoto
from ci import app
from defs.bind import check_bind, get_bind_uid
from defs.player import Player
@app.on_inline_query()
async def answer_callback(_: Client, query: InlineQuery):
uid = None
if check_bind(query.from_user.id):
uid = get_bind_uid(query.from_user.id)
if query.query:
uid = query.query
if not uid:
return await query.answer(
results=[],
switch_pm_text=f'{emoji.CROSS_MARK} 没有搜索到任何结果',
switch_pm_parameter="start",
)
data = Player(uid)
if not data.all_char:
return await query.answer(
results=[],
switch_pm_text=f'{emoji.CROSS_MARK} 没有搜索到任何结果',
switch_pm_parameter="start",
)
2023-01-14 13:59:43 +00:00
inline_data = [
InlineQueryResultCachedPhoto(
photo_file_id=i.file_id, title=i.name, description=data.name
)
for i in data.all_char
]
await query.answer(
inline_data,
switch_pm_text=f'{emoji.KEY} 搜索到了 {len(data.all_char)} 个角色',
switch_pm_parameter="start",
)