29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
from os import sep
|
|
|
|
from pyrogram import Client
|
|
from pyrogram.types import CallbackQuery, InputMediaPhoto
|
|
|
|
from ci import app
|
|
from defs.player import Player
|
|
|
|
|
|
@app.on_callback_query()
|
|
async def answer_callback(_: Client, callback_query: CallbackQuery):
|
|
data = callback_query.data.split("|")
|
|
uid = data[0]
|
|
char = callback_query.data.split("|")[1] if len(data) > 1 else None
|
|
data = Player(uid)
|
|
if not data.all_char:
|
|
return await callback_query.answer("没有可展示的角色,可能是数据未刷新", show_alert=True)
|
|
if not char:
|
|
return await callback_query.message.edit_media(
|
|
InputMediaPhoto(media=f"resources{sep}Kitsune.png",
|
|
caption=f"请选择 {data.name} 的一个角色:"),
|
|
reply_markup=data.gen_keyboard())
|
|
if char_data := next((i for i in data.all_char if i.name == char), None):
|
|
await callback_query.message.edit_media(
|
|
InputMediaPhoto(media=char_data.file_id),
|
|
reply_markup=data.gen_back())
|
|
else:
|
|
return await callback_query.answer("没有可展示的角色,可能是数据未刷新", show_alert=True)
|