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) data.restore() if not data.all_char: return await query.answer( results=[], switch_pm_text=f'{emoji.CROSS_MARK} 没有搜索到任何结果', switch_pm_parameter="start", ) inline_data = [] for i in data.all_char: inline_data.append(InlineQueryResultCachedPhoto(photo_file_id=i["file_id"], title=i["name"], description=data.name)) await query.answer(inline_data, switch_pm_text=f'{emoji.KEY} 搜索到了 {len(data.all_char)} 个角色', switch_pm_parameter="start")