diff --git a/conjuntasbot/conjuntasbot.py b/conjuntasbot/conjuntasbot.py index 57121f1..fa3c8e9 100644 --- a/conjuntasbot/conjuntasbot.py +++ b/conjuntasbot/conjuntasbot.py @@ -367,21 +367,24 @@ async def handle_conjunta(update: Update, context: CallbackContext): if limit is not None and quantity > limit_per_user or limit is not None and quantity > quantity_left(conjunta_id): await update.message.reply_text("La cantidad deseada excede el límite por usuario de la conjunta o no quedan suficientes.") else: - cursor.execute("INSERT INTO conjunta_users (conjunta_id, user_id, user_name, quantity) VALUES (?, ?, ?, ?)", - (conjunta_id, user_id, user_name, quantity)) - conn.commit() + if user_name: + cursor.execute("INSERT INTO conjunta_users (conjunta_id, user_id, user_name, quantity) VALUES (?, ?, ?, ?)", + (conjunta_id, user_id, user_name, quantity)) + conn.commit() - socios_worksheet = spreadsheet.worksheet("Socios") - socio = socios_worksheet.find(user_name) - - worksheet = spreadsheet.worksheet(f"{product_name} - {conjunta_id}") - worksheet.append_row([user_name, quantity, "SÍ" if socio else "NO"]) - - await update.message.reply_text(f"Te has unido a la conjunta para '{product_name}' con {quantity} unidades.") - try: - await update_conjunta(update, context, conjunta_id) - except Exception: - pass + socios_worksheet = spreadsheet.worksheet("Socios") + socio = socios_worksheet.find(user_name) + + worksheet = spreadsheet.worksheet(f"{product_name} - {conjunta_id}") + worksheet.append_row([user_name, quantity, "SÍ" if socio else "NO"]) + + await update.message.reply_text(f"Te has unido a la conjunta para '{product_name}' con {quantity} unidades.") + try: + await update_conjunta(update, context, conjunta_id) + except Exception: + pass + else: + await update.message.reply_text("Por favor, tienes que ponerte un nick en Telegram para poder participar.") except ValueError: await update.message.reply_text("Por favor, introduce una cantidad válida.") else: