def create_days_keyboard(selected_date): days_of_week = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'] days_of_week_kb = Keyboa(items=days_of_week, items_in_row=7).keyboard selected_date = selected_date.split('-') days = calendar.monthcalendar(int(selected_date[0]), int(selected_date[1])) day_buttons = [] for week in days: week = list(map(str, week)) for i in range(len(week)): if week[i] == '0': week[i] = ' ' day_buttons.append(week) day_keyboard = Keyboa(items=day_buttons, back_marker='@day', copy_text_to_callback=True).keyboard month_calendar_keyboard = Keyboa.combine(keyboards=(days_of_week_kb, day_keyboard)) return month_calendar_keyboard
def habits(message): db = DbHandler() keyboard_habits = keyboards.habits_keyboard() #to_print = create_list(message.chat.id, 'habits') records = db.select_habits(message.chat.id) if len(records) > 0: to_print = 'Your habits:\n' i = 1 for record in records: to_print += str(i) + '\. ' if record[4] == 1: to_print += '~' + record[2] + '~\n' else: to_print += record[2] + "\n" db.add_gener_num_habits(record[0], i) i += 1 bot.send_message(message.chat.id, to_print, reply_markup=keyboard_habits, parse_mode="MarkdownV2") else: kb_habits = Keyboa(items=[{"Add new habit": "new_habit"}]).keyboard bot.send_message(message.chat.id, "You don't have any habits yet", reply_markup=kb_habits)
def show_tasks(message): db = DbHandler() records = db.select_tasks(message.chat.id) # 0 - task, 1 - state_id, 2 - task_id, 3 - deadline if len(records) > 0: to_print = 'Your tasks:\n' i = 1 for record in records: to_print += str(i) + '. ' # in progress if record[1] == 1: to_print += record[0] + '\u23F3' # done elif record[1] == 3: to_print += '~' + record[0] + '~' # to do else: to_print += record[0] # with deadline if record[3]: to_print += ' ' + record[3].replace('-', '.') to_print += '\n' db.add_gener_num_tasks(record[2], i) i += 1 to_print = functions.markdownv2_ecran(to_print) keyboard = keyboards.tasks_keyboard() bot.send_message(message.chat.id, to_print, reply_markup=keyboard, parse_mode='MarkdownV2') else: buttons = [{'add task': 'new_task'}] keyboard = Keyboa(items=buttons, items_in_row=2).keyboard bot.send_message(message.chat.id, 'You have 0 tasks, do you want to add some?', reply_markup=keyboard)
def history(message1): names = bd.SQLlighter.get_name(message1.from_user.id) names_list = [item for sub in names for item in sub] keyboard = Keyboa(items=names_list, copy_text_to_callback=True).keyboard bot.send_message(message1.chat.id, reply_markup=keyboard, text="Выберите товар для проверки \n")
def create_months_keyboard(): month_buttons = [] for i in range(1,13): button = {} button[calendar.month_name[i]] = str(i) month_buttons.append(button) month_keyboard = Keyboa(items=month_buttons, items_in_row=3, back_marker='@month').keyboard return month_keyboard
def create_year_keyboard(): current_year = datetime.datetime.today().year year_buttons = [i for i in range(current_year, current_year + 4)] year_keyboard = Keyboa(items=year_buttons, back_marker='@year', items_in_row=2, copy_text_to_callback=True).keyboard return year_keyboard
def less_go(callback): menu = [{"Стадион «Фишт»": "fisht"}, {"Ледовый дворец «Большой»": "big_ice"}, {'Ледовая арена «Шайба»': 'shaiba'}, {'Адлер-Арена': 'adler'}, {'Образовательный центр Сириус': "sirius"}, {'Отель омега Сириус': 'sirius_hotel'}, {"Сириус Лицей": 'sirius_lyceum'}, {"Фонтаны": "fontains"}, {"Закончить экскурсию": "end"}] keyboard = Keyboa(items=menu, front_marker="", back_marker="").keyboard bot.send_message(chat_id=callback.message.chat.id, text="Про какой объект тебе рассказать?", reply_markup=keyboard)
def check_command(message1): names = bd.SQLlighter.get_name(message1.from_user.id) names_list = [item for sub in names for item in sub] keyboard = Keyboa(items=names_list, copy_text_to_callback=True).keyboard bot.send_message(message1.chat.id, reply_markup=keyboard, text="Выберите товар для проверки \n") @bot.callback_query_handler(func=lambda call: True) def callback(call): choice(call)
def habits_keyboard(): habits_buttons = [{ "Add new habit": "new_habit" }, { "Change progress": "progress_habit" }, { "Edit": "edit_habit" }, { "Delete": "delete_habit" }] keyboard = Keyboa(habits_buttons, items_in_row=2).keyboard return keyboard
def goals_keyboard(): goals_buttons = [{ 'Add new goal': 'new_goal' }, { 'Change progress': 'progress_goal' }, { 'Edit': 'edit_goal' }, { 'Delete': 'delete_goal' }] keyboard = Keyboa(goals_buttons, 2).keyboard return keyboard
def send_welcome(message): bot.send_message( message.from_user.id, 'Приветcтвую!😉 Я - Cирин,\nумная птица🕊 экскурсовод. Я могу рассказать тебе о прекрасной' ' федеральной территории Сириус⛰') time.sleep(2) if data: bot.send_message(chat_id=message.from_user.id, text=f"Сейчас в Сочи {data['weather'][0]['description']}{sm}.\n" f"Максимальная температура составляет:" f" {data['main']['temp_max']}°C{temp_sm}") menu = [{"Текстовая": "txt"}, {"Голосовая": "voice"}] time.sleep(3) keyboard = Keyboa(items=menu, front_marker="", back_marker="").keyboard bot.send_message(chat_id=message.from_user.id, text="В каком формате тебе наиболее удобна экскурсия?", reply_markup=keyboard)
def tasks_keyboard(): buttons = [{ 'add new task': 'new_task' }, { 'change progress': 'progress_task' }, { 'edit': 'edit_task' }, { 'delete': 'delete_task' }, { 'change deadline': 'changedeadline_task' }] keyboard = Keyboa(buttons, 2).keyboard return keyboard
def get_text_messages(message): try: if message.text.lower() == '/start': # обработка команды начала работы markup = types.ReplyKeyboardMarkup(resize_keyboard=False) status_b = types.KeyboardButton('Запросить статус костюма 📡') notif_b = types.KeyboardButton('Включить/Отключить уведомления 🔔') suit_enable_b = types.KeyboardButton('Включить/Отключить костюм 🔛') sos_b = types.KeyboardButton('Подать сигнал помощи 🆘') markup.row(status_b) markup.row(notif_b, suit_enable_b) markup.row(sos_b) te_bot.send_message( message.from_user.id, 'Здравствуйте, это чат бот для управления защитным костюмом на шахте.', reply_markup=markup) kb_suits = Keyboa(items=rig.get_suits_id()).keyboard te_bot.send_message( message.from_user.id, 'Для начала работы необходиимо пройти процедуру выбора костюма.', reply_markup=kb_suits) elif message.text == 'Включить/Отключить уведомления 🔔': # отключение/включение всех уведомлений кроме SOS users[str(message.from_user.id)]['notif'] = not users[str( message.from_user.id)]['notif'] with open('users.json', 'w') as f: json.dump(users, f) if users[str(message.from_user.id)]['notif']: te_bot.send_message(message.from_user.id, 'Уведомления включены') else: te_bot.send_message(message.from_user.id, 'Уведомления выключены') elif message.text == 'Запросить статус костюма 📡': stats = rig.get_stats(users[str(message.from_user.id)]['object_id']) te_bot.send_message(message.from_user.id, stats) elif message.text == "Включить/Отключить костюм 🔛": suit = rig.switch_suit(users[str(message.from_user.id)]['object_id']) if suit: te_bot.send_message(message.from_user.id, "Костюм активирован") else: te_bot.send_message(message.from_user.id, "Костюм деактивирован") elif message.text == "Подать сигнал помощи 🆘": rig.send_sos() te_bot.send_message(message.from_user.id, "Сигнал о помощи подан, ожидайте!") else: te_bot.send_message(message.from_user.id, 'Не понимаю, что это значит.') except Exception: print('Ошибка при обработке сообщений')
def show_goals(message): db = DbHandler() keyboard_goals = keyboards.goals_keyboard() records = db.select_goals(message.chat.id) if len(records) > 0: to_print = 'Your goals:\n' i = 1 for record in records: to_print += str(i) + '. ' if record[3] == 1: to_print += '~' + record[2] + '~\n' else: to_print += record[2] + "\n" db.add_gener_num_goals(record[0], i) i += 1 to_print = functions.markdownv2_ecran(to_print) bot.send_message(message.chat.id, to_print, reply_markup=keyboard_goals, parse_mode="MarkdownV2") else: kb_goals = Keyboa(items=[{'add new goal':'new_goal'}]).keyboard bot.send_message(message.chat.id, "You don't have any goals yet", reply_markup=kb_goals)
def time_keyboard(): buttons = [{'add time': 'add_time'}, {'skip': 'skip'}] keyboard = Keyboa(buttons, 2).keyboard return keyboard
def answer(call): db = DbHandler() if call.data == 'new_task': instruction = 'Enter your tasks \(each task with a new string\)' task_query = bot.send_message(call.message.chat.id, instruction, parse_mode = 'MarkdownV2') bot.register_next_step_handler(task_query, add_new_task) elif call.data == 'new_habit': sent =bot.send_message(call.message.chat.id, 'What habit would you like to add?') bot.register_next_step_handler(sent, add_habits) elif call.data == 'new_goal': send = bot.send_message(call.message.chat.id, 'What goal would you like to add?') bot.register_next_step_handler(send, add_goals) elif call.data == 'add_time': send = bot.edit_message_text('enter date HH:MM', call.message.chat.id, call.message.id) bot.register_next_step_handler(send, add_time) elif call.data == 'skip': bot.edit_message_text('deadline successfully added', call.message.chat.id, call.message.id ) else: selected_button = call.data replies = {'edit_task':'select task you want to edit', 'delete_task':'select task you want to delete', 'progress_task':'select task to change progress', 'changedeadline_task':'select task for changing deadline', 'edit_habit':'select habit you want to edit', 'delete_habit':'select habit you want to delete', 'progress_habit':'select habit to change progress','edit_goal':'select goal you want to edit', 'delete_goal':'select goal you want to delete', 'progress_goal':'select goal to change progress'} if call.data in replies: if call.data.split('_')[1] == 'task': kb_tasks_generated_num = Keyboa(items=db.get_task_generated_num(call.message.chat.id), back_marker='@'+selected_button, items_in_row=5, copy_text_to_callback=True).keyboard bot.send_message(call.message.chat.id, replies[call.data], reply_markup=kb_tasks_generated_num) if call.data.split('_')[1] == 'habit': kb_habits_generated_num = Keyboa(items=db.get_habit_generated_num(call.message.chat.id), back_marker='@'+selected_button, items_in_row=5, copy_text_to_callback=True).keyboard bot.send_message(call.message.chat.id, replies[call.data], reply_markup=kb_habits_generated_num) if call.data.split('_')[1] == 'goal': kb_goals_generated_num = Keyboa(items=db.get_goal_generated_num(call.message.chat.id), back_marker='@'+selected_button, items_in_row=5, copy_text_to_callback=True).keyboard bot.send_message(call.message.chat.id, replies[call.data], reply_markup=kb_goals_generated_num) elif call.data.split('@')[0].isalnum(): choice_info = call.data.split('@') if choice_info[1] == 'delete_task': bot.send_message(call.message.chat.id, 'successfully deleted') db.delete_task(call.message.chat.id, choice_info[0]) elif choice_info[1] == 'progress_task': db.add_selected_number(call.message.chat.id, choice_info[0]) keyboard = keyboards.progress_keyboard() send = bot.send_message(call.message.chat.id, 'select progress', reply_markup=keyboard) bot.register_next_step_handler(send, change_state) elif choice_info[1] == 'edit_task': db.add_selected_number(call.message.chat.id, choice_info[0]) send = bot.send_message(call.message.chat.id, 'change to') bot.register_next_step_handler(send, edit_task) elif choice_info[1] == 'changedeadline_task': db.add_selected_number(call.message.chat.id, choice_info[0]) keyboard = keyboards.create_year_keyboard() bot.send_message(call.message.chat.id, 'select year', reply_markup=keyboard) elif choice_info[1] == 'year': today = str(datetime.datetime.today())[4:10] default_time = ' 23:59' deadline = choice_info[0] + today + default_time db.add_deadline(call.message.chat.id, deadline) keyboard = keyboards.create_months_keyboard() bot.edit_message_text(text='select month', chat_id=call.message.chat.id, message_id=call.message.id, reply_markup=keyboard) elif choice_info[1] == 'month': month = (choice_info[0]) if len(choice_info[0]) == 1: month = '0' + choice_info[0] today = str(datetime.datetime.today())[7:10] year = db.get_deadline(db.selected_task_id(call.message.chat.id)) year = year[0:5] default_time = ' 23:59' deadline = year + month + today + default_time db.add_deadline(call.message.chat.id, deadline) date = db.get_deadline(db.selected_task_id(call.message.chat.id)) date = date[:7] keyboard = keyboards.create_days_keyboard(date) bot.edit_message_text(text='select day', chat_id=call.message.chat.id, message_id=call.message.id, reply_markup=keyboard) elif choice_info[1] == 'day': date = (choice_info[0]) if len(choice_info[0]) == 1: date = '0' + choice_info[0] selected_date = db.get_deadline(db.selected_task_id(call.message.chat.id)) selected_date = selected_date[:8] default_time = ' 23:59' deadline = selected_date + date + default_time db.add_deadline(call.message.chat.id, deadline) choice_keyboard = keyboards.time_keyboard() send = bot.send_message(call.message.chat.id, 'include time?', reply_markup=choice_keyboard) elif choice_info[1] == 'edit_habit': db.add_selected_number(call.message.chat.id, choice_info[0]) send = bot.send_message(call.message.chat.id, 'change to') bot.register_next_step_handler(send, edit_habit) elif choice_info[1] == 'delete_habit': bot.send_message(call.message.chat.id, 'successfully deleted') db.delete_habit(call.message.chat.id, choice_info[0]) elif choice_info[1] == 'progress_habit': db.change_progress_habit(call.message.chat.id, choice_info[0]) bot.send_message(call.message.chat.id, 'progress changed') elif choice_info[1] == 'edit_goal': db.add_selected_number(call.message.chat.id, choice_info[0]) send = bot.send_message(call.message.chat.id, 'change to') bot.register_next_step_handler(send, edit_goal) elif choice_info[1] == 'delete_goal': bot.send_message(call.message.chat.id, 'successfully deleted') db.delete_goal(call.message.chat.id, choice_info[0]) elif choice_info[1] == 'progress_goal': db.change_progress_goal(call.message.chat.id, choice_info[0]) bot.send_message(call.message.chat.id, 'progress changed')
def answer(call): db = DbHandler() if call.data == 'new_task': instruction = 'Enter your tasks \(each task with a new string\)' task_query = bot.send_message(call.message.chat.id, instruction, parse_mode='MarkdownV2') bot.register_next_step_handler(task_query, add_new_task) elif call.data == 'new_habit': sent = bot.send_message(call.message.chat.id, 'What habit would you like to add?') bot.register_next_step_handler(sent, add_habits) elif call.data == 'new_goal': send = bot.send_message(call.message.chat.id, 'What goal would you like to add?') bot.register_next_step_handler(send, add_goals) else: selected_button = call.data replies = { 'edit_task': 'select task you want to edit', 'delete_task': 'select task you want to delete', 'progress_task': 'select task to change progress', 'changedeadline_task': 'select task for changing deadline', 'edit_habit': 'select habit you want to edit', 'delete_habit': 'selecthabit you want to delete', 'progress_habit': 'select habit to mark as done', 'edit_goal': 'select goal you want to edit', 'delete_goal': 'select goal you want to delete', 'progress_goal': 'select goal to mark as reached' } print(call.data) if call.data in replies: if call.data.split('_')[1] == 'task': kb_tasks_generated_num = Keyboa( items=db.get_task_generated_num(call.message.chat.id), back_marker='@' + selected_button, items_in_row=5, copy_text_to_callback=True).keyboard bot.send_message(call.message.chat.id, replies[call.data], reply_markup=kb_tasks_generated_num) if call.data.split('_')[1] == 'habit': kb_habits_generated_num = Keyboa( items=db.get_habit_generated_num(call.message.chat.id), back_marker='@' + selected_button, items_in_row=5, copy_text_to_callback=True).keyboard bot.send_message(call.message.chat.id, replies[call.data], reply_markup=kb_habits_generated_num) if call.data.split('_')[1] == 'goal': buttons = db.get_goal_generated_num(call.message.chat.id) print(buttons) kb_goals_generated_num = Keyboa( items=buttons, back_marker='@' + selected_button, items_in_row=5, copy_text_to_callback=True).keyboard bot.send_message(call.message.chat.id, replies[call.data], reply_markup=kb_goals_generated_num) elif call.data.split('@')[0].isalnum(): choice_info = call.data.split('@') if choice_info[1] == 'delete_task': bot.send_message(call.message.chat.id, 'successfully deleted') db.delete_task(call.message.chat.id, choice_info[0]) elif choice_info[1] == 'progress_task': db.add_selected_number(call.message.chat.id, choice_info[0]) keyboard = keyboards.progress_keyboard() send = bot.send_message(call.message.chat.id, 'select progress', reply_markup=keyboard) bot.register_next_step_handler(send, change_state) elif choice_info[1] == 'edit_task': db.add_selected_number(call.message.chat.id, choice_info[0]) send = bot.send_message(call.message.chat.id, 'change to') bot.register_next_step_handler(send, edit_task) elif choice_info[1] == 'changedeadline_task': db.add_selected_number(call.message.chat.id, choice_info[0]) keyboard = keyboards.create_year_keyboard() bot.send_message(call.message.chat.id, 'select year', reply_markup=keyboard) elif choice_info[1] == 'year': db.add_deadline(call.message.chat.id, choice_info[0]) keyboard = keyboards.create_months_keyboard() bot.edit_message_text(text='select month', chat_id=call.message.chat.id, message_id=call.message.id, reply_markup=keyboard) elif choice_info[1] == 'month': date = (choice_info[0]) if len(choice_info[0]) == 1: date = '0' + choice_info[0] db.update_deadline(call.message.chat.id, '-' + date) date = db.get_deadline( db.selected_task_id(call.message.chat.id)) keyboard = keyboards.create_days_keyboard(date) bot.edit_message_text(text='select day', chat_id=call.message.chat.id, message_id=call.message.id, reply_markup=keyboard) elif choice_info[1] == 'day': date = (choice_info[0]) if len(choice_info[0]) == 1: date = '0' + choice_info[0] db.update_deadline(call.message.chat.id, '-' + date) send = bot.send_message(call.message.chat.id, 'enter_time') bot.register_next_step_handler(send, add_time) elif choice_info[1] == 'edit_habit': db.add_selected_number(call.message.chat.id, choice_info[0]) send = bot.send_message(call.message.chat.id, 'change to') bot.register_next_step_handler(send, edit_habit) elif choice_info[1] == 'edit_goal': db.add_selected_number(call.message.chat.id, choice_info[0]) send = bot.send_message(call.message.chat.id, 'change to') bot.register_next_step_handler(send, edit_goal) elif choice_info[1] == 'delete_habit': bot.send_message(call.message.chat.id, 'successfully deleted') db.delete_habit(call.message.chat.id, choice_info[0]) elif choice_info[1] == 'delete_goal': bot.send_message(call.message.chat.id, 'successfully deleted') db.delete_goal(call.message.chat.id, choice_info[0]) elif choice_info[1] == 'progress_habit': db.change_progress_habit(call.message.chat.id, choice_info[0]) bot.send_message(call.message.chat.id, 'progress changed') elif choice_info[1] == 'progress_goal': db.change_progress_goal(call.message.chat.id, choice_info[0]) bot.send_message(call.message.chat.id, 'progress changed')
def going_voice(callback): menu = [{"Мужской голос": "going_voice_m"}, {"Женский голос": "going_voice_w"}] keyboard = Keyboa(items=menu, front_marker="", back_marker="").keyboard bot.send_message(chat_id=callback.message.chat.id, text="Выбери голос экскурсовода:", reply_markup=keyboard)