async def managing_admin_main_menu_add_admin_write_login( message: types.Message, state: FSMContext): """Обработчик ввода логина администратора""" user = DataBaseFunc.get_user(int(message.from_user.id)) user_message = AdminHelper.get_user_from_message(message) data = await state.get_data() if (user_message): await message.delete() data = await state.get_data() user_message.is_admin = True DataBaseFunc.commit() await bot.edit_message_text( chat_id=message.chat.id, message_id=data['message_id'], text=get_text( user, 'managing_admins_main_menu_add_admin_success').format( username=AdminHelper.escape_telegrambot_underscore( user_message.username)), reply_markup=AdminGenerateKeyboard.admin_main_menu(user)) await AdminStateMainMenu.admin_menu.set() else: await message.delete() await bot.edit_message_text( chat_id=message.chat.id, message_id=data['message_id'], text=get_text(user, 'managing_admins_main_menu_add_admin_not_found'), reply_markup=AdminGenerateKeyboard. managing_admins_main_menu_add_admin(user))
async def managing_admins_main_menu_back(callback: types.CallbackQuery): """Возвращает в главное меню админки""" user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text( get_text(user, 'main_admin_menu'), reply_markup=AdminGenerateKeyboard.admin_main_menu(user)) await AdminStateMainMenu.admin_menu.set()
async def managing_users_delete_course_final_cancel( callback: types.CallbackQuery): """Отменяет удаление курса у пользователя.""" await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text( get_text(user, 'main_admin_menu'), reply_markup=AdminGenerateKeyboard.admin_main_menu(user)) await AdminStateMainMenu.admin_menu.set()
async def managin_users_main_menu_delete_course_choose_use_back( callback: types.CallbackQuery): """Вернуться в панель управления пользователями""" await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text( get_text(user, 'main_admin_menu'), reply_markup=AdminGenerateKeyboard.admin_main_menu(user)) await AdminStateMainMenu.admin_menu.set()
async def managing_users_main_menu_add_course_choose_user_cancel( callback: types.CallbackQuery): """Обработка кнопки отменить добавление подписки пользователю""" await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text( get_text(user, 'main_admin_menu'), reply_markup=AdminGenerateKeyboard.admin_main_menu(user)) await AdminStateMainMenu.admin_menu.set()
async def admin_menu(callback: types.CallbackQuery): """Отправляет админ-панель.""" user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text( get_text(user, 'main_admin_menu'), reply_markup=AdminGenerateKeyboard.admin_main_menu(user)) await DataBaseFunc.delete_messages_from_callback( user, callback.message.message_id) await AdminStateMainMenu.admin_menu.set()
async def write_shedule(message : types.Message, state : FSMContext): user = DataBaseFunc.get_user(message.from_user.id) id_shedule = (await state.get_data())["id_shedule"] if id_shedule == 1: with open(texts_shedule_filename, 'w', encoding='utf8') as file: file.write(message.text) else: with open(texts_shedule2_filename, 'w', encoding='utf8') as file: file.write(message.text) await message.answer('Расписание изменено', reply_markup=AdminGenerateKeyboard.admin_main_menu(user)) await AdminStateMainMenu.admin_menu.set()
async def managing_users_delete_course_final_add(callback: types.CallbackQuery, state: FSMContext): """Удалить курс у пользователя.""" await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) data = await state.get_data() delete_user = DataBaseFunc.get_user(data['user_delete_id']) course = DataBaseFunc.get_course(data['course_id']) await DataBaseFunc.delete_course_from_user(delete_user, course) await callback.message.edit_text( get_text(user, 'managing_users_delete_course_final_add').format( course=course.name, username=AdminHelper.escape_telegrambot_underscore( delete_user.username)), reply_markup=AdminGenerateKeyboard.admin_main_menu(user)) await AdminStateMainMenu.admin_menu.set()
async def managing_users_main_menu_add_course_choose_user_add( callback: types.CallbackQuery, state: FSMContext): """Обработка кнопки добавить подписку пользователю""" await callback.answer() data = await state.get_data() user = DataBaseFunc.get_user(callback.from_user.id) user_add = DataBaseFunc.get_user(data['user_add_course_id']) course = DataBaseFunc.get_course(data['course_id']) DataBaseFunc.add_course_in_user(user_add, course) user.subscribe_end = False user.is_register = True DataBaseFunc.commit() await callback.message.edit_text( get_text(user, 'managing_users_main_menu_add_course_choose_user_add'), reply_markup=AdminGenerateKeyboard.admin_main_menu(user)) await AdminStateMainMenu.admin_menu.set()
async def admin_in_admnin_menu(callback: types.CallbackQuery): """Возвращает в главное меню администрации""" await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text(get_text(user, 'main_admin_menu'), reply_markup=AdminGenerateKeyboard.admin_main_menu(user)) await AdminStateMainMenu.admin_menu.set()
async def new_shedule_1_potok_handler(callback : types.CallbackQuery, state : FSMContext): await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text(get_text(user,'main_admin_menu'), reply_markup=AdminGenerateKeyboard.admin_main_menu(user)) await AdminStateMainMenu.admin_menu.set()