Some fixes in database
This commit is contained in:
@@ -97,7 +97,7 @@ async def edit_conjunta(update: Update, context: CallbackContext):
|
||||
|
||||
conjunta_id = int(query.data.split("edit ")[1])
|
||||
|
||||
cursor.execute("SELECT * FROM conjuntas WHERE id=?", (conjunta_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 id=?", (conjunta_id,))
|
||||
conjunta = cursor.fetchone()
|
||||
|
||||
if conjunta:
|
||||
@@ -380,7 +380,8 @@ def quantity_left(conjunta_id):
|
||||
|
||||
# Función para actualizar la cantidad el anclado
|
||||
async def update_conjunta(update: Update, context: CallbackContext, conjunta_id):
|
||||
cursor.execute("SELECT * FROM conjuntas WHERE id=?", (conjunta_id,))
|
||||
logging.info("Updating conjunta...")
|
||||
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 id=?", (conjunta_id,))
|
||||
conjunta = cursor.fetchone()
|
||||
|
||||
if conjunta:
|
||||
@@ -413,7 +414,7 @@ async def update_conjunta(update: Update, context: CallbackContext, conjunta_id)
|
||||
# quantity_string = "unidades" if quantity > 1 else "unidad"
|
||||
# message += f"@{user_name} - {quantity} {quantity_string}\n"
|
||||
|
||||
if 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
|
||||
logging.info(f"Updating message for {product_name} - {conjunta_id}")
|
||||
try:
|
||||
@@ -438,12 +439,12 @@ async def update_conjunta(update: Update, context: CallbackContext, conjunta_id)
|
||||
# Anclar el mensaje en el grupo
|
||||
await context.bot.pin_chat_message(vip_group_chat_id, sent_message.message_id)
|
||||
|
||||
cursor.execute("UPDATE conjuntas SET message_id_general = ? WHERE id=?", (sent_message.message_id, conjunta_id))
|
||||
cursor.execute("UPDATE conjuntas SET message_id_vip = ?, message_date = ? WHERE id=?", (sent_message.message_id, int(time.time()), conjunta_id))
|
||||
conn.commit()
|
||||
|
||||
await update_conjunta(update, context, conjunta_id)
|
||||
|
||||
if 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
|
||||
logging.info(f"Updating message for {product_name} - {conjunta_id}")
|
||||
try:
|
||||
@@ -476,14 +477,15 @@ async def handle_conjunta(update: Update, context: CallbackContext):
|
||||
|
||||
if group_id == int(general_group_chat_id):
|
||||
logging.info(f"Retrieving data for general group")
|
||||
cursor.execute("SELECT * 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):
|
||||
logging.info(f"Retrieving data for vip group")
|
||||
cursor.execute("SELECT * 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()
|
||||
|
||||
if conjunta:
|
||||
logging.info("Handling message...")
|
||||
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
|
||||
|
||||
regex_borrar = r'\b(?!apunto)(desapunto|borro|desapuntar|borrar)\b'
|
||||
@@ -581,7 +583,7 @@ async def close_conjunta(update: Update, context: CallbackContext):
|
||||
|
||||
conjunta_id = int(query.data.split("close ")[1])
|
||||
|
||||
cursor.execute("SELECT * FROM conjuntas WHERE id=?", (conjunta_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 id=?", (conjunta_id,))
|
||||
conjunta = cursor.fetchone()
|
||||
|
||||
if conjunta:
|
||||
@@ -630,7 +632,7 @@ async def general_conjunta(update: Update, context: CallbackContext):
|
||||
|
||||
conjunta_id = int(query.data.split("general ")[1])
|
||||
|
||||
cursor.execute("SELECT * FROM conjuntas WHERE id=?", (conjunta_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 id=?", (conjunta_id,))
|
||||
conjunta = cursor.fetchone()
|
||||
|
||||
if conjunta:
|
||||
@@ -651,7 +653,7 @@ async def admin_summary(update: Update, context: CallbackContext):
|
||||
user_id = update.effective_user.id
|
||||
|
||||
if user_id in admin_ids:
|
||||
cursor.execute("SELECT * FROM conjuntas WHERE closed=0")
|
||||
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 closed=0")
|
||||
conjuntas = cursor.fetchall()
|
||||
|
||||
if conjuntas:
|
||||
@@ -706,7 +708,7 @@ async def show_conjunta_details(update: Update, context: CallbackContext):
|
||||
|
||||
selected_conjunta_idx = int(query.data.split("info ")[1])
|
||||
|
||||
cursor.execute("SELECT * FROM conjuntas WHERE id = ?", (selected_conjunta_idx,))
|
||||
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 id = ?", (selected_conjunta_idx,))
|
||||
conjunta = cursor.fetchone()
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user