replace-bot/handlers/callback/main.py

57 lines
1.7 KiB
Python
Raw Permalink Normal View History

2022-02-16 18:13:44 +03:00
import logging
from aiogram import types
from load import dp
from keyboards.inline.keyboard import cancel_button, menu
from parser import get_about_replacements
2023-02-19 01:51:52 +03:00
@dp.callback_query_handler(lambda c: c.data != "back" and not len(c.data.split("|")) == 2)
2022-02-16 18:13:44 +03:00
async def callback_query(query: types.CallbackQuery):
from_user = query.from_user
data = get_about_replacements()
group = query.data
logging.info("Button: {btn}, User: {user_id} - {username}".format(
user_id=str(from_user.id),
username=str(from_user.username),
btn=str(group)
))
if group in data['data']:
await query.message.edit_text(
text="Группа: {group}\nЗамены: {replace}"
.format(
group=str(group),
replace=data['data'][group]
),
reply_markup=cancel_button
)
else:
await query.message.edit_text(
text=(
"Группа: {group} не найдена!\n"
"Список обновится автоматически после нажатия кнопки ниже"
)
.format(
group=str(group),
),
reply_markup=cancel_button
)
#await query.answer()
@dp.callback_query_handler(lambda c: c.data == "back")
async def back_button(query: types.CallbackQuery):
data = get_about_replacements()
await query.message.edit_text(
"{date}\n{teacher}\nВыберите свою группу"
.format(
date=data["date"],
teacher=data["another_teacher"]
),
reply_markup=menu(data["data"])
)
await query.answer()