diff --git a/bot/telegram_bot.py b/bot/telegram_bot.py index 72ea39e..a5cbdfe 100644 --- a/bot/telegram_bot.py +++ b/bot/telegram_bot.py @@ -21,6 +21,7 @@ timezone = pytz.timezone("Asia/Singapore") + def get_category_text(sheet_id, entry_type): msg = "" markup_list = [] @@ -215,7 +216,8 @@ def config_category(update, context) -> int: ) payment_list = gs.get_main_dropdown_value(sheet_id, "Payment") update.callback_query.message.reply_text( - DEFAULT_PAYMENT_TEXT, reply_markup=utils.create_inline_markup(payment_list) + DEFAULT_PAYMENT_TEXT, + reply_markup=utils.create_inline_markup(payment_list), ) return CS.CONFIG_PAYMENT elif config == EntryType.OTHERS: @@ -264,7 +266,8 @@ def config_payment(update, context) -> int: if len(sub_markup_list) > 1: sub_markup_list.pop(0) update.callback_query.message.edit_text( - DEFAULT_PAYMENT_TEXT, reply_markup=utils.create_inline_markup(sub_markup_list) + DEFAULT_PAYMENT_TEXT, + reply_markup=utils.create_inline_markup(sub_markup_list), ) return CS.CONFIG_SUBPAYMENT except Exception as e: @@ -347,7 +350,9 @@ def remarks(update: Update, context) -> int: return CS.REMARKS msg, markup_list = get_category_text(sheet_id, entry_type) try: - update.message.reply_text(msg, reply_markup=utils.create_inline_markup(markup_list)) + update.message.reply_text( + msg, reply_markup=utils.create_inline_markup(markup_list) + ) return CS.CATEGORY except Exception as e: update.message.reply_text(ERROR_TEXT) @@ -367,7 +372,8 @@ def category(update, context) -> int: context.user_data["category"] = f"{reply}" payment_list = get_payment_text(sheet_id) update.callback_query.message.reply_text( - DEFAULT_PAYMENT_TEXT, reply_markup=utils.create_inline_markup(payment_list) + DEFAULT_PAYMENT_TEXT, + reply_markup=utils.create_inline_markup(payment_list), ) return CS.PAYMENT elif entry_type == EntryType.OTHERS: @@ -434,7 +440,8 @@ def payment(update, context) -> int: sub_markup_list.pop(0) sub_markup_list.append(BACK_TEXT) update.callback_query.message.edit_text( - DEFAULT_PAYMENT_TEXT, reply_markup=utils.create_inline_markup(sub_markup_list) + DEFAULT_PAYMENT_TEXT, + reply_markup=utils.create_inline_markup(sub_markup_list), ) return CS.SUBPAYMENT # This won't be called as there will always be a subpayment, but just in case @@ -442,7 +449,7 @@ def payment(update, context) -> int: update.callback_query.edit_message_text( f'Payment type: {context.user_data["payment"]}', reply_markup=None ) - if context.user_data["backlog"]: + if context.user_data.get("backlog"): backlog_transaction(context.user_data, update) else: log_transaction(context.user_data, update) @@ -468,7 +475,7 @@ def subpayment(update, context) -> int: update.callback_query.edit_message_text( f'Payment type: {context.user_data["payment"]}', reply_markup=None ) - if context.user_data["backlog"]: + if context.user_data.get("backlog"): backlog_transaction(context.user_data, update) else: log_transaction(context.user_data, update) @@ -560,7 +567,6 @@ def backlog_transaction(user_data, update): if backlog_month.title() == month: gs.row_incremental_all(sheet_id) - # user input data entry_type = user_data["entry_type"] payment = user_data["payment"] @@ -572,6 +578,7 @@ def backlog_transaction(user_data, update): # create backlog entry gs.create_backlog_entry(sheet_id, backlog_day, backlog_month, row_data) + def cancel(update, context): update.message.reply_text(END_TEXT, reply_markup=None) context.user_data.clear() @@ -719,12 +726,16 @@ def handle_get_transaction(update, context): total_spend, transport_values, other_values = gs.get_day_transaction( sheet_id, month, day ) - if total_spend == None and transport_values == None and other_values == None: + if ( + total_spend == None + and transport_values == None + and other_values == None + ): update.message.reply_text( f"No transaction found for {day} {month}", reply_markup=None ) return ConversationHandler.END - + if not total_spend: total_spend = "To be determine" else: @@ -811,7 +822,8 @@ def income(update, context) -> int: sheet_id = context.user_data["sheet_id"] work_list = gs.get_work_place(sheet_id) update.message.reply_text( - CHOOSE_INCOME_SOURCE_TEXT, reply_markup=utils.create_inline_markup(work_list) + CHOOSE_INCOME_SOURCE_TEXT, + reply_markup=utils.create_inline_markup(work_list), ) return CS.WORK_PLACE except Exception as e: @@ -851,12 +863,14 @@ def cpf(update, context) -> int: update.callback_query.message.reply_text(ERROR_TEXT) return ConversationHandler.END + def backlog(update, context) -> int: context.user_data.clear() update.message.reply_text(BACKLOG_DATE_TEXT) context.user_data["backlog"] = True return CS.ADD_BACKLOG_ENTRY + def add_backlog_entry(update, context) -> int: reply = update.message.text if utils.check_date_format(reply): @@ -869,7 +883,7 @@ def add_backlog_entry(update, context) -> int: else: update.message.reply_text(BACKLOG_DATE_TEXT) return CS.ADD_BACKLOG_ENTRY - + telegram_id = update.effective_user.id context.user_data["sheet_id"] = db.get_user_sheet_id(telegram_id) update.message.reply_text( @@ -880,6 +894,7 @@ def add_backlog_entry(update, context) -> int: ) return CS.ENTRY + def setup_handlers(dispatcher): # Configuration-related states and handlers config_states = { @@ -900,7 +915,9 @@ def setup_handlers(dispatcher): CS.SUBCATEGORY: [CallbackQueryHandler(subcategory)], CS.PAYMENT: [CallbackQueryHandler(payment)], CS.SUBPAYMENT: [CallbackQueryHandler(subpayment)], - CS.ADD_BACKLOG_ENTRY: [MessageHandler(Filters.text & ~Filters.command, add_backlog_entry)], + CS.ADD_BACKLOG_ENTRY: [ + MessageHandler(Filters.text & ~Filters.command, add_backlog_entry) + ], } # Quick add-related states and handlers diff --git a/bot/text_str.py b/bot/text_str.py index ff26f1b..0b23334 100644 --- a/bot/text_str.py +++ b/bot/text_str.py @@ -14,7 +14,7 @@ + "6. Copy your entire Google Sheet URL and send it over\n" + "Example: https://docs.google.com/spreadsheets/d/abcd1234/edit\n" ) -ERROR_TEXT = "There seems to be an error, please try again later." +ERROR_TEXT = "There seems to be an error, please try again later. If the problem persists, please contact report it at github.com/brucewzj99/tele-tracker-v2/issues" SUCCESS_LINK_TEXT = "Google sheet successfully linked! Please proceed to configure your Dropdown sheet.\nOnce completed, type /addentry to add your first entry!" GSHEET_ERROR_TEXT = f"There seems to be an error linking your google sheet, have you shared your Google Sheet with {GOOGLE_API_EMAIL} yet?" GSHEET_WRONG_TEXT = ( @@ -69,4 +69,6 @@ CPF_TEXT = "Is there CPF?" INCOME_LIMIT_TEXT = "You have exceed the number of income allowed! (max 6)" -BACKLOG_DATE_TEXT = "Please enter the date of the entry in this format: DD MMM\ne.g 16 Mar" \ No newline at end of file +BACKLOG_DATE_TEXT = ( + "Please enter the date of the entry in this format: DD MMM\ne.g 16 Mar" +) diff --git a/release_notes.md b/release_notes.md index 7ecc565..36395bf 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,4 +1,8 @@ # Release Notes +## Version 2.1.8 - Date 17 Dec 2023 +### Bug Fix 🛠️ +- Fix add entry bug + ## Version 2.1.7 - Date 16 Dec 2023 ### New Features 🆕 - You can now add backdated transactions with `/backlog` command! 🎉