def start(update, context): """Send a message when the command /start is issued.""" text = """*bold \*text* _italic \*text_ __underline__ ~strikethrough~ *bold _italic bold ~italic bold strikethrough~ __underline italic bold___ bold* [inline URL](http://www.example.com/) [inline mention of a user](tg://user?id=123456789) `inline fixed-width code` ``` pre-formatted fixed-width code block ``` ```python pre-formatted fixed-width code block written in the Python programming language ```""" text = text * 40 reply_markdown(update, context, text) context.user_data["status"] = "START"
def set_sub_category_and_ask_location(update, context): """Get sub category""" # save log work type data if check_status(context, "SIGN_IN"): put_sub_category(context.user_data["log_id"], update.message.text) text_message = """I see! Please send me your location by click the button on your phone. 1. Please check your location service is on.(if not please turn on your location service) 2. Desktop app can not send location""" keyboard = [ [ KeyboardButton("Share Location", request_location=True), "Not Available" ], ] reply_markdown(update, context, text_message, keyboard) else: print(context.user_data) return ANSWER_SIGN_IN_LOCATION
def ask_confirmation_of_removal(update, context): log_id = update.message.text try: int(log_id) context.user_data["remove_log_id"] = log_id keyboard = [["YES", "NO"]] conn = create_connection() row = select_record(conn, "logbook", LOG_COLUMN, {"id": log_id}) conn.close() header_message = f"Do you really want to do remove log No.{log_id}?\n" text_message = make_text_from_logs(row, header_message) reply_markdown(update, context, text_message, keyboard) return HANDLE_LOG_DELETE except ValueError: text_message = "Please. Send me numbers only." reply_markdown(update, context, text_message) return HANDLE_DELETE_LOG_ID
def override_log_and_ask_work_type(update, context): choices = {"REMOVE SIGN IN LOG": True, "NO": False} answer = choices.get(update.message.text) if answer: log_id = context.user_data.get("log_id") conn = create_connection() delete_record(conn, "logbook", {"id": log_id}) conn.close() text_message = f"Log No. {log_id} has been Deleted\n" reply_markdown(update, context, text_message) else: text_message = "process has been stoped. The log has not been deleted." reply_markdown(update, context, text_message) return ConversationHandler.END log_id = post_basic_user_data(update, context, "signing in") context.user_data["log_id"] = log_id return ask_sub_category(update, context)
def start_edit(update, context): choices = {"YES": True, "NO": False} answer = choices.get(update.message.text) if answer: log_id = context.user_data.get("log_id") conn = create_connection() rows = select_record(conn, "logbook", ("category", "history"), {"id": log_id}) category = rows[0][0] history = rows[0][1] if rows[0][1] else "" history += f"Edited at {update.message.date} for {category}\n" update_record(conn, "logbook", {"history": history}, log_id) conn.close() keyboard_dict = { "signing in": [ ["Office", "Home"], ], "signing out": [[ "I worked at Office", "I would like to report because I worked at home", ]], "getting back": [ ["Without any member of KOICA", "With KOICA Colleagues"], ], } status_dict = { "signing in": "SIGN_IN", "signing out": "SIGN_OUT", "getting back": "GET_BACK", } context.user_data["status"] = status_dict.get(category) text_message = f"start to edit Log No.{log_id} by press button\n" reply_markdown(update, context, text_message, keyboard_dict.get(category)) else: text_message = "process has been stoped. The log has not been deleted." reply_markdown(update, context, text_message) context.user_data.clear() return ConversationHandler.END
def ask_confirmation_of_edit(update, context): log_id = update.message.text try: int(log_id) keyboard = [["YES", "NO"]] conn = create_connection() rows = select_record(conn, "logbook", LOG_COLUMN, {"id": log_id}) conn.close() header_message = f"Do you really want to do edit log No.{log_id}?\n" text_message = make_text_from_logs(rows, header_message) reply_markdown(update, context, text_message, keyboard) chat_id = rows[0][1] set_context(update, context, {"log_id": log_id, "chat_id": chat_id}) return ANSWER_CONFIRMATION except ValueError: text_message = "Please. Send me numbers only." reply_markdown(update, context, text_message) return ANSWER_LOG_ID
def ask_log_id_to_edit(update, context): """ """ user = update.message.from_user conn = create_connection() rows = select_record( conn, "logbook", LOG_COLUMN, {"chat_id": user.id}, "ORDER BY timestamp DESC LIMIT 3", ) rows = rows[-1::-1] conn.close() text_message = "Which log do you want to edit?\nPlease send me the log number." text_message = make_text_from_logs(rows, text_message) reply_markdown(update, context, text_message) context.user_data["status"] = "EDIT_LOG_ID" return ANSWER_LOG_ID
def ask_content_for_remarks(update, context): text = update.message.text print(text, type(text)) print(get_record_by_log_ids(text)) try: if get_record_by_log_ids(text): context.user_data["remarks_log_ids"] = text text_message = "What remarks? do you want to add?" reply_markdown(update, context, text_message) return HANDLE_REMARKS_CONTENT else: text_message = "log id is not exist. Please try again" reply_markdown(update, context, text_message) raise ValueError except ValueError: text_message = "Please. Send us numbers only." reply_markdown(update, context, text_message) return HANDLE_REMARKS_LOG_ID
def ask_work_content(update, context): text_message = "OK. Please text me what you have done today for work briefly." reply_markdown(update, context, text_message) return ANSWER_WORK_CONTENT
def get_logs_today(update, context): """ """ text_message = get_logs_of_today() reply_markdown(update, context, text_message)
def ask_date_for_log(update, context): text_message = "Please send the date as YYYY-MM-DD format" reply_markdown(update, context, text_message) context.user_data["status"] = "DATE_FOR_LOG"