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_user_add_time_write_time(message: types.Message, state: FSMContext): """Ввод времени""" data = await state.get_data() user = DataBaseFunc.get_user(message.from_user.id) try: time = int(message.text) await state.update_data(time=time) await message.delete() user_addtime = DataBaseFunc.get_user(data['user_deletetime_id']) await bot.edit_message_text( text=AdminHelper.get_text_managing_users_delete_time_final( user_addtime, data['course_id'], time), chat_id=message.chat.id, message_id=data['message_id'], reply_markup=AdminGenerateKeyboard.managing_users_add_time_final( user)) await AdminStateManagingUser.delete_time_final.set() except: await message.delete() await bot.edit_message_text( chat_id=message.chat.id, message_id=data['message_id'], text=get_text(user, 'managing_user_add_time_write_time_not_str'), reply_markup=AdminGenerateKeyboard. managing_users_add_time_choose_time(user))
async def managin_users_main_menu_delete_course_choose_user( 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 state.update_data(user_deletetime_id=user_message.id) await message.delete() await bot.edit_message_text( chat_id=message.chat.id, message_id=data['message_id'], text=get_text(user, 'managing_users_delete_time_choose_courses'), reply_markup=AdminGenerateKeyboard. managing_users_add_time_choose_course(user_message)) await AdminStateManagingUser.delete_time_choose_course.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_users_add_time_choose_user_not_found'), reply_markup=AdminGenerateKeyboard. admin_menu_managing_users_add_time_choose_user_back(user))
async def managing_courses_add_channels(message: types.Message, state=FSMContext): """Добавление новых каналов в подписку""" # -458757767 user = DataBaseFunc.get_user(message.from_user.id) data = await state.get_data() if (not ("channels" in data.keys())): await state.update_data(channels=[]) data = await state.get_data() channels = data["channels"] if (message.forward_from_chat != None): id_channel = message.forward_from_chat.id full_name_channel = message.forward_from_chat.full_name channels.append({"id": id_channel, "name": full_name_channel}) else: try: mas_text = message.text.split(':') channels.append({"id": mas_text[0], "name": mas_text[1]}) except: pass await state.update_data(channels=channels) await bot.delete_message(message.chat.id, message.message_id) text = AdminHelper.add_channels_in_message( get_text(user, 'managing_course_add_channels'), channels) await bot.edit_message_text(text=text, chat_id=data['chat_id'], message_id=data['message_id'], reply_markup=AdminGenerateKeyboard. managing_courses_add_channels_continue(user))
async def managing_admins_main_menu_list_admins(callback: types.CallbackQuery): """Отправляет список администраторов бота""" await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text( AdminHelper.get_list_admins(user), reply_markup=AdminGenerateKeyboard.managing_admin_list_admins(user))
async def admin_whos(callback: types.CallbackQuery): await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) keyboard = InlineKeyboardMarkup() keyboard.add(InlineKeyboardButton(text="Назад", callback_data="admin_in_admin_menu")) await callback.message.edit_text(text=AdminHelper.get_whos_admin(user), reply_markup=keyboard) await AdminStateMainMenu.whos.set()
async def managing_courses_add_continue(callback: types.CallbackQuery, state: FSMContext): """Кнопка продолжить при добавлении курса.""" user = DataBaseFunc.get_user(callback.from_user.id) data = await state.get_data() text = AdminHelper.get_text_for_additionaly_course(user, data) keyboard = AdminGenerateKeyboard.managing_courses_additionaly(user) await callback.message.edit_text(text, parse_mode="markdown", reply_markup=keyboard) await AdminStateManagingCourses.confirm.set()
async def managing_courses_edit_description(callback: types.CallbackQuery, state=FSMContext): """Обрабатывает кнопки редактировать описание при выбранном для редакта курсе""" await callback.answer() data = await state.get_data() user = DataBaseFunc.get_user(callback.from_user.id) text = get_text(user, 'managing_courses_edit_access_delete') course = DataBaseFunc.get_course(data['id_course']) text = AdminHelper.get_channel_for_managing_courses_edit_access_delete( text, course) await state.update_data(message_id=callback.message.message_id) await callback.message.edit_text(text) await AdminStateManaginCourseEdit.edit_access_delete.set()
async def managing_course_edit_choose(callback: types.CallbackQuery, state: FSMContext): """Обрабатывает редакт конкретного курса""" await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) course = DataBaseFunc.get_course(int(callback.data[21:])) await state.update_data(id_course=course.id) text = AdminHelper.get_text_info_course(user, course) keyboard = AdminGenerateKeyboard.managing_courses_edit_button(user) await callback.message.edit_text(text, parse_mode="markdown", reply_markup=keyboard) await AdminStateManaginCourseEdit.choose_edit.set()
async def managing_users_choose_course_for_delete( callback: types.CallbackQuery, state: FSMContext): """Выбор курса для удаления.""" await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) course_id = callback.data[49:] await state.update_data(course_id=course_id) data = await state.get_data() await callback.message.edit_text( AdminHelper.get_info_for_delete_course(user, data['user_delete_id'], course_id), reply_markup=AdminGenerateKeyboard.managing_users_delete_course_final( user)) await AdminStateManagingUser.delete_course_final.set()
async def managing_courses_edit_access_msg(message: types.Message, state: FSMContext): user = DataBaseFunc.get_user(message.from_user.id) data = await state.get_data() DataBaseFunc.add_channel_in_course(message, data) await message.delete() course = DataBaseFunc.get_course(data['id_course']) text = AdminHelper.get_text_info_course(user, course) keyboard = AdminGenerateKeyboard.managing_courses_edit_button(user) await bot.edit_message_text(text=text, chat_id=message.chat.id, message_id=data['message_id'], reply_markup=keyboard, parse_mode="markdown") await AdminStateManaginCourseEdit.choose_edit.set()
async def managing_users_main_menu_add_course(callback: types.CallbackQuery, state: FSMContext): """Выбрать какой курс добавить пользователю""" await callback.answer() data = await state.get_data() user = DataBaseFunc.get_user(callback.from_user.id) add_user = DataBaseFunc.get_user(int(data['user_add_course_id'])) course_id = int(callback.data[26:]) await state.update_data(message_id=callback.message.message_id, course_id=course_id) await callback.message.edit_text( text=AdminHelper.managing_users_get_info_user(user, add_user, course_id), reply_markup=AdminGenerateKeyboard. managing_users_main_menu_add_course_choose_user(user)) await AdminStateManagingUser.add_course_choouse_user_final.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( 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() if (user_message.is_have_subscription): await bot.edit_message_text( chat_id=message.chat.id, message_id=data['message_id'], text=get_text( user, 'managing_users_mein_menu_add_course_choose_user_is_have'), reply_markup=AdminGenerateKeyboard. admin_menu_managing_users_add_course(user)) return data = await state.get_data() await state.update_data(user_add_course_id=user_message.id) await bot.edit_message_text( chat_id=message.chat.id, message_id=data['message_id'], text=get_text(user, 'managing_users_main_menu_add_course'), reply_markup=AdminGenerateKeyboard.managing_user_add_course( user, user_message)) await AdminStateManagingUser.add_course.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_users_mein_menu_add_course_choose_user_not_found'), reply_markup=AdminGenerateKeyboard. admin_menu_managing_users_add_course(user))