from aiogram import Router, F from aiogram.types import CallbackQuery from aiogram.fsm.context import FSMContext from handlers.ban_words import ban_words_btn from templates import message as tmessage from templates import commands as tcommands from handlers.message import message_btn from utils.defs import delete_msg router = Router() @router.callback_query(F.data == 'come_back_buttons') async def come_back_buttons_btn(call: CallbackQuery, state: FSMContext): """ Ловит кнопку ⬅️ Назад :param call: CallbackQuery :param state: FSMContext :return: """ state_data = await state.get_data() await state_data['last_msg'].edit_text( text=tmessage.send_buttons_text, reply_markup=tmessage.send_buttons_ikb() ) await delete_msg( msg=state_data.get('preview_msg') ) state_data['edited_message_data']['buttons'] = [] await state.update_data( edited_message_data=state_data['edited_message_data'] ) await state.set_state( state=tmessage.SendState.buttons ) @router.callback_query(F.data == 'come_back_message') async def come_back_message_btn(call: CallbackQuery, state: FSMContext): """ Ловит кнопку ⬅️ Назад :param call: CallbackQuery :param state: FSMContext :return: """ state_data = await state.get_data() await state_data['last_msg'].edit_text( text=tmessage.send_message_text, reply_markup=tmessage.send_message_ikb() ) await state.set_state( state=tmessage.SendState.message ) @router.callback_query(F.data == 'come_back_preview') async def come_back_preview_btn(call: CallbackQuery, state: FSMContext): """ Ловит кнопку ⬅️ Назад :param call: CallbackQuery :param state: FSMContext :return: """ await message_btn( call=call, state=state ) @router.callback_query(F.data == 'come_back_menu') async def come_back_preview_btn(call: CallbackQuery, state: FSMContext): """ Ловит кнопку ⬅️ Назад :param call: CallbackQuery :param state: FSMContext :return: """ state_data = await state.get_data() last_msg = await call.message.answer( text=tcommands.start_text, reply_markup=await tcommands.start_ikb() ) await state.update_data( last_msg=last_msg ) await delete_msg( msg=state_data.get('preview_msg') ) await delete_msg( msg=state_data.get('last_msg') ) @router.callback_query(F.data == 'come_back_ban_words') async def come_back_ban_words_btn(call: CallbackQuery, state: FSMContext): """ Ловит кнопку ⬅️ Назад :param call: CallbackQuery :param state: FSMContext :return: """ await ban_words_btn( call=call, state=state )