def title_handler(update, context): # Get user id and user language user_id = update.message.from_user.id language = get_user_language(user_id=user_id, short=True) # Check pushed button of keyboard pushed_button = check_button(update, KEYBOARDS["static"]["cancel"], language) # If pushed button is "cancel" exit user from conversation if pushed_button == "cancel": return exit_from_conversation(update) # Check if user has task with such title if update.message.text in get_user_tasks(user_id, only_titles=True): update.message.reply_text(get_message("task_exist", language)) return "title_handler" # Clear context.user_data for new task and load title there context.user_data["new_task"] = {} context.user_data["new_task"]["title"] = update.message.text # Send message to write days of the week of the task update.message.reply_text(get_message("write_task_days_of_the_week", language), reply_markup=get_menu_keyboard( "cancel_back", language)) return "days_of_the_week_handler"
def send_main_menu(update): # Get user language language = get_user_language(update=update, short=True) # Send menu update.message.reply_text(get_signboard("main_menu", language), reply_markup=get_menu_keyboard( "main_menu", language))
def send_edit_mode_menu(update): # Get user language language = get_user_language(update=update, short=True) # Send menu update.message.reply_text(get_message("choice_action", language), reply_markup=get_menu_keyboard( "edit_task_menu", language))
def days_of_the_week_handler(update, context): # Get user id and user language user_id = update.message.from_user.id language = get_user_language(user_id=user_id, short=True) # Check pushed button of keyboard pushed_button = check_button(update, KEYBOARDS["static"]["cancel_back"], language) # If pushed button is "cancel" exit user from conversation if pushed_button == "cancel": return exit_from_conversation(update) # If pushed button is "back" return user to previous # stage of task adding - write task title if pushed_button == "back": update.message.reply_text(get_message("write_task_title", language), reply_markup=get_menu_keyboard( "cancel", language)) return "title_handler" # Get days of the week from user message days_of_the_week_str = get_days_of_the_week_from_string( update.message.text, language) # Check if message is incorrect if not days_of_the_week_str: update.message.reply_text(get_message("invalid_input", language)) return "days_of_the_week_handler" # Load days of the week to context.user_data for new task context.user_data["new_task"]["days_of_the_week"] = days_of_the_week_str # Get data from context.user_data new_task_data = context.user_data["new_task"] # Add new task to database add_task(user_id, new_task_data["title"], new_task_data["days_of_the_week"]) # Clear context.user_data for new task context.user_data["new_task"] = {} # Send message to user about successful adding update.message.reply_text(get_message("task_added", language)) # Exit from conversation return exit_from_conversation(update)
def handler(update, context): # Get user id and user language user_id = update.message.from_user.id language = get_user_language(user_id=user_id, short=True) # Check pushed button of keyboard pushed_button = check_button(update, KEYBOARDS["static"]["editor_menu"], language) # If pushed button is "add_task", proceed to task adding if pushed_button == "add_task": update.message.reply_text(get_message("write_task_title", language), reply_markup=get_menu_keyboard( "cancel", language)) return "add_task" # If pushed button is "add_task" elif pushed_button == "edit_task": # If user has tasks, proceed to task editing if get_user_tasks(user_id): send_choice_tasks_menu(update) return "edit_task" # If user hasn't tasks, stay in editor menu else: update.message.reply_text(get_message("not_tasks", language)) send_editor_menu(update) return "editor_menu" # If pushed button is "back", exit from conversation elif pushed_button == "back": return exit_from_conversation(update) # If user message isn't button, ask user click on the buttons else: update.message.reply_text(get_message("click_buttons", language)) send_editor_menu(update) return "editor_menu"
def edit_mode_handler(update, context): # Get user id and user language user_id = update.message.from_user.id language = get_user_language(user_id=user_id, short=True) # Check pushed button of keyboard pushed_button = check_button(update, KEYBOARDS["static"]["edit_task_menu"], language) # If pushed button is "back" return user to previous # stage of task editing - choice task menu if pushed_button == "back": if "page" not in context.user_data: context.user_data["page"] = 0 send_choice_tasks_menu(update, context.user_data["page"]) return "choice_task_handler" # If pushed button is "title", proceed to title editing elif pushed_button == "title": update.message.reply_text(get_message("write_task_title", language), reply_markup=get_menu_keyboard( "cancel", language)) return "new_title_handler" # If pushed button is "days_of_the_week", # proceed to days of the week editing elif pushed_button == "days_of_the_week": update.message.reply_text(get_message("write_task_days_of_the_week", language), reply_markup=get_menu_keyboard( "cancel", language)) return "new_days_of_the_week_handler" # If pushed button is "delete", delete task elif pushed_button == "delete": # Delete task delete_task(context.user_data["selected_task_id"]) # Send message to user about successful deleting update.message.reply_text(get_message("task_deleted", language)) # If user has tasks, send choice task menu if get_user_tasks(user_id): send_choice_tasks_menu(update) context.user_data["page"] = 0 return "choice_task_handler" # Else send editor menu else: send_editor_menu(update) return ConversationHandler.END # If more than one condition is incorrect, # send message to user push to buttons else: update.message.reply_text(get_message("click_buttons", language)) return "edit_mode_handler"