def add_time(message): db = DbHandler() print(message.text) if re.match('(([0-1][0-9]|2[0-3]):[0-5][0-9])', message.text).group(): db.update_deadline(message.chat.id, ' ' + message.text) bot.send_message(message.chat.id, 'deadline successfully added')
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')