def next_state(user: User, message: Message): if user.state == User.STATE_ADD_START: user.new_place = InterestPlace() bot.send_message(chat_id=message.chat.id, text="Назови место", reply_markup=standard_keyboard_force_reply()) user.state = User.STATE_ADD_NAME elif user.state == User.STATE_ADD_NAME: if message.content_type == 'text': user.new_place.name = message.text bot.send_message(chat_id=message.chat.id, text="Укажи геопозицию (адрес или GPS-метку)", reply_markup=standard_keyboard_force_reply()) user.state = User.STATE_ADD_LOCATION else: bot.send_message(chat_id=message.chat.id, text="Назови место", reply_markup=standard_keyboard_force_reply()) elif user.state == User.STATE_ADD_LOCATION: if message.content_type == 'location': geocode = Map.geocode_from_location( (message.location.latitude, message.location.longitude)) user.new_place.address = geocode.get('address') user.new_place.location = geocode.get('location') bot.send_message(chat_id=message.chat.id, text="Добавь фото", reply_markup=standard_keyboard_force_reply()) user.state = User.STATE_ADD_PHOTO elif message.content_type == 'text': geocode = Map.geocode_from_address(message.text) user.new_place.address = geocode.get('address') user.new_place.location = geocode.get('location') bot.send_message(chat_id=message.chat.id, text="Добавь фото", reply_markup=standard_keyboard_force_reply()) user.state = User.STATE_ADD_PHOTO else: bot.send_message(chat_id=message.chat.id, text="Укажи геопозицию (адрес или GPS-метку)", reply_markup=standard_keyboard_force_reply()) elif user.state == User.STATE_ADD_PHOTO: if message.content_type == 'photo': file_id = message.photo[-1].file_id file_info = bot.get_file(file_id) user.new_place.photo = bot.download_file(file_info.file_path) bot.send_message( chat_id=message.chat.id, text=f"Сохранить место \"{user.new_place.name}\" (да/нет)?", reply_markup=decision_keyboard()) user.state = User.STATE_ADD_SAVE else: bot.send_message(chat_id=message.chat.id, text="Добавь фото", reply_markup=standard_keyboard_force_reply()) elif user.state == User.STATE_ADD_SAVE: if message.content_type == 'text': if "да" in message.text.lower(): user.save_new_place() bot.send_message( chat_id=message.chat.id, text=f"Место \"{user.new_place.name}\" сохранено.", reply_markup=command_keyboard()) user.state = User.STATE_IDLE elif "нет" in message.text.lower(): bot.send_message( chat_id=message.chat.id, text=f"Место \"{user.new_place.name}\" не сохранено.", reply_markup=command_keyboard()) user.state = User.STATE_IDLE else: bot.send_message( chat_id=message.chat.id, text=f"Сохранить место \"{user.new_place.name}\" (да/нет)?", reply_markup=decision_keyboard()) else: bot.send_message( chat_id=message.chat.id, text=f"Сохранить место \"{user.new_place.name}\" (да/нет)?", reply_markup=decision_keyboard()) elif user.state == User.STATE_RESET_START: bot.send_message(chat_id=message.chat.id, text="Удалить список интересных мест (да/нет)?", reply_markup=decision_keyboard()) user.state = User.STATE_RESET_DO elif user.state == User.STATE_RESET_DO: if message.content_type == 'text': if "да" in message.text.lower(): InterestPlace.reset(user) bot.send_message(chat_id=message.chat.id, text="Список интересных мест удален", reply_markup=command_keyboard()) user.state = User.STATE_IDLE elif "нет" in message.text.lower(): bot.send_message(chat_id=message.chat.id, text="Список интересных мест не удален", reply_markup=command_keyboard()) user.state = User.STATE_IDLE else: bot.send_message( chat_id=message.chat.id, text=f"Сохранить место \"{user.new_place.name}\" (да/нет)?", reply_markup=decision_keyboard()) else: bot.send_message(chat_id=message.chat.id, text="Удалить список интересных мест (да/нет)?", reply_markup=decision_keyboard()) else: bot.send_message(chat_id=message.chat.id, text=""" Ты можешь использвать следующие команды для управления: /start - начать диалог /help - вывести справку /add - добавить новое место /list - отобразить добавленные места /reset - удалить все добавленные места /echo - эхо""", reply_markup=command_keyboard()) user.save()