Enka_Panel_Bot/plugins/callback.py

29 lines
1.1 KiB
Python
Raw Normal View History

2022-09-03 14:50:36 +00:00
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())
2023-01-14 13:59:43 +00:00
if char_data := next((i for i in data.all_char if i.name == char), None):
2022-09-03 14:50:36 +00:00
await callback_query.message.edit_media(
2023-01-14 13:59:43 +00:00
InputMediaPhoto(media=char_data.file_id),
2022-09-03 14:50:36 +00:00
reply_markup=data.gen_back())
else:
return await callback_query.answer("没有可展示的角色,可能是数据未刷新", show_alert=True)