Added button to product found. Added product_name to know from which search provides the article found.
This commit is contained in:
@@ -91,16 +91,21 @@ async def menu_click_handler(update: Update, context: CallbackContext):
|
||||
|
||||
async def add_product_name(update: Update, context: CallbackContext):
|
||||
if context.user_data.get('product_name', '') == '':
|
||||
answer = update.message.text
|
||||
context.user_data['product_name'] = answer
|
||||
if not walladb.get_product(context.user_data):
|
||||
product_name = update.message.text
|
||||
if len(product_name) > 200:
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||
text='Escribe el precio mínimo', reply_markup=ForceReply())
|
||||
return ADD_PRODUCT_MIN_PRICE
|
||||
text='El nombre del producto a buscar es muy largo, pon otro nombre', reply_markup=ForceReply())
|
||||
return ADD_PRODUCT_NAME
|
||||
else:
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||
text=f"¡{walladb.get_product(context.user_data)['product_name']} ya está en seguimiento!")
|
||||
return ConversationHandler.END
|
||||
context.user_data['product_name'] = product_name
|
||||
if not walladb.get_product(context.user_data):
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||
text='Escribe el precio mínimo', reply_markup=ForceReply())
|
||||
return ADD_PRODUCT_MIN_PRICE
|
||||
else:
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||
text=f"¡{walladb.get_product(context.user_data)['product_name']} ya está en seguimiento!")
|
||||
return ConversationHandler.END
|
||||
|
||||
async def add_product_min_price(update: Update, context: CallbackContext):
|
||||
if context.user_data.get('min_price', '') == '':
|
||||
@@ -111,9 +116,9 @@ async def add_product_min_price(update: Update, context: CallbackContext):
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||
text='Pon un precio mínimo en números', reply_markup=ForceReply())
|
||||
return ADD_PRODUCT_MIN_PRICE
|
||||
if min_price < 0:
|
||||
if min_price < 0 or min_price > 999999:
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||
text='Pon un precio mínimo en números que no sean negativos', reply_markup=ForceReply())
|
||||
text='Pon un precio mínimo entre 0 y 999999', reply_markup=ForceReply())
|
||||
return ADD_PRODUCT_MIN_PRICE
|
||||
context.user_data['min_price'] = min_price
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||
@@ -129,9 +134,13 @@ async def add_product_max_price(update: Update, context: CallbackContext):
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||
text='Pon un precio máximo en números', reply_markup=ForceReply())
|
||||
return ADD_PRODUCT_MAX_PRICE
|
||||
if max_price < 0:
|
||||
if max_price < 0 or max_price > 999999:
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||
text='Pon un precio máximo en números que no sean negativos', reply_markup=ForceReply())
|
||||
text='Pon un precio máximo entre 0 y 999999', reply_markup=ForceReply())
|
||||
return ADD_PRODUCT_MAX_PRICE
|
||||
if max_price < context.user_data['min_price']:
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||
text='Pon un precio máximo menor al precio mínimo', reply_markup=ForceReply())
|
||||
return ADD_PRODUCT_MAX_PRICE
|
||||
context.user_data['max_price'] = max_price
|
||||
keyboard = [
|
||||
@@ -340,7 +349,7 @@ async def add_to_db_and_send(update: Update, context: ContextTypes.DEFAULT_TYPE)
|
||||
walladb.add_product(context.user_data)
|
||||
p = threading.Thread(target=Worker.run, args=(walladb.get_product(context.user_data), ))
|
||||
p.start()
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id, text=f"¡*{context.user_data['product_name']}* añadido correctamente\!", parse_mode=ParseMode.MARKDOWN_V2)
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id, text=f"¡*{helpers.telegram_escape_characters(context.user_data['product_name'])}* añadido correctamente\!", parse_mode=ParseMode.MARKDOWN_V2)
|
||||
|
||||
def error(update, context):
|
||||
logging.error(f'Update ---{update}--- caused error ---{context.error}---')
|
||||
@@ -371,6 +380,8 @@ def main()->None:
|
||||
application.add_handler(CommandHandler("remove_user", remove_user_command))
|
||||
application.add_handler(CommandHandler("status", status_command))
|
||||
application.add_handler(CommandHandler("test", test_command))
|
||||
#application.add_handler(CallbackQueryHandler("list", send_list()))
|
||||
#application.add_handler(CallbackQueryHandler(pattern="list", callback=send_list()))
|
||||
|
||||
conv_handler = ConversationHandler(
|
||||
conversation_timeout=60,
|
||||
|
||||
Reference in New Issue
Block a user