Changed remove product to list of buttons

This commit is contained in:
Joan Cano
2023-03-20 00:03:17 +01:00
parent 981271bc65
commit a91f39bece

View File

@@ -78,8 +78,6 @@ async def menu_click_handler(update: Update, context: CallbackContext):
return ConversationHandler.END
if query.data == 'remove':
await send_list(update, context)
await context.bot.send_message(chat_id=update.effective_chat.id,
text='Escribe el nombre del producto a borrar, tal y como aparece en la lista', reply_markup=ForceReply())
return REMOVE_PRODUCT
if query.data == 'list':
await send_list(update, context)
@@ -306,15 +304,15 @@ async def cancel(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
return ConversationHandler.END
async def remove_product(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await update.callback_query.edit_message_reply_markup(None)
query = update.callback_query
product_name = query.data
telegram_user_id = helpers.get_telegram_user_id(update)
if walladb.is_user_valid(telegram_user_id):
if walladb.is_user_testing(telegram_user_id) or walladb.is_user_premium(telegram_user_id):
product_to_remove = update.message.text
message = f"¡{product_to_remove} no está en seguimiento!"
if walladb.remove_product({'product_name' : product_to_remove, \
message = f"¡{product_name} no está en seguimiento!"
if walladb.remove_product({'product_name' : product_name, \
'telegram_user_id' : telegram_user_id}):
message = f"¡{product_to_remove} borrado de la lista de seguimiento!"
await update.message.reply_text(message)
message = f"¡{product_name} borrado de la lista de seguimiento!"
await context.bot.send_message(chat_id=update.effective_chat.id, text=message)
return ConversationHandler.END
async def product_details(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
@@ -338,10 +336,14 @@ async def send_list(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
telegram_user_id = helpers.get_telegram_user_id(update)
if walladb.is_user_valid(telegram_user_id):
if walladb.is_user_testing(telegram_user_id) or walladb.is_user_premium(telegram_user_id):
query = update.callback_query
if query.data == 'remove':
text = "Escoge un producto para borrar"
if query.data == 'list':
text = "Escoge un producto para ver los detalles"
keyboard = helpers.create_products_keyboard(telegram_user_id)
markup = InlineKeyboardMarkup(keyboard)
await context.bot.send_message(chat_id=update.effective_chat.id, text="Escoge para ver detalles", reply_markup=markup)
await context.bot.send_message(chat_id=update.effective_chat.id, text=text, reply_markup=markup)
async def admin_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
if helpers.is_user_admin(update.message.chat_id):
@@ -443,7 +445,7 @@ def main()->None:
ADD_PRODUCT_CATEGORY: [CallbackQueryHandler(add_product_category)],
CONTINUE_OR_FINISH: [CallbackQueryHandler(continue_or_finish),
MessageHandler(filters.TEXT, continue_or_finish)],
REMOVE_PRODUCT: [MessageHandler(filters.TEXT, remove_product)],
REMOVE_PRODUCT: [CallbackQueryHandler(remove_product)],
LIST: [CallbackQueryHandler(product_details)],
ConversationHandler.TIMEOUT: [CallbackQueryHandler(conv_timeout),
MessageHandler(filters.TEXT, conv_timeout)],