def add_new_text(msg, need_list, need_index): new_text = msg.text user_task = user_get_tasks(msg, db_collection)[need_list][need_index] user_task['task'] = new_text update_status = user_update_task(msg, COLLECTION, need_list, need_index, user_task) if update_status: notify_text = ui.dialogue['text_changed'].format( ui.different_signs['warning']) bot.send_message(chat_id=call.message.chat.id, text=notify_text, reply_markup=MENU_BACK) new_screen_info = edited_task_card(user_task) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=new_screen_info[0], reply_markup=new_screen_info[1], parse_mode='HTML') else: notify_text = ui.dialogue['text_not_changed'].format( ui.different_signs['exclamatory']) bot.send_message(chat_id=call.message.chat.id, text=notify_text, reply_markup=MENU_BACK)
def switch_task_status(call, db_collection, text): target_id = extract_id(text) target_list = find_list(call, db_collection, target_id) task_index = find_index_task(call, db_collection, target_id, target_list) if target_list and task_index is not False: user_task = user_get_tasks(call, db_collection)[target_list][task_index] if user_task.get('task_status'): user_task['task_status'] = False else: user_task['task_status'] = True update_status = user_update_task(call, COLLECTION, target_list, task_index, user_task) if update_status: new_screen_info = edited_task_card(user_task) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=new_screen_info[0], reply_markup=new_screen_info[1], parse_mode='HTML') text = ui.dialogue['task_status_changed'].format( ui.different_signs['warning']) bot.send_message(chat_id=call.message.chat.id, text=text) else: text = ui.dialogue['task_status_not_changed'].format( ui.different_signs['exclamatory']) bot.send_message(chat_id=call.message.chat.id, text=text) else: text = ui.dialogue['wrong_task_status'].format( ui.different_signs['exclamatory']) bot.send_message(chat_id=call.message.chat.id, text=text)
def callback_inline_keyboard(call): if call.message: if call.data == list(ui.button_blanks.keys())[0]: # Show expanded help text = ui.help_todo['full_info'] bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=text, parse_mode='HTML', reply_markup=None) if call.data == list(ui.button_blanks.keys())[1]: # Delete task del_status = del_task(call, COLLECTION, call.message.text) if del_status: text = ui.dialogue['delete_task_success'].format( ui.different_signs['warning']) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=text) else: text = ui.dialogue['delete_failed'].format( ui.different_signs['exclamatory']) bot.send_message(chat_id=call.message.chat.id, text=text) if call.data == list(ui.button_blanks.keys())[2]: # Edit text task edit_text(call, COLLECTION, call.message.text) if call.data == list(ui.button_blanks.keys())[3]: # Mark the task as completed switch_task_status(call, COLLECTION, call.message.text) if call.data == list(ui.button_blanks.keys())[4]: # Mark task as not completed switch_task_status(call, COLLECTION, call.message.text)