def apply_pass(message): if functions.get_value_from_users(message, 'STATUS') == 'Waiting_for_passport': if functions.get_value_from_users(message, 'PASS_FILE') == '(None,)' or \ functions.get_dif_of_time(functions.get_value_from_users(message, 'PASS_FILE').split('_')[1], datetime.datetime.now()) > 24: file_id = message.photo[-1].file_id file_info = bot.get_file(file_id) downloaded_file = bot.download_file(file_info.file_path) file_name = str(message.from_user.id) + '_' + str( datetime.datetime.now()) functions.set_value(message.from_user.id, 'PASS_FILE', file_name) with open('users/' + file_name, 'wb') as new_file: new_file.write(downloaded_file) functions.send_photo_to_admin(file_name, message, bot) bot.send_message(message.chat.id, phrases.pass_photo_received) else: estimated_time = 24 - functions.get_dif_of_time( functions.get_value_from_users(message, 'PASS_FILE').split('_')[1], datetime.datetime.now()) bot.send_message( message.chat.id, phrases.wrong_time_of_photo + str(estimated_time) + ' часа')
def enter_point(message): try: task_id = int(functions.get_value_from_users(message, 'Status')) lat, lon = message.location.latitude, message.location.longitude conn = sqlite3.connect('users.db') cursor = conn.cursor() query = 'UPDATE tasks SET Home_lat=? WHERE id=?' value = [lat, task_id] cursor.execute(query, value) conn.commit() query = 'UPDATE tasks SET Home_long=? WHERE id=?' value = [lon, task_id] cursor.execute(query, value) conn.commit() conn.close() bot.send_message( message.chat.id, 'Сколько будет стоить набор товаров? Не волнуйтесь, если будет неточно, ' 'разница вернётся') bot.register_next_step_handler(message, set_price_for_goods) except Exception as e: if message.text == 'Отменить': bot.send_message(message.chat.id, 'Ладно, как знаешь') else: bot.send_message(message.chat.id, phrases.wrong_location) bot.register_next_step_handler(message, enter_point)
def set_price_for_delivery(message): price = message.text try: task_id = int(functions.get_value_from_users(message, 'Status')) price = int(price) conn = sqlite3.connect('users.db') cursor = conn.cursor() query = 'UPDATE tasks SET Price_for_delivery=? WHERE id=?' value = [price, task_id] cursor.execute(query, value) conn.commit() conn.close() order_text = 'Ваш заказ размещён, деньги зарезервированы, как только курьер примет заказ, ' \ 'мы Вам сообщим.\n' desc = functions.get_value_from_tasks(task_id, 'Description') goods_price = functions.get_number_from_tasks( task_id, 'Price_for_goods') order_text += 'Номер заказа: ' + str(task_id) + '\n' order_text += 'Описание: ' + desc + '\n' order_text += 'Цена товаров: ' + goods_price + '\n' order_text += 'Цена доставки: ' + str(price) + '.0' + '\n' order_text += 'Узнать баланс: /balance' bot.send_message(message.chat.id, order_text) if not functions.success_of_money_reservation(task_id): conn = sqlite3.connect('users.db') cursor = conn.cursor() cursor.execute('DELETE FROM tasks WHERE id=?', [task_id]) conn.commit() conn.close() bot.send_message( message.chat.id, 'Кажется, у тебя не хватает денег. Узнать свой баланс можно по ' 'команде /balance') else: functions.send_task_to_couriers(bot, task_id) except Exception as e: print(e) if message.text == 'Отменить': bot.send_message(message.chat.id, 'Ладно, как знаешь') else: bot.send_message(message.chat.id, phrases.not_number) bot.register_next_step_handler(message, set_price_for_delivery)
def set_price_for_goods(message): price = message.text try: task_id = int(functions.get_value_from_users(message, 'Status')) price = float(price) conn = sqlite3.connect('users.db') cursor = conn.cursor() query = 'UPDATE tasks SET Price_for_goods=? WHERE id=?' value = [price, task_id] cursor.execute(query, value) conn.commit() bot.register_next_step_handler(message, set_price_for_delivery) bot.send_message(message.chat.id, 'Сколько ты готов заплатить за доставку?') except Exception as e: if message.text == 'Отменить': bot.send_message(message.chat.id, 'Ладно, как знаешь') else: bot.send_message(message.chat.id, phrases.not_number) bot.register_next_step_handler(message, set_price_for_goods)
row = str(row) if row != '(None,)' and row != 'None': row = row[1:len(row) - 2] conn.close() bot.send_message(message.chat.id, row) @bot.message_handler(commands=['help']) def get_help(message): bot.send_message(message.chat.id, phrases.get_help) @bot.message_handler(func=lambda message: not (functions.does_user_exist( str(message.from_user.id)))) def reg_for_user(message): bot.send_message(message.chat.id, phrases.unknown_user) @bot.message_handler(func=lambda message: functions.get_value_from_users( message, 'status') == 'Waiting_for_name') def waiting_for_pass(message): functions.set_value(message.from_user.id, 'Name', message.text) functions.set_value(message.from_user.id, 'STATUS', 'Waiting_for_surname') bot.send_message(message.chat.id, phrases.name_completed) @bot.message_handler(func=lambda message: functions.get_value_from_users( message, 'status') == 'Waiting_for_surname') def waiting_for_pass(message): functions.set_value(message.from_user.id, 'Surname', message.text) functions.set_value(message.from_user.id, 'STATUS', 'Waiting_for_age') bot.send_message(message.chat.id, phrases.surname_completed) @bot.message_handler(func=lambda message: functions.get_value_from_users( message, 'status') == 'Waiting_for_age')