def send_exchange_rates(message): city = get_hash_city(message.chat.id) # Берем город по id пользователя if city != "error": curr_weather = weather.make_report_overall(weather. getTodayWeatherOverall(str(city))) bot.send_message(message.chat.id, "Погода на сегодня:\n" + str(curr_weather)) else: set_state(message.chat.id, "2") # Перевод пользователя в статус 2 - необходимо указать город bot.send_message(message.chat.id, 'Не указан город. Пройдите регистрацию /start')
def send_time_now(message): user_timezone = get_hash_timezone(message.chat.id) if user_timezone != "error": currDTime = datetime.datetime.fromtimestamp(message.date) curr_user_time = get_time_from_another_timezone(currDTime,int(user_timezone)) bot.send_message(message.chat.id, 'Сегодня {:%d %b %Y, %H:%M } '.format(curr_user_time)) else: set_state(message.chat.id, "1") bot.send_message(message.chat.id, 'Не указан часовой пояс. Пройдите регистрацию /start')
def set_timezone(message): msg = message.text if msg.isdigit(): if inRange(int(msg),-11,12): bot.send_message(message.chat.id, "Теперь укажите ближайший город.") set_hash_timezone(message.chat.id,msg) set_state(message.chat.id, config.States.S_ENTER_CITY.value) else: bot.send_message(message.chat.id, "Что-то не так, попробуй ещё раз!") else: bot.send_message(message.chat.id, "Что-то не так, попробуй ещё раз!")
def send_welcome(message): userId = message.from_user.id # id пользователя в telegram firstName = message.from_user.first_name # Имя пользователя userName = message.from_user.username # Имя, отображающееся в telegram lastName = message.from_user.last_name # Фамилия пользователя botName = bot.get_me().first_name # Берем имя бота bot.send_message(message.chat.id, str(userName) + ", Приветствую! Меня зовут " + str(botName) + ". Чем я могу тебе помочь?") db = SQL_Postgre() if db.check_user_id(message.chat.id) == False: db.new_user(userId, firstName, userName, lastName) db.close() curr_state = get_current_state(message.chat.id) if curr_state == config.States.S_CHECKINOK.value: pass if curr_state == config.States.S_START.value: # Первый вход bot.send_message(message.chat.id, "Похоже, вы у нас в первый раз. Ну ничего страшного, для начала мне понадобятся некоторые данные." ) set_state(message.chat.id, config.States.S_ENTER_TIMEZONE.value) setUTC(message) return elif curr_state == config.States.S_ENTER_TIMEZONE.value: setUTC(message) return elif curr_state == config.States.S_ENTER_CITY.value: set_city(message) bot.send_message(message.chat.id, userName + "Чтобы общаться со мной, введите команду /miass") # После ввода последней настройки вызываем для иництализации get_current_position(message.chat.id) return # После регистрации клиента в системе выводим первое приветсвие bot.send_message(message.chat.id, "/miass - твоя персональная помощница\n" "/settings - мои настройки\n" "/reset_settings - сбросить настройки ") """
def set_city(message): msg = message.text # !!! Тут нужно сделать проверку город с помощью регулярного выражения!!! list_city = ['Москва','москва','Moscow','moscow'] if str(msg) in list_city: check = True else: check = False #db = SQL_Postgre() #check = db.check_city(str(msg)) #db.close() if check == True: bot.send_message(message.chat.id, "Отлично! Я к твоим услугам. Чтобы общаться со мной, введи команду /miass") db = SQL_Postgre() set_hash_city(message.chat.id,'Moscow') utc = get_hash_timezone(message.chat.id) db.update_user(message.chat.id, utc, 'Moscow') db.close() set_state(message.chat.id, config.States.S_CHECKINOK.value) # Теперь переводим в статус зарегестрированного else: bot.send_message(message.chat.id, "Похоже твоего города нет в списке. Введи Москва (Я пока в бета-версии) :)")
def reset_settings(message): bot.send_message(message.chat.id, "Сбрасываю настройки.") set_state(message.chat.id, config.States.S_ENTER_TIMEZONE.value) setUTC(message)