def feedback_response(message): if message.text in ['❌ Отмена', '❌ Cancel']: text = 'Хорошо' if message.text == '❌ Отмена' else 'Ok' bot.send_message(message.chat.id, text, reply_markup=markups.get_main_menu_markup( message.chat.id), parse_mode='Markdown') else: feedback = f'id: {message.chat.id}\n' \ f'Пользователь: {message.from_user.username}\n' \ f'Имя: {message.from_user.first_name}\n' \ f'Фамилия: {message.from_user.last_name}\n' \ f'Язык: {message.from_user.language_code}\n\n' \ f'Сообщение: *{message.text}*' bot.send_message(settings.ADMIN_ID, feedback, parse_mode='Markdown') user = User.get(message.chat.id) ru_text = 'Твоё обращение уже на столе у начальника😉' en_text = "Your appeal is already on the boss's desk😉" text = ru_text if user.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, reply_markup=markups.get_main_menu_markup( message.chat.id), parse_mode='Markdown')
def settings_type_recieve(message): if message.text == '🇷🇺 Язык': bot.send_message(message.chat.id, 'Выбери язык', reply_markup=markups.get_languages_markup()) bot.register_next_step_handler(message, language_receive) elif message.text == '🇬🇧 Language': bot.send_message(message.chat.id, 'Choose the language', reply_markup=markups.get_languages_markup()) bot.register_next_step_handler(message, language_receive) elif message.text == '🕒 Часовой пояс': bot.send_message( message.chat.id, "Можно задать часовой пояс вручную или просто поделиться местоположением.", reply_markup=markups.get_location_markup(message.chat.id)) bot.register_next_step_handler(message, location_receive) elif message.text == '🕒 Timezone': bot.send_message( message.chat.id, "You can specify timezone manually or just share location.", reply_markup=markups.get_location_markup(message.chat.id)) bot.register_next_step_handler(message, location_receive) else: # Отмена bot.send_message(message.chat.id, message.text, reply_markup=markups.get_main_menu_markup( message.chat.id))
def location_receive(message): if message.location: tzw = tzwhere.tzwhere() timezone_str = tzw.tzNameAt(message.location.latitude, message.location.longitude) user = User.get(message.chat.id) user.timezone = timezone_str user.save() ru_text = f'Часовой пояс изменён на *{timezone_str}*' en_text = f'Timezone changed to *{timezone_str}*' text = ru_text if user.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, reply_markup=markups.get_main_menu_markup( message.chat.id), parse_mode='Markdown') elif message.text == 'Указать вручную': bot.send_message(message.chat.id, 'Выбери свой часовой пояс', reply_markup=markups.get_timezone_markup()) bot.register_next_step_handler(message, timezone_receive) elif message.text == 'Specify manually': bot.send_message(message.chat.id, 'Choose your timezone', reply_markup=markups.get_timezone_markup()) bot.register_next_step_handler(message, timezone_receive) else: bot.register_next_step_handler(message, location_receive)
def user_violations(message): user = User.get(message.chat.id) violations = user.get_fines() if len(violations) == 0: ru_report = 'Ты чист как слеза: ни одного нарушения.' en_report = "You are clean as a whistle: there are not any violations." report = ru_report if user.language_code == 'ru' else en_report markup = user_markups.get_main_menu_markup(message.chat.id) else: ru_report = 'Ты обвиняешься в следующих нарушениях:\n\n' en_report = 'You are charged with the following violations:\n\n' report = ru_report if user.language_code == 'ru' else en_report for violation in violations: label = violation[0] datetime_native = violation[1] fine = violation[2] report += f'_{datetime_native}_ {label} *${fine}*\n\n' report += 'Выбери наказание' if user.language_code == 'ru' else 'Choose punishment' markup = markups.get_punishment_markup(message.chat.id) bot.send_message(message.chat.id, text=report, parse_mode='Markdown', reply_markup=markup)
def money_intention(message): user = User.get(message.chat.id) ru_text = '80% пойдут детишкам на интернет: https://giveinternet.org/\n\n' \ 'Остальное я потрачу на кофе с булочками😊' en_text = '80% of money I will donate on Internet access to ' \ 'underprivileged high-school students: https://giveinternet.org/\n\n' \ "I'll spend the rest on coffee with buns😊" text = ru_text if user.language_code == 'ru' else en_text try: bot.send_message(message.chat.id, text=text, parse_mode='Markdown', reply_markup=user_markups.get_main_menu_markup( message.chat.id)) except: pass
def language_receive(message): print(message) print(message.text) user = User.get(message.chat.id) if message.text in ('🇷🇺Русский', '🇬🇧English'): # set user language user.language_code = 'ru' if message.text == '🇷🇺Русский' else 'en' user.save() ru_text = 'Язык изменён на *русский*' en_text = 'Language changed to *English*' text = ru_text if user.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, reply_markup=markups.get_main_menu_markup( message.chat.id), parse_mode='Markdown') else: bot.register_next_step_handler(message, language_receive)
def timezone_receive(message): user = User.get(message.chat.id) tz = 'Etc/' + message.text tz = tz.replace('-', '+') if '-' in tz else tz.replace('+', '-') if tz in pytz.all_timezones: user.timezone = tz user.save() ru_text = f'Часовой пояс изменён на *{message.text}*' en_text = f'Timezone changed to *{message.text}*' text = ru_text if user.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, reply_markup=markups.get_main_menu_markup( message.chat.id), parse_mode='Markdown') else: ru_text = 'Ты отправил что-то не то' en_text = 'You sent something wrong' text = ru_text if user.language_code == 'ru' else en_text bot.send_message(message.chat.id, text) bot.register_next_step_handler(message, timezone_receive)
def promise_receive(message): user = User.get(message.chat.id) # Назначаем привычку habit = Habit(message.chat.id, preparing_habits[message.chat.id]['label'], preparing_habits[message.chat.id]['days_of_week'], preparing_habits[message.chat.id]['time_array'], preparing_habits[message.chat.id]['fine']).save() # Снимаем штрафы с пригласившего if user.referrer: referrer = User.get(user.referrer) referrer.satisfy_fines(CheckStatus.WORKED.name) ru_text_ref = f'{get_user_naming(user, "Твой друг")} ' \ f'назначил свою первую привычку. ' \ f'За успешно проведённые социальные работы ' \ f'с тебя снимаются все обвинения и твои штрафы аннулируются.' en_text_ref = f'{get_user_naming(user, "Your friend")} ' \ f'has assigned his first habit. ' \ f'For successful social work all charges ' \ f'against you and your fines are canceled.' text_ref = ru_text_ref if referrer.language_code == 'ru' else en_text_ref bot.send_message(referrer.id, text_ref) if preparing_habits[message.chat.id]['with_judge']: ru_text = 'Осталось назначить судью. Просто отправь другу сообщение ниже👇' en_text = 'It remains to assign the judge. Just send the message below to a friend👇' text = ru_text if user.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, reply_markup=types.ReplyKeyboardRemove()) ru_days = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'] en_days = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'] days = ru_days if user.language_code == 'ru' else en_days check_days = re.sub( r'\s+', ' ', ' '.join([ day if day_of_week in preparing_habits[message.chat.id]['days_of_week'] else '' for day_of_week, day in enumerate(days) ])) check_time = ' '.join(preparing_habits[message.chat.id]['time_array']) ru_text = f'{get_user_naming(user, "Твой друг")} хочет, ' \ f'чтобы ты стал его судьёй на привычке *{habit.label}*.\n\n' \ f'Дни недели: *{check_days}*\n' \ f'Время проверки: *{check_time}*\n' \ f'Длительность: *3 недели*\n\n' \ f'За каждый провал {get_user_naming(user, "твой друг")} обязуется заплатить тебе *${habit.fine}*' en_text = f'{get_user_naming(user, "Your friend")} wants you ' \ f'to be the judge on the habit *{habit.label}*.\n\n' \ f'Days of week: *{check_days}*\n' \ f'Checks time: *{check_time}*\n' \ f'Duration: *3 weeks*\n\n' \ f'For each fail {get_user_naming(user, "your friend")} agrees to pay you *${habit.fine}*' text = ru_text if user.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, reply_markup=markups.get_judge_markup( user.id, habit.id), parse_mode='Markdown') else: schedule_native, schedule_utc = get_schedule( preparing_habits[message.chat.id]['days_of_week'], preparing_habits[message.chat.id]['time_array'], User.get(message.chat.id).timezone, ) for check_native, check_utc in zip( schedule_native, schedule_utc): # нужно оптимизировать Check(habit.id, check_native, check_utc).save() del preparing_habits[message.chat.id] ru_text = 'Ну что ж, посмотрим, какой ты крутой. Удачи!' en_text = "Well, let's see how cool you are. Good luck!" text = ru_text if user.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, reply_markup=markups.get_main_menu_markup( message.chat.id)) bot.send_sticker(message.chat.id, 'CAADAgADWQIAAsY4fgsQX6OJTX_IOgI')
def promise_receive(message): user = User.get(message.chat.id) habit = Habit(message.chat.id, preparing_habits[message.chat.id]['label'], preparing_habits[message.chat.id]['days_of_week'], preparing_habits[message.chat.id]['time_array'], preparing_habits[message.chat.id]['fine']).save() if preparing_habits[message.chat.id]['with_judge']: ru_text = 'Осталось назначить судью. Просто отправь другу сообщение ниже👇' en_text = 'It remains to assign the judge. Just send the message below to a friend👇' text = ru_text if user.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, reply_markup=types.ReplyKeyboardRemove()) ru_days = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'] en_days = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'] days = ru_days if user.language_code == 'ru' else en_days check_days = re.sub( r'\s+', ' ', ' '.join([ day if day_of_week in preparing_habits[message.chat.id]['days_of_week'] else '' for day_of_week, day in enumerate(days) ])) check_time = ' '.join(preparing_habits[message.chat.id]['time_array']) ru_text = f'{get_user_naming(user, "Твой друг")} хочет, ' \ f'чтобы ты стал его судьёй на привычке *{habit.label}*.\n\n' \ f'Дни недели: *{check_days}*\n' \ f'Время проверки: *{check_time}*\n' \ f'Длительность: *3 недели*\n\n' \ f'За каждый провал {get_user_naming(user, "твой друг")} обязуется заплатить тебе *${habit.fine}*' en_text = f'{get_user_naming(user, "Your friend")} wants you ' \ f'to be the judge on the habit *{habit.label}*.\n\n' \ f'Days of week: *{check_days}*\n' \ f'Checks time: *{check_time}*\n' \ f'Duration: *3 weeks*\n\n' \ f'For each fail {get_user_naming(user, "your friend")} agrees to pay you *${habit.fine}*' text = ru_text if user.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, reply_markup=markups.get_judge_markup( user.id, habit.id), parse_mode='Markdown') else: ru_text = 'Ну что ж, посмотрим, какой ты крутой. Удачи!' en_text = "Well, let's see how cool you are. Good luck!" text = ru_text if user.language_code == 'ru' else en_text schedule_native, schedule_utc = get_schedule( preparing_habits[message.chat.id]['days_of_week'], preparing_habits[message.chat.id]['time_array'], User.get(message.chat.id).timezone, ) for check_native, check_utc in zip( schedule_native, schedule_utc): # нужно оптимизировать Check(habit.id, check_native, check_utc).save() bot.send_message(message.chat.id, text, reply_markup=markups.get_main_menu_markup( message.chat.id)) bot.send_sticker(message.chat.id, 'CAADAgADWQIAAsY4fgsQX6OJTX_IOgI') del preparing_habits[message.chat.id]