def handler_call(call): chat_id = call.message.chat.id message_id = call.message.message_id # Main menu if call.data == 'catalog': bot.edit_message_text( chat_id=chat_id, message_id=message_id, text='Каталог', reply_markup=func.menu_catalog() ) if call.data == 'exit_from_catalog': bot.edit_message_text( chat_id=chat_id, message_id=message_id, text='Вы вернулись назад', reply_markup=menu.main_menu ) if call.data in func.list_sections(): name = call.data product = func.Product(chat_id) product_dict[call.message.chat.id] = product product.section = name bot.edit_message_text( chat_id=chat_id, message_id=message_id, text=f'❕ Выберите нужный товар', reply_markup=func.menu_section(call.data) ) if call.data in func.list_product(): conn = sqlite3.connect("base_ts.sqlite") cursor = conn.cursor() cursor.execute(f'SELECT * FROM "{call.data}"') row = cursor.fetchall() if len(row) > 0: product = func.Product(chat_id) product_dict[chat_id] = product product = product_dict[chat_id] info = func.menu_product(call.data, product) product.product = info[1].product product.section = info[1].section product.amount_MAX = info[1].amount_MAX product.price = info[1].price bot.edit_message_text( chat_id=chat_id, message_id=message_id, text=info[0], reply_markup=menu.btn_purchase ) if len(row) == 0: bot.edit_message_text( chat_id=chat_id, message_id=message_id, text='Товар закончился, напишите в тех. поддержку', reply_markup=menu.main_menu ) if call.data == 'buy': product = product_dict[chat_id] msg = bot.send_message(chat_id=chat_id, text=f'❕ Введите кол-во товара\n❕ От 1 - {product.amount_MAX}') bot.register_next_step_handler(msg, buy) if call.data == 'info': bot.edit_message_text( chat_id=chat_id, message_id=message_id, text=settings.info, reply_markup=menu.main_menu ) if call.data == 'purchases': msg = func.basket(chat_id) if len(msg) > 0: bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=msg, reply_markup=menu.main_menu) if len(msg) == 0: bot.edit_message_text(chat_id=chat_id, message_id=message_id, text='У вас нет покупок 😢', reply_markup=menu.main_menu) if call.data == 'exit_to_menu': bot.edit_message_text( chat_id=chat_id, message_id=message_id, text='Вы вернулись в главное меню', reply_markup=menu.main_menu ) if call.data == 'btn_ok': bot.delete_message(chat_id, message_id) if call.data == 'profile': info = func.profile(chat_id) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=settings.profile.format( id=info[0], login=f'@{info[1]}', data=info[2][:19], balance=info[5] ), reply_markup=menu.main_menu) # Admin menu if call.data == 'admin_info': bot.edit_message_text( chat_id=chat_id, message_id=message_id, text=func.admin_info(), reply_markup=menu.admin_menu ) if call.data == 'add_section_to_catalog': if chat_id == settings.admin_id: msg = bot.send_message(chat_id=chat_id, text='Введите название раздела') bot.register_next_step_handler(msg, create_section) if call.data == 'del_section_to_catalog': if chat_id == settings.admin_id: conn = sqlite3.connect("base_ts.sqlite") cursor = conn.cursor() cursor.execute('SELECT * FROM catalog') row = cursor.fetchall() cursor.close() conn.close() text = '' num = 0 for i in row: text = text + '№ ' + str(num) + ' | ' + str(i[0]) + '\n' num += 1 msg = bot.send_message( chat_id=chat_id, text='Введите номер раздела\n\n' f'{text}' ) bot.register_next_step_handler(msg, del_section) if call.data == 'add_product_to_section': if chat_id == settings.admin_id: conn = sqlite3.connect("base_ts.sqlite") cursor = conn.cursor() cursor.execute('SELECT * FROM catalog') row = cursor.fetchall() text = '' num = 0 for i in row: text = text + '№ ' + str(num) + ' | ' + str(i[0]) + '\n' num += 1 msg = bot.send_message(chat_id=chat_id, text='Введите номер раздела в которы вы хотите добавить товар\n\n' f'{text}') bot.register_next_step_handler(msg, create_product) if call.data == 'del_product_to_section': if chat_id == settings.admin_id: conn = sqlite3.connect("base_ts.sqlite") cursor = conn.cursor() cursor.execute('SELECT * FROM catalog') row = cursor.fetchall() text = '' num = 0 for i in row: text = text + '№ ' + str(num) + ' | ' + str(i[0]) + '\n' num += 1 msg = bot.send_message(chat_id=chat_id, text='Введите номер раздела из которого вы хотите удалить товар\n\n' f'{text}') bot.register_next_step_handler(msg, del_product) if call.data == 'download_product': conn = sqlite3.connect("base_ts.sqlite") cursor = conn.cursor() cursor.execute('SELECT * FROM catalog') row = cursor.fetchall() text = '' num = 0 for i in row: text = text + '№ ' + str(num) + ' | ' + str(i[0]) + '\n' num += 1 msg = bot.send_message(chat_id=chat_id, text='Введите номер раздела\n\n' f'{text}') bot.register_next_step_handler(msg, download_product) if call.data == 'exit_admin_menu': bot.edit_message_text( chat_id=chat_id, message_id=message_id, text='Вы покинули меню админа', reply_markup=menu.main_menu ) if call.data == 'back_to_admin_menu': bot.edit_message_text( chat_id=chat_id, message_id=message_id, text='Вы перешли в меню админа', reply_markup=menu.admin_menu ) if call.data == 'catalog_control': bot.edit_message_text( chat_id=chat_id, message_id=message_id, text='Вы перешли в управление каталогом', reply_markup=menu.admin_menu_control_catalog ) if call.data == 'section_control': bot.edit_message_text( chat_id=chat_id, message_id=message_id, text='Вы перешли в управление разделами', reply_markup=menu.admin_menu_control_section ) if call.data == 'replenish_balance': bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=func.replenish_balance(chat_id), reply_markup=menu.replenish_balance) if call.data == 'cancel_payment': func.cancel_payment(chat_id) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text='❕ Добро пожаловать!', reply_markup=menu.main_menu) if call.data == 'check_payment': check = func.check_payment(chat_id) if check[0] == 1: bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=f'✅ Оплата прошла\nСумма - {check[1]} руб', reply_markup=menu.main_menu) bot.send_message(chat_id=settings.admin_id, text='💰 Пополнение баланса\n' f'🔥 От - {chat_id}\n' f'🔥 Сумма - {check[1]} руб') try: bot.send_message(chat_id=f'-100{settings.CHANNEL_ID}', text='💰 Пополнение баланса\n' f'🔥 От - {chat_id}\n' f'🔥 Сумма - {check[1]} руб') except: pass if check[0] == 0: bot.send_message(chat_id=chat_id, text='❌ Оплата не найдена', reply_markup=menu.to_close) if call.data == 'to_close': bot.delete_message(chat_id=chat_id, message_id=message_id) if call.data == 'give_balance': msg = bot.send_message(chat_id=chat_id, text='Введите логин человека, которому будет изменён баланс') bot.register_next_step_handler(msg, give_balance) if call.data == 'admin_sending_messages': msg = bot.send_message(chat_id, text='Введите текст рассылки') bot.register_next_step_handler(msg, admin_sending_messages)
def handler_call(call): chat_id = call.message.chat.id message_id = call.message.message_id # Main menu if call.data == 'edit_price': msg = bot.send_message( chat_id=chat_id, text=f'Выберите каталог:\n{func.edit_price_list_c()}') bot.register_next_step_handler(msg, edit_price) if '🇷🇺' in call.data or '🇺🇦' in call.data or '🇰🇿' in call.data: bot.edit_message_text( chat_id=chat_id, message_id=message_id, text=f'Добро пожаловать в меню, вы выбрали город {call.data}', reply_markup=menu.main_menu) if call.data in 'ruuakz': bot.edit_message_text(chat_id=chat_id, message_id=message_id, text='Выберите город', reply_markup=func.cities(call.data)) if call.data == 'catalog': bot.edit_message_text(chat_id=chat_id, message_id=message_id, text='Каталог', reply_markup=func.menu_catalog()) if call.data == 'exit_from_catalog': bot.edit_message_text(chat_id=chat_id, message_id=message_id, text='Вы вернулись назад', reply_markup=menu.main_menu) if call.data == 'admin_address': bot.send_message(chat_id=chat_id, text=func.admin_address(), reply_markup=menu.to_close) if call.data in func.list_sections(): name = call.data product = func.Product(chat_id) product_dict[call.message.chat.id] = product product.section = name bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=f'❕ Выберите нужный товар', reply_markup=func.menu_section(call.data)) if call.data in func.list_product(): product = func.Product(chat_id) product_dict[chat_id] = product product = product_dict[chat_id] info = func.menu_product(call.data, product) product.product = info[1].product product.section = info[1].section product.amount_MAX = info[1].amount_MAX product.price = info[1].price bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=info[0], reply_markup=menu.btn_purchase) try: if call.data == 'buy': product = product_dict[chat_id] msg = bot.send_message( chat_id=chat_id, text=f'❕ Введите кол-во товара\n❕ От 1 - 15') bot.register_next_step_handler(msg, buy) except: pass try: if call.data == 'info': bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=settings.info, reply_markup=menu.main_menu) except: pass if call.data == 'exit_to_menu': bot.edit_message_text(chat_id=chat_id, message_id=message_id, text='Вы вернулись в главное меню', reply_markup=menu.main_menu) if call.data == 'btn_ok': bot.delete_message(chat_id, message_id) try: if call.data == 'profile': info = func.profile(chat_id) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=settings.profile.format( id=info[0], login=f'@{info[1]}', data=info[2][:19], balance=info[5]), reply_markup=menu.main_menu) except: pass # Admin menu try: if call.data == 'admin_info': bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=func.admin_info(), reply_markup=menu.admin_menu) except: pass if call.data == 'add_section_to_catalog': if chat_id == settings.admin_id: msg = bot.send_message(chat_id=chat_id, text='Введите название раздела') bot.register_next_step_handler(msg, create_section) if call.data == 'del_section_to_catalog': if chat_id == settings.admin_id: conn = sqlite3.connect("base_ts.sqlite") cursor = conn.cursor() cursor.execute('SELECT * FROM catalog') row = cursor.fetchall() cursor.close() conn.close() text = '' num = 0 for i in row: text = text + '№ ' + str(num) + ' | ' + str(i[0]) + '\n' num += 1 msg = bot.send_message(chat_id=chat_id, text='Введите номер раздела\n\n' f'{text}') bot.register_next_step_handler(msg, del_section) if call.data == 'add_product_to_section': if chat_id == settings.admin_id: conn = sqlite3.connect("base_ts.sqlite") cursor = conn.cursor() cursor.execute('SELECT * FROM catalog') row = cursor.fetchall() text = '' num = 0 for i in row: text = text + '№ ' + str(num) + ' | ' + str(i[0]) + '\n' num += 1 msg = bot.send_message( chat_id=chat_id, text= 'Введите номер раздела в которы вы хотите добавить товар\n\n' f'{text}') bot.register_next_step_handler(msg, create_product) if call.data == 'del_product_to_section': if chat_id == settings.admin_id: conn = sqlite3.connect("base_ts.sqlite") cursor = conn.cursor() cursor.execute('SELECT * FROM catalog') row = cursor.fetchall() text = '' num = 0 for i in row: text = text + '№ ' + str(num) + ' | ' + str(i[0]) + '\n' num += 1 msg = bot.send_message( chat_id=chat_id, text= 'Введите номер раздела из которого вы хотите удалить товар\n\n' f'{text}') bot.register_next_step_handler(msg, del_product) if call.data == 'download_product': conn = sqlite3.connect("base_ts.sqlite") cursor = conn.cursor() cursor.execute('SELECT * FROM catalog') row = cursor.fetchall() text = '' num = 0 for i in row: text = text + '№ ' + str(num) + ' | ' + str(i[0]) + '\n' num += 1 msg = bot.send_message(chat_id=chat_id, text='Введите номер раздела\n\n' f'{text}') bot.register_next_step_handler(msg, download_product) if call.data == 'exit_admin_menu': bot.edit_message_text(chat_id=chat_id, message_id=message_id, text='Вы покинули меню админа', reply_markup=menu.main_menu) if call.data == 'back_to_admin_menu': bot.edit_message_text(chat_id=chat_id, message_id=message_id, text='Вы перешли в меню админа', reply_markup=menu.admin_menu) if call.data == 'catalog_control': bot.edit_message_text(chat_id=chat_id, message_id=message_id, text='Вы перешли в управление каталогом', reply_markup=menu.admin_menu_control_catalog) if call.data == 'section_control': bot.edit_message_text(chat_id=chat_id, message_id=message_id, text='Вы перешли в управление разделами', reply_markup=menu.admin_menu_control_section) if call.data == 'replenish_balance': bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=func.replenish_balance(chat_id), reply_markup=menu.replenish_balance) if call.data == 'cancel_payment': func.cancel_payment(chat_id) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text='❕ Добро пожаловать!', reply_markup=menu.main_menu) if call.data == 'check_payment': check = func.check_payment(chat_id) if check[0] == 1: bot.edit_message_text( chat_id=chat_id, message_id=message_id, text=f'✅ Оплата прошла\nСумма - {check[1]} тенге', reply_markup=menu.main_menu) bot.send_message( chat_id=settings.admin_id, text='💰 Пополнение баланса\n' f'🔥 От - {chat_id}/{call.message.from_user.username}/{call.message.from_user.first_name}\n' f'🔥 Сумма - {check[1]} тенге') try: bot.send_message( chat_id=f'-100{settings.CHANNEL_ID}', text='💰 Пополнение баланса\n' f'🔥 Бот пренадлежит - {settings.LOGIN_ADMIN}' f'🔥 От - {chat_id}/{call.message.from_user.username}/{call.message.from_user.first_name}\n' f'🔥 Сумма - {check[1]} тенге') except: pass if check[0] == 0: bot.send_message(chat_id=chat_id, text='❌ Оплата не найдена', reply_markup=menu.to_close) if call.data == 'to_close': bot.delete_message(chat_id=chat_id, message_id=message_id) if call.data == 'give_balance': msg = bot.send_message( chat_id=chat_id, text='Введите id человека, которому будет изменён баланс') bot.register_next_step_handler(msg, give_balance) if call.data == 'admin_sending_messages': msg = bot.send_message(chat_id, text='Введите текст рассылки') bot.register_next_step_handler(msg, admin_sending_messages)