From eab21831cf13c9afdafc59adde32c85b9716e76b Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Wed, 22 Feb 2023 11:08:15 -0800 Subject: fix /cancel flow --- command.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'command.py') diff --git a/command.py b/command.py index 09340fc..579fa48 100644 --- a/command.py +++ b/command.py @@ -1,5 +1,6 @@ from telegram import Update from telegram.constants import ParseMode +from telegram.error import BadRequest from telegram.ext import ContextTypes, ConversationHandler from config import * @@ -24,5 +25,17 @@ async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No async def cancel_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: + for prompt in [PROMPT_LOCATION_KEYWORD, PROMPT_CHOOSE_POI_FROM_LIST, PROMPT_ADD_COMMENT, PROMPT_ADD_MEDIA]: + try: + if context.user_data.get(prompt): + await context.bot.delete_message(chat_id=update.message.chat_id, + message_id=context.user_data[prompt]) + except BadRequest as e: + if "not found" in str(e.message): + pass + except Exception as e: + print(e) + await update.message.reply_text(text=PROMPT_CANCELED, reply_markup=MAIN_MENU) + context.user_data.clear() return ConversationHandler.END -- cgit v1.2.3