Fixes
This commit is contained in:
@@ -387,7 +387,8 @@ async def update_conjunta(update: Update, context: CallbackContext, conjunta_id)
|
|||||||
if conjunta:
|
if conjunta:
|
||||||
conjunta_id, message_id_general, message_id_vip, product_name, product_description, limit, limit_per_user, price, price_member, closed, photo_id, message_date = conjunta
|
conjunta_id, message_id_general, message_id_vip, product_name, product_description, limit, limit_per_user, price, price_member, closed, photo_id, message_date = conjunta
|
||||||
|
|
||||||
message = f"Conjunta para 🛒 <b>{product_name}</b>\n\n"
|
message = f'<a href="https://t.me/homelabsclub/556703">📖 Normas de conjuntas 📖</a>\n\n'
|
||||||
|
message += f"Conjunta para 🛒 <b>{product_name}</b>\n\n"
|
||||||
if limit:
|
if limit:
|
||||||
message += f"#️⃣ Límite de <b>{limit}</b> productos.\n"
|
message += f"#️⃣ Límite de <b>{limit}</b> productos.\n"
|
||||||
message += f"#️⃣ Límite de <b>{limit_per_user}</b> por usuario.\n"
|
message += f"#️⃣ Límite de <b>{limit_per_user}</b> por usuario.\n"
|
||||||
@@ -402,7 +403,8 @@ async def update_conjunta(update: Update, context: CallbackContext, conjunta_id)
|
|||||||
message += f"\n💰 Precio para socios: <b>{price_member}€</b>\n"
|
message += f"\n💰 Precio para socios: <b>{price_member}€</b>\n"
|
||||||
message += f"💰 Precio para NO socios: <b>{price}€</b>\n"
|
message += f"💰 Precio para NO socios: <b>{price}€</b>\n"
|
||||||
message += f"\nPuedes unirte respondiendo a este mensaje con <code>me apunto {{cantidad}}</code>, en números.\n"
|
message += f"\nPuedes unirte respondiendo a este mensaje con <code>me apunto {{cantidad}}</code>, en números.\n"
|
||||||
message += f"Para borrarte responde a este mensaje y di <code>me borro</code>.\n"
|
message += f"Para borrarte responde a este mensaje y di <code>me borro</code>.\n\n"
|
||||||
|
message += f'<a href="https://t.me/homelabsclub/556703">📖 Normas de conjuntas 📖</a>\n'
|
||||||
|
|
||||||
cursor.execute("SELECT * FROM conjunta_users WHERE conjunta_id=?", (conjunta_id,))
|
cursor.execute("SELECT * FROM conjunta_users WHERE conjunta_id=?", (conjunta_id,))
|
||||||
users = cursor.fetchall()
|
users = cursor.fetchall()
|
||||||
@@ -416,7 +418,7 @@ async def update_conjunta(update: Update, context: CallbackContext, conjunta_id)
|
|||||||
|
|
||||||
if int(message_id_vip) != 0:
|
if int(message_id_vip) != 0:
|
||||||
if (int(time.time()) - int(message_date)) < (24 * 3600 * 2): # borramos el mensaje si tiene más de 1 día
|
if (int(time.time()) - int(message_date)) < (24 * 3600 * 2): # borramos el mensaje si tiene más de 1 día
|
||||||
logging.info(f"Updating message for {product_name} - {conjunta_id}")
|
logging.info(f"Updating message for {product_name} - {conjunta_id} in vip group")
|
||||||
try:
|
try:
|
||||||
await context.bot.edit_message_caption(chat_id=vip_group_chat_id, message_id=message_id_vip, caption=message, parse_mode=ParseMode.HTML)
|
await context.bot.edit_message_caption(chat_id=vip_group_chat_id, message_id=message_id_vip, caption=message, parse_mode=ParseMode.HTML)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -446,7 +448,7 @@ async def update_conjunta(update: Update, context: CallbackContext, conjunta_id)
|
|||||||
|
|
||||||
if int(message_id_general) != 0: # si existe un mensaje en el chat general, comprobamos y actualizamos
|
if int(message_id_general) != 0: # si existe un mensaje en el chat general, comprobamos y actualizamos
|
||||||
if (int(time.time()) - int(message_date)) < (24 * 3600 * 2): # borramos el mensaje si tiene más de 1 día
|
if (int(time.time()) - int(message_date)) < (24 * 3600 * 2): # borramos el mensaje si tiene más de 1 día
|
||||||
logging.info(f"Updating message for {product_name} - {conjunta_id}")
|
logging.info(f"Updating message for {product_name} - {conjunta_id} in general group")
|
||||||
try:
|
try:
|
||||||
await context.bot.edit_message_caption(chat_id=general_group_chat_id, message_id=message_id_general, caption=message, parse_mode=ParseMode.HTML)
|
await context.bot.edit_message_caption(chat_id=general_group_chat_id, message_id=message_id_general, caption=message, parse_mode=ParseMode.HTML)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -476,10 +478,8 @@ async def handle_conjunta(update: Update, context: CallbackContext):
|
|||||||
logging.info(f"{user_name} replied to message {reply_message_id} in group {group_id}")
|
logging.info(f"{user_name} replied to message {reply_message_id} in group {group_id}")
|
||||||
|
|
||||||
if group_id == int(general_group_chat_id):
|
if group_id == int(general_group_chat_id):
|
||||||
logging.info(f"Retrieving data for general group")
|
|
||||||
cursor.execute("SELECT id, message_id_general, message_id_vip, product_name, product_description, limite, limit_per_user, price, price_member, closed, photo_id, message_date FROM conjuntas WHERE message_id_general=?", (reply_message_id,))
|
cursor.execute("SELECT id, message_id_general, message_id_vip, product_name, product_description, limite, limit_per_user, price, price_member, closed, photo_id, message_date FROM conjuntas WHERE message_id_general=?", (reply_message_id,))
|
||||||
elif group_id == int(vip_group_chat_id):
|
elif group_id == int(vip_group_chat_id):
|
||||||
logging.info(f"Retrieving data for vip group")
|
|
||||||
cursor.execute("SELECT id, message_id_general, message_id_vip, product_name, product_description, limite, limit_per_user, price, price_member, closed, photo_id, message_date FROM conjuntas WHERE message_id_vip=?", (reply_message_id,))
|
cursor.execute("SELECT id, message_id_general, message_id_vip, product_name, product_description, limite, limit_per_user, price, price_member, closed, photo_id, message_date FROM conjuntas WHERE message_id_vip=?", (reply_message_id,))
|
||||||
|
|
||||||
conjunta = cursor.fetchone()
|
conjunta = cursor.fetchone()
|
||||||
@@ -502,7 +502,7 @@ async def handle_conjunta(update: Update, context: CallbackContext):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
worksheet = spreadsheet.worksheet(f"{product_name} - {conjunta_id}")
|
worksheet = spreadsheet.worksheet(f"{product_name} - {conjunta_id}")
|
||||||
found_cell = worksheet.find(user_name)
|
found_cell = worksheet.find(user_name, case_sensitive=False)
|
||||||
if found_cell:
|
if found_cell:
|
||||||
worksheet.delete_rows(found_cell.row)
|
worksheet.delete_rows(found_cell.row)
|
||||||
|
|
||||||
@@ -545,7 +545,7 @@ async def handle_conjunta(update: Update, context: CallbackContext):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
socios_worksheet = spreadsheet.worksheet("Socios")
|
socios_worksheet = spreadsheet.worksheet("Socios")
|
||||||
socio = socios_worksheet.find(user_name)
|
socio = socios_worksheet.find(user_name, case_sensitive=False)
|
||||||
|
|
||||||
worksheet = spreadsheet.worksheet(f"{product_name} - {conjunta_id}")
|
worksheet = spreadsheet.worksheet(f"{product_name} - {conjunta_id}")
|
||||||
worksheet.append_row([user_name, quantity, "SÍ" if socio else "NO"])
|
worksheet.append_row([user_name, quantity, "SÍ" if socio else "NO"])
|
||||||
@@ -576,7 +576,7 @@ async def handle_conjunta(update: Update, context: CallbackContext):
|
|||||||
logging.error(f"Error handling message: {e}")
|
logging.error(f"Error handling message: {e}")
|
||||||
|
|
||||||
async def close_conjunta(update: Update, context: CallbackContext):
|
async def close_conjunta(update: Update, context: CallbackContext):
|
||||||
user_id = update.effective_user.id
|
message_user_id = update.effective_user.id
|
||||||
query = update.callback_query
|
query = update.callback_query
|
||||||
await query.answer(text="Cerrando conjunta")
|
await query.answer(text="Cerrando conjunta")
|
||||||
await query.edit_message_reply_markup(None)
|
await query.edit_message_reply_markup(None)
|
||||||
@@ -589,10 +589,11 @@ async def close_conjunta(update: Update, context: CallbackContext):
|
|||||||
if conjunta:
|
if conjunta:
|
||||||
conjunta_id, message_id_general, message_id_vip, product_name, product_description, limit, limit_per_user, price, price_member, closed, photo_id, message_date = conjunta
|
conjunta_id, message_id_general, message_id_vip, product_name, product_description, limit, limit_per_user, price, price_member, closed, photo_id, message_date = conjunta
|
||||||
|
|
||||||
if user_id in admin_ids:
|
if message_user_id in admin_ids:
|
||||||
cursor.execute("UPDATE conjuntas SET closed=1 WHERE id=?", (conjunta_id,))
|
cursor.execute("UPDATE conjuntas SET closed=1 WHERE id=?", (conjunta_id,))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
message = f"La conjunta para <b>{product_name}</b> ha sido cerrada.\n"
|
message = f"La conjunta para <b>{product_name}</b> ha sido cerrada.\n"
|
||||||
|
message_public = f"La conjunta para <b>{product_name}</b> ha sido cerrada.\n"
|
||||||
message += f"La lista de apuntados es la siguiente:\n\n<code>"
|
message += f"La lista de apuntados es la siguiente:\n\n<code>"
|
||||||
|
|
||||||
cursor.execute("SELECT * FROM conjunta_users WHERE conjunta_id = ?", (conjunta_id,))
|
cursor.execute("SELECT * FROM conjunta_users WHERE conjunta_id = ?", (conjunta_id,))
|
||||||
@@ -607,22 +608,24 @@ async def close_conjunta(update: Update, context: CallbackContext):
|
|||||||
message += f"\n💰 Precio para socios: <b>{price_member}€</b>\n"
|
message += f"\n💰 Precio para socios: <b>{price_member}€</b>\n"
|
||||||
message += f"💰 Precio para NO socios: <b>{price}€</b>\n"
|
message += f"💰 Precio para NO socios: <b>{price}€</b>\n"
|
||||||
|
|
||||||
await context.bot.send_message(chat_id=vip_group_chat_id, text=message, parse_mode=ParseMode.HTML)
|
await context.bot.send_message(chat_id=vip_group_chat_id, text=message_public, parse_mode=ParseMode.HTML)
|
||||||
|
|
||||||
# Desanclamos el mensaje del grupo vip
|
# Desanclamos el mensaje del grupo vip
|
||||||
await context.bot.unpin_chat_message(vip_group_chat_id, message_id_vip)
|
await context.bot.unpin_chat_message(vip_group_chat_id, message_id_vip)
|
||||||
|
|
||||||
if message_id_general != 0:
|
if message_id_general != 0:
|
||||||
await context.bot.send_message(chat_id=general_group_chat_id, text=message, parse_mode=ParseMode.HTML)
|
await context.bot.send_message(chat_id=general_group_chat_id, text=message_public, parse_mode=ParseMode.HTML)
|
||||||
|
|
||||||
# Desanclamos el mensaje del grupo general
|
# Desanclamos el mensaje del grupo general
|
||||||
await context.bot.unpin_chat_message(general_group_chat_id, message_id_general)
|
await context.bot.unpin_chat_message(general_group_chat_id, message_id_general)
|
||||||
|
|
||||||
await context.bot.send_message(chat_id=user_id, text=f"La conjunta para {product_name} ha sido cerrada correctamente.")
|
await context.bot.send_message(chat_id=message_user_id, text=f"La conjunta para {product_name} ha sido cerrada correctamente.")
|
||||||
|
|
||||||
|
send_message_to_admins(message)
|
||||||
else:
|
else:
|
||||||
await context.bot.send_message(chat_id=user_id, text="Solo el administrador puede cerrar la conjunta.")
|
await context.bot.send_message(chat_id=message_user_id, text="Solo el administrador puede cerrar la conjunta.")
|
||||||
else:
|
else:
|
||||||
await context.bot.send_message(chat_id=user_id, text="La conjunta no existe.")
|
await context.bot.send_message(chat_id=message_user_id, text="La conjunta no existe.")
|
||||||
|
|
||||||
async def general_conjunta(update: Update, context: CallbackContext):
|
async def general_conjunta(update: Update, context: CallbackContext):
|
||||||
user_id = update.effective_user.id
|
user_id = update.effective_user.id
|
||||||
@@ -732,7 +735,8 @@ async def show_conjunta_details(update: Update, context: CallbackContext):
|
|||||||
url = spreadsheet.worksheet(f"{product_name} - {conjunta_id}").url
|
url = spreadsheet.worksheet(f"{product_name} - {conjunta_id}").url
|
||||||
selected_conjunta_details += f"\n<a href='{url}'>💻 URL en Google Sheets</a>\n"
|
selected_conjunta_details += f"\n<a href='{url}'>💻 URL en Google Sheets</a>\n"
|
||||||
|
|
||||||
await context.bot.send_photo(chat_id=update.effective_chat.id, photo=photo_id, caption=selected_conjunta_details, parse_mode=ParseMode.HTML)
|
await context.bot.send_photo(chat_id=update.effective_chat.id, photo=photo_id, caption=product_name, parse_mode=ParseMode.HTML)
|
||||||
|
await context.bot.send_message(chat_id=update.effective_chat.id, text=selected_conjunta_details, parse_mode=ParseMode.HTML)
|
||||||
|
|
||||||
# Función para enviar un mensaje a todos los administradores
|
# Función para enviar un mensaje a todos los administradores
|
||||||
async def send_message_to_admins(update: Update, context: CallbackContext, message):
|
async def send_message_to_admins(update: Update, context: CallbackContext, message):
|
||||||
|
|||||||
Reference in New Issue
Block a user