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 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 process_successful_payment(message: types.Message, state: FSMContext): user = DataBaseFunc.get_user(message.from_user.id) data = await state.get_data() course = DataBaseFunc.get_course(user.course_id) DataBaseFunc.add_course_in_user(user, course) user.subscribe_end = False DataBaseFunc.commit() for channel in course.channels: try: await bot.unban_chat_member(chat_id=channel.channels.id, user_id=user.id) except: continue mess = await bot.send_message( message.chat.id, str(get_text(user, 'subscribe_menu_good_pay')).format( amount=course.cost, currency=message.successful_payment.currency, coursename=course.name)) mess2 = await bot.send_message(message.chat.id, get_text(user, 'start'), reply_markup=await UserGeneratorKeyboard.start_button(user)) await DataBaseFunc.delete_messages(user) ms = Message(user_id=user.id, message_id=mess.message_id) ms2 = Message(user_id=user.id, message_id=mess2.message_id) DataBaseFunc.add(ms) DataBaseFunc.add(ms2) await UserStateMainMenu.main_menu.set()
async def register_phone_write(message: types.Message, state: FSMContext): """Ввод номера телефона.""" await message.delete() user = DataBaseFunc.get_user(message.from_user.id) data = await state.get_data() message_id = data['callback_message_id'] phone = "".join(ch for ch in message.text if ch.isdigit()) if (phone[0] == '8'): phone = '7' + phone[1:] errors = get_text(user, 'write_phone_errors') keyboard = UserGeneratorKeyboard.register_button(user) # keyboard = types.InlineKeyboardMarkup() # keyboard.add(types.InlineKeyboardButton(get_text_but(user, 'register_write_back'), callback_data="register_write_back")) if len(phone) == 0: await bot.edit_message_text(text=errors['empty'], chat_id=message.chat.id, message_id=message_id, reply_markup=keyboard) await UserStateRegister.main_menu.set() return check_user = DataBaseFunc.get_user_for_phone(phone) if (check_user != None): await bot.edit_message_text(text=errors['is_register'], chat_id=message.chat.id, message_id=message_id, reply_markup=keyboard) await UserStateRegister.main_menu.set() return contact = DataBaseFunc.get_contact(phone=phone) if (contact == None): await bot.edit_message_text(text=errors['not_found'], chat_id=message.chat.id, message_id=message_id, reply_markup=keyboard) await UserStateRegister.main_menu.set() return user.phone = phone user.mail = contact.mail user.is_register = True user.course_id = contact.course_id contact.is_register = True DataBaseFunc.commit() DataBaseFunc.add_course_in_user(user, DataBaseFunc.get_course(user.course_id)) await bot.edit_message_text(text=get_text(user, 'start'), chat_id=message.chat.id, message_id=message_id, reply_markup=await UserGeneratorKeyboard.start_button(user)) await UserStateMainMenu.main_menu.set()
async def register_mail_write(message: types.Message, state: FSMContext): """Ввод номера телефона.""" await message.delete() user = DataBaseFunc.get_user(message.from_user.id) data = await state.get_data() message_id = data['callback_message_id'] mail = message.text mail = mail.lower() errors = get_text(user, 'write_mail_errors') keyboard = UserGeneratorKeyboard.register_button(user) # keyboard = types.InlineKeyboardMarkup() # keyboard.add(types.InlineKeyboardButton(get_text_but(user, 'register_write_back'), callback_data="register_write_back")) if ("@" in mail) == False: await bot.edit_message_text(text=errors['empty'], chat_id=message.chat.id, message_id=message_id, reply_markup=keyboard) await UserStateRegister.main_menu.set() return check_user = DataBaseFunc.get_user_for_mail(mail) if (check_user != None): await bot.edit_message_text(text=errors['is_register'], chat_id=message.chat.id, message_id=message_id, reply_markup=keyboard) await UserStateRegister.main_menu.set() return contact = DataBaseFunc.get_contact(mail=mail) if (contact == None): await bot.edit_message_text(text=errors['not_found'], chat_id=message.chat.id, message_id=message_id, reply_markup=keyboard) await UserStateRegister.main_menu.set() return user.mail = mail user.phone = contact.phone user.is_register = True contact.is_register = True user.course_id = contact.course_id DataBaseFunc.commit() DataBaseFunc.add_course_in_user(user, DataBaseFunc.get_course(user.course_id)) await bot.edit_message_text(text=get_text(user, 'start'), chat_id=message.chat.id, message_id=message_id, reply_markup=await UserGeneratorKeyboard.start_button(user)) await UserStateMainMenu.main_menu.set()
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_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 main_menu_back(callback: types.CallbackQuery): """Возвращает пользователя в главное меню из меню с выбором тарифа для оплаты.""" user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text(get_text(user, 'start'), reply_markup=await UserGeneratorKeyboard.start_button(user)) await UserStateMainMenu.main_menu.set()
async def main_menu_subscribe(callback: types.CallbackQuery): """Реализует отправку доступных для покупки курсов.""" user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text( get_text(user, "main_menu_subscribe"), reply_markup=UserGeneratorKeyboard.main_menu_subscribe(user)) await UserStateMainMenu.get_subscribe.set()
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 subscribe_menu_choose_course(callback: types.CallbackQuery, state: FSMContext): """Отправляет чек для оплаты выбраноого курса""" user = DataBaseFunc.get_user(callback.from_user.id) if (TOKEN_SHOP_YANDEX.split(':')[1] == "TEST"): await callback.message.edit_text( text=get_text(user, 'subscribe_menu_test_payments')) course = DataBaseFunc.get_course(int(callback.data[20:])) timestamp = get_timestamp(user) PRICE = types.LabeledPrice(label=course.name, amount=int(f"{course.cost}00")) await state.update_data(last_course_id=int(callback.data[20:])) await bot.send_invoice( callback.message.chat.id, title=course.name, description=course.description, provider_token=TOKEN_SHOP_YANDEX, currency="rub", is_flexible=False, prices=[PRICE], start_parameter=f"course_id_{course.id}", payload=timestamp, # reply_markup=UserGeneratorKeyboard.course_back_in_list(user) # start_parameter = f"lol-lel-cheburek", # payload = "test-payload-check" )
async def get_access_choose_channels_back(callback: types.CallbackQuery): """Возвращает пользователя обратно в выбор курса""" user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text(get_text(user, 'start'), reply_markup=await UserGeneratorKeyboard.start_button(user)) await UserStateMainMenu.main_menu.set()
async def start_menu_get_access(callback: types.CallbackQuery): """Отправляет меню с доступными курсами для того, чтобы пользователь мог вступить в них.""" await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) if (user.is_have_subscription == False): text = get_text(user, 'get_access_main_menu_no_courses') else: text = get_text(user, 'get_access_main_menu') keyboard = await UserGeneratorKeyboard.get_user_channels(user) await callback.message.edit_text(text=text, reply_markup=keyboard) await DataBaseFunc.delete_messages_from_callback( user, callback.message.message_id) await UserStateGetAccessCourse.choose_course.set()
async def managing_courses_edit(callback: types.CallbackQuery): """Обработка кнопки назад""" user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text( get_text(user, 'admin_menu_managing_courses'), reply_markup=AdminGenerateKeyboard.admin_menu_managing_courses(user)) await AdminStateMainMenu.managing_courses.set()
async def start_message(message: types.Message): """Обработчик команды /start.""" user = DataBaseFunc.get_user(message.from_user.id) if user != None: if (user.chat_id != message.chat.id): user.chat_id = message.chat.id DataBaseFunc.commit() await message.delete() if user == None: user = User(id=message.from_user.id, username=message.from_user.username, chat_id=message.chat.id, is_check_seven_days=False) DataBaseFunc.add(user) DataBaseFunc.commit() mess = await message.answer( get_text(user, 'register'), reply_markup=UserGeneratorKeyboard.register_button(user)) await DataBaseFunc.delete_messages(user) ms = Message(user_id=user.id, message_id=mess.message_id) DataBaseFunc.add(ms) await UserStateRegister.main_menu.set() elif user.is_register == False: if (user.chat_id == None): user.chat_id = message.chat.id mess = await message.answer( get_text(user, 'register'), reply_markup=UserGeneratorKeyboard.register_button(user)) await DataBaseFunc.delete_messages(user) ms = Message(user_id=user.id, message_id=mess.message_id) DataBaseFunc.add(ms) await UserStateRegister.main_menu.set() else: if (user.chat_id == None): user.chat_id = message.chat.id mess = await message.answer(get_text(user, 'start'), reply_markup=await UserGeneratorKeyboard.start_button(user)) await DataBaseFunc.delete_messages(user) ms = Message(user_id=user.id, message_id=mess.message_id) DataBaseFunc.add(ms) await UserStateMainMenu.main_menu.set()
async def managing_courses_add(callback: types.CallbackQuery, state: FSMContext): """Обрабатывает кнопку добавить курс. """ user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text(get_text(user, 'managing_courses_add')) await state.update_data(message_id=callback.message.message_id, chat_id=callback.message.chat.id) await AdminStateManagingCourses.add_course.set()
async def get_access_main_menu_back(callback: types.CallbackQuery): """Кнпка назад, возвращает пользователя в главное меню""" await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text(get_text(user, 'start'), reply_markup=await UserGeneratorKeyboard.start_button(user)) await UserStateMainMenu.main_menu.set()
async def managing_courses_delete(callback: types.CallbackQuery): """Обработка кнопки удалить""" await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) text = get_text(user, 'managing_courses_delete') keyboard = AdminGenerateKeyboard.managing_courses_delete(user) await callback.message.edit_text(text, reply_markup=keyboard) await AdminStateManaginCourseDelete.get_course.set()
async def register_write_back(callback: types.CallbackQuery): """Прекратить ввод номера или почты при регистрации.""" await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text( get_text(user, 'register'), reply_markup=UserGeneratorKeyboard.register_button(user)) await UserStateRegister.main_menu.set()
async def managing_admin_list_admins_back(callback: types.CallbackQuery): """Возвращает в главное меню управления администрации""" await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text( get_text(user, 'admin_menu_managing_admins'), reply_markup=AdminGenerateKeyboard.admin_menu_managing_admins(user)) await AdminStateManagingAdmin.main_menu.set()
async def managing_users_add_time_final_cancel(callback: types.CallbackQuery, state: FSMContext): await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text( get_text(user, 'admin_menu_managing_users'), reply_markup=AdminGenerateKeyboard.admin_menu_managing_users(user)) await AdminStateManagingUser.main_menu.set()
async def managing_users_add_course_back(callback: types.CallbackQuery): """Возвращает в меню выбора действий в управлении пользователями""" await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text( get_text(user, 'admin_menu_managing_users'), reply_markup=AdminGenerateKeyboard.admin_menu_managing_users(user)) await AdminStateManagingUser.main_menu.set()
async def managign_users_delete_time_back(callback: types.CallbackQuery): """Возвращает в главное меню управления пользователями""" await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text( get_text(user, 'admin_menu_managing_users'), reply_markup=AdminGenerateKeyboard.admin_menu_managing_users(user)) await AdminStateManagingUser.main_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 managing_courses_add_additionaly_cancel( callback: types.CallbackQuery, state: FSMContext): """Возвращает в менеджер управления подписками""" await state.reset_data() user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text( get_text(user, 'admin_menu_managing_courses'), reply_markup=AdminGenerateKeyboard.admin_menu_managing_courses(user)) await AdminStateMainMenu.managing_courses.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 managing_courses_edit_description(callback: types.CallbackQuery, state=FSMContext): """Обрабатывает кнопки редактировать описание при выбранном для редакта курсе""" await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) text = get_text(user, 'managing_courses_edit_access_add') await state.update_data(message_id=callback.message.message_id) await callback.message.edit_text(text) await AdminStateManaginCourseEdit.edit_access_add.set()
async def managing_admins_main_menu_add_admin_back( callback: types.CallbackQuery): """Кнопка назад из ввода имени для добавления администратора""" await callback.answer() user = DataBaseFunc.get_user(callback.from_user.id) await callback.message.edit_text( get_text(user, 'admin_menu_managing_admins'), reply_markup=AdminGenerateKeyboard.admin_menu_managing_admins(user)) await AdminStateManagingAdmin.main_menu.set()
def _get_document_parts(self, path): config = self.registered.pop(path) bg, textcolour = guiconfig.get_tooltip_colours() style = """ body { background-color: %s; color: %s } """ % (bg, textcolour) text = config.get_text() text = '<div class="tooltip_segment">%s</div>' % (text) bodyattrs = self._get_body_attrs(config.get_module(), overrides = {"columns": "false"} ) return dict(module=config.get_module(), content=text, stylesheets=self.bible_stylesheets, bodyattrs=bodyattrs, styles=style)