Added a couple of lines of code...
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,2 @@
|
|||||||
.env
|
.env
|
||||||
/data/db/*
|
/data/*
|
||||||
@@ -3,12 +3,14 @@ import sqlite3
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
|
import gspread
|
||||||
|
|
||||||
from telegram import Update, ReplyKeyboardMarkup
|
from oauth2client.service_account import ServiceAccountCredentials
|
||||||
from telegram.ext import Application, CommandHandler, MessageHandler, filters, ConversationHandler, CallbackContext
|
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
||||||
|
from telegram.ext import Application, CommandHandler, MessageHandler, filters, ConversationHandler, CallbackContext, CallbackQueryHandler
|
||||||
from telegram.constants import ParseMode
|
from telegram.constants import ParseMode
|
||||||
|
|
||||||
PRODUCT_NAME, PRODUCT_DESCRIPTION, PRODUCT_IMAGE, LIMIT, LIMIT_PER_USER, UNLIMITED, LIMITED = range(7)
|
PRODUCT_NAME, PRODUCT_DESCRIPTION, PRICE_MEMBER, PRICE, PRODUCT_IMAGE, LIMIT, LIMIT_PER_USER, UNLIMITED, LIMITED = range(9)
|
||||||
|
|
||||||
# Enable logging
|
# Enable logging
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
@@ -24,6 +26,7 @@ httpx_logger.setLevel(logging.WARNING)
|
|||||||
admin_ids = [int(admin_id) for admin_id in os.environ.get("ADMIN_IDS", "").split(",")]
|
admin_ids = [int(admin_id) for admin_id in os.environ.get("ADMIN_IDS", "").split(",")]
|
||||||
group_chat_id = os.environ.get("GROUP_CHAT_ID")
|
group_chat_id = os.environ.get("GROUP_CHAT_ID")
|
||||||
bot_token = os.environ.get("TELEGRAM_TOKEN")
|
bot_token = os.environ.get("TELEGRAM_TOKEN")
|
||||||
|
spreadsheet_id = os.environ.get("SPREADSHEET_ID")
|
||||||
|
|
||||||
# Configura la base de datos SQLite
|
# Configura la base de datos SQLite
|
||||||
conn = sqlite3.connect('/app/data/db/conjuntas.db')
|
conn = sqlite3.connect('/app/data/db/conjuntas.db')
|
||||||
@@ -35,6 +38,8 @@ cursor.execute('''CREATE TABLE IF NOT EXISTS conjuntas (
|
|||||||
product_description TEXT,
|
product_description TEXT,
|
||||||
limite INTEGER,
|
limite INTEGER,
|
||||||
limit_per_user INTEGER,
|
limit_per_user INTEGER,
|
||||||
|
price INTEGER,
|
||||||
|
price_member INTEGER,
|
||||||
closed INTEGER,
|
closed INTEGER,
|
||||||
photo_id TEXT
|
photo_id TEXT
|
||||||
)''')
|
)''')
|
||||||
@@ -49,6 +54,17 @@ cursor.execute('''CREATE TABLE IF NOT EXISTS conjunta_users (
|
|||||||
)''')
|
)''')
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
# Configuramos API de Google Sheets
|
||||||
|
|
||||||
|
json_keyfile = '/app/data/creds.json'
|
||||||
|
scopes = [
|
||||||
|
'https://www.googleapis.com/auth/spreadsheets',
|
||||||
|
'https://www.googleapis.com/auth/drive'
|
||||||
|
]
|
||||||
|
creds = ServiceAccountCredentials.from_json_keyfile_name(json_keyfile, scopes)
|
||||||
|
client = gspread.authorize(creds)
|
||||||
|
spreadsheet = client.open_by_key(spreadsheet_id)
|
||||||
|
|
||||||
async def list_conjuntas(update: Update, context: CallbackContext):
|
async def list_conjuntas(update: Update, context: CallbackContext):
|
||||||
chat_id = update.message.chat_id
|
chat_id = update.message.chat_id
|
||||||
cursor.execute("SELECT * FROM conjuntas WHERE closed=0")
|
cursor.execute("SELECT * FROM conjuntas WHERE closed=0")
|
||||||
@@ -57,7 +73,7 @@ async def list_conjuntas(update: Update, context: CallbackContext):
|
|||||||
if conjuntas:
|
if conjuntas:
|
||||||
for conjunta in conjuntas:
|
for conjunta in conjuntas:
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
conjunta_id, message_id, product_name, product_description, limit, limit_per_user, closed, photo_id = conjunta
|
conjunta_id, message_id, product_name, product_description, limit, limit_per_user, price, price_member, closed, photo_id = conjunta
|
||||||
caption = f"Conjunta para '{product_name}'\n"
|
caption = f"Conjunta para '{product_name}'\n"
|
||||||
cursor.execute("SELECT COUNT(*) FROM conjunta_users WHERE conjunta_id = ?", (conjunta[0],))
|
cursor.execute("SELECT COUNT(*) FROM conjunta_users WHERE conjunta_id = ?", (conjunta[0],))
|
||||||
users = cursor.fetchone()
|
users = cursor.fetchone()
|
||||||
@@ -101,6 +117,34 @@ async def product_description(update: Update, context: CallbackContext):
|
|||||||
|
|
||||||
context.user_data['product_description'] = product_description
|
context.user_data['product_description'] = product_description
|
||||||
|
|
||||||
|
await update.message.reply_text("Envía el precio para SOCIOS.")
|
||||||
|
|
||||||
|
return PRICE_MEMBER
|
||||||
|
|
||||||
|
# Función para manejar el precio para socios del producto
|
||||||
|
async def product_price_member(update: Update, context: CallbackContext):
|
||||||
|
price_member = update.message.text
|
||||||
|
|
||||||
|
try:
|
||||||
|
context.user_data['price_member'] = int(price_member)
|
||||||
|
except ValueError:
|
||||||
|
await update.message.reply_text("Envía un número, por favor.")
|
||||||
|
return PRICE_MEMBER
|
||||||
|
|
||||||
|
await update.message.reply_text("Envía el precio para NO socios.")
|
||||||
|
|
||||||
|
return PRICE
|
||||||
|
|
||||||
|
# Función para manejar el precio para no socios del producto
|
||||||
|
async def product_price(update: Update, context: CallbackContext):
|
||||||
|
price = update.message.text
|
||||||
|
|
||||||
|
try:
|
||||||
|
context.user_data['price'] = int(price)
|
||||||
|
except ValueError:
|
||||||
|
await update.message.reply_text("Envía un número, por favor.")
|
||||||
|
return PRICE
|
||||||
|
|
||||||
await update.message.reply_text("Envía una foto para esta conjunta.")
|
await update.message.reply_text("Envía una foto para esta conjunta.")
|
||||||
|
|
||||||
return PRODUCT_IMAGE
|
return PRODUCT_IMAGE
|
||||||
@@ -163,15 +207,22 @@ async def add_and_send(update: Update, context: CallbackContext, message):
|
|||||||
limit_per_user = context.user_data['limit_per_user']
|
limit_per_user = context.user_data['limit_per_user']
|
||||||
photo_id = context.user_data['photo_id']
|
photo_id = context.user_data['photo_id']
|
||||||
product_description = context.user_data['product_description']
|
product_description = context.user_data['product_description']
|
||||||
|
price = context.user_data['price']
|
||||||
|
price_member = context.user_data['price_member']
|
||||||
|
|
||||||
sent_message = await context.bot.send_photo(group_chat_id, photo=photo_id, caption=message)
|
sent_message = await context.bot.send_photo(group_chat_id, photo=photo_id, caption=message)
|
||||||
|
|
||||||
cursor.execute("INSERT INTO conjuntas (message_id, product_name, product_description, limite, limit_per_user, closed, photo_id) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
cursor.execute("INSERT INTO conjuntas (message_id, product_name, product_description, price, price_member, limite, limit_per_user, closed, photo_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
(sent_message.message_id, product_name, product_description, limit, limit_per_user, 0, photo_id))
|
(sent_message.message_id, product_name, product_description, price, price_member, limit, limit_per_user, 0, photo_id))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
conjunta_id = cursor.lastrowid
|
conjunta_id = cursor.lastrowid
|
||||||
|
|
||||||
|
# Creamos una nueva hoja en el documento
|
||||||
|
worksheet = spreadsheet.add_worksheet(title=f"{product_name} - {conjunta_id}", rows=1, cols=3)
|
||||||
|
#worksheet.update(values = [2, 5, 3], range_name = "A1:C1")
|
||||||
|
worksheet.append_row(["Usuario", "Cantidad", "Socio"])
|
||||||
|
|
||||||
# Anclar el mensaje en el grupo
|
# Anclar el mensaje en el grupo
|
||||||
await context.bot.pin_chat_message(group_chat_id, sent_message.message_id)
|
await context.bot.pin_chat_message(group_chat_id, sent_message.message_id)
|
||||||
await update_conjunta(update, context, conjunta_id)
|
await update_conjunta(update, context, conjunta_id)
|
||||||
@@ -222,19 +273,33 @@ async def update_conjunta(update: Update, context: CallbackContext, conjunta_id)
|
|||||||
conjunta = cursor.fetchone()
|
conjunta = cursor.fetchone()
|
||||||
|
|
||||||
if conjunta:
|
if conjunta:
|
||||||
conjunta_id, message_id, product_name, product_description, limit, limit_per_user, closed, photo_id = conjunta
|
conjunta_id, message_id, product_name, product_description, limit, limit_per_user, price, price_member, closed, photo_id = conjunta
|
||||||
|
|
||||||
|
message = f"Conjunta para 🛒 <b>{product_name}</b>\n\n"
|
||||||
if limit:
|
if limit:
|
||||||
message = f"Conjunta para <b>{product_name}</b> con un límite de <b>{limit}</b> productos y <b>{limit_per_user}</b> por usuario.\n"
|
message += f"#️⃣ Límite de <b>{limit}</b> productos.\n"
|
||||||
|
message += f"#️⃣ Límite de <b>{limit_per_user}</b> por usuario.\n"
|
||||||
left = quantity_left(conjunta_id)
|
left = quantity_left(conjunta_id)
|
||||||
if left == 0:
|
if left == 0:
|
||||||
message += f"\nYa no quedan productos disponibles.\n"
|
message += f"\n❌ Ya no quedan productos disponibles.\n"
|
||||||
else:
|
else:
|
||||||
message += f"\nTodavía quedan <b>{left}</b> productos disponibles.\n"
|
message += f"\n✅ Todavía quedan <b>{left}</b> productos disponibles.\n"
|
||||||
else:
|
else:
|
||||||
message = f"Conjunta para <b>{product_name}</b> sin límite de cantidad.\n"
|
message = f"✅ No hay límite de productos por usuario.\n"
|
||||||
message += f"\n{product_description}\n\n"
|
message += f"\n🗒️ {product_description}\n"
|
||||||
message += f"Puedes unirte respondiendo a este mensaje con <code>me apunto {{cantidad}}</code>, en números.\nPara borrarte responde a este mensaje y di <code>me borro</code>."
|
message += f"\n💰 Precio para socios: <b>{price_member}€</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"Para borrarte responde a este mensaje y di <code>me borro</code>.\n"
|
||||||
|
|
||||||
|
cursor.execute("SELECT * FROM conjunta_users WHERE conjunta_id=?", (conjunta_id,))
|
||||||
|
users = cursor.fetchall()
|
||||||
|
|
||||||
|
if users:
|
||||||
|
message += f"\n🧍 Lista de apuntados:\n\n"
|
||||||
|
for user in users:
|
||||||
|
id, conjunta_id, user_id, user_name, quantity = user
|
||||||
|
message += f"@{user_name} - {quantity} unidades\n"
|
||||||
|
|
||||||
await context.bot.edit_message_caption(chat_id=group_chat_id, message_id=message_id, caption=message, parse_mode=ParseMode.HTML)
|
await context.bot.edit_message_caption(chat_id=group_chat_id, message_id=message_id, caption=message, parse_mode=ParseMode.HTML)
|
||||||
|
|
||||||
@@ -250,7 +315,7 @@ async def handle_conjunta(update: Update, context: CallbackContext):
|
|||||||
conjunta = cursor.fetchone()
|
conjunta = cursor.fetchone()
|
||||||
|
|
||||||
if conjunta:
|
if conjunta:
|
||||||
conjunta_id, message_id, product_name, product_description, limit, limit_per_user, closed, photo_id = conjunta
|
conjunta_id, message_id, product_name, product_description, limit, limit_per_user, price, price_member, closed, photo_id = conjunta
|
||||||
|
|
||||||
regex_borrar = r'\b(?!apunto)(desapunto|borro|desapuntar|borrar)\b'
|
regex_borrar = r'\b(?!apunto)(desapunto|borro|desapuntar|borrar)\b'
|
||||||
regex_apuntar = r'\b(apunto|me uno)\b'
|
regex_apuntar = r'\b(apunto|me uno)\b'
|
||||||
@@ -264,6 +329,12 @@ async def handle_conjunta(update: Update, context: CallbackContext):
|
|||||||
if user_conjunta:
|
if user_conjunta:
|
||||||
cursor.execute("DELETE FROM conjunta_users WHERE id = ?", (user_conjunta[0],))
|
cursor.execute("DELETE FROM conjunta_users WHERE id = ?", (user_conjunta[0],))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
worksheet = spreadsheet.worksheet(f"{product_name} - {conjunta_id}")
|
||||||
|
found_cell = worksheet.find(user_name)
|
||||||
|
if found_cell:
|
||||||
|
worksheet.delete_rows(found_cell.row)
|
||||||
|
|
||||||
await update.message.reply_text("¡Desapuntado de la conjunta!")
|
await update.message.reply_text("¡Desapuntado de la conjunta!")
|
||||||
try:
|
try:
|
||||||
await update_conjunta(update, context, conjunta_id)
|
await update_conjunta(update, context, conjunta_id)
|
||||||
@@ -299,6 +370,13 @@ async def handle_conjunta(update: Update, context: CallbackContext):
|
|||||||
cursor.execute("INSERT INTO conjunta_users (conjunta_id, user_id, user_name, quantity) VALUES (?, ?, ?, ?)",
|
cursor.execute("INSERT INTO conjunta_users (conjunta_id, user_id, user_name, quantity) VALUES (?, ?, ?, ?)",
|
||||||
(conjunta_id, user_id, user_name, quantity))
|
(conjunta_id, user_id, user_name, quantity))
|
||||||
conn.commit()
|
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.")
|
await update.message.reply_text(f"Te has unido a la conjunta para '{product_name}' con {quantity} unidades.")
|
||||||
try:
|
try:
|
||||||
await update_conjunta(update, context, conjunta_id)
|
await update_conjunta(update, context, conjunta_id)
|
||||||
@@ -313,14 +391,13 @@ async def handle_conjunta(update: Update, context: CallbackContext):
|
|||||||
# Función para consultar el estado de una conjunta
|
# Función para consultar el estado de una conjunta
|
||||||
async def status_conjunta(update: Update, context: CallbackContext):
|
async def status_conjunta(update: Update, context: CallbackContext):
|
||||||
user_id = update.effective_user.id
|
user_id = update.effective_user.id
|
||||||
chat_id = update.message.chat_id
|
|
||||||
conjunta_id = context.args[0]
|
conjunta_id = context.args[0]
|
||||||
|
|
||||||
cursor.execute("SELECT * FROM conjuntas WHERE id=?", (conjunta_id,))
|
cursor.execute("SELECT * FROM conjuntas WHERE id=?", (conjunta_id,))
|
||||||
conjunta = cursor.fetchone()
|
conjunta = cursor.fetchone()
|
||||||
|
|
||||||
if conjunta:
|
if conjunta:
|
||||||
conjunta_id, message_id, product_name, product_description, limit, limit_per_user, closed, photo_id = conjunta
|
conjunta_id, message_id, product_name, product_description, limit, limit_per_user, price, price_member, closed, photo_id = conjunta
|
||||||
|
|
||||||
cursor.execute("SELECT * FROM conjunta_users WHERE conjunta_id=?", (conjunta_id,))
|
cursor.execute("SELECT * FROM conjunta_users WHERE conjunta_id=?", (conjunta_id,))
|
||||||
users_data = cursor.fetchall()
|
users_data = cursor.fetchall()
|
||||||
@@ -341,25 +418,43 @@ async def status_conjunta(update: Update, context: CallbackContext):
|
|||||||
|
|
||||||
async def close_conjunta(update: Update, context: CallbackContext):
|
async def close_conjunta(update: Update, context: CallbackContext):
|
||||||
user_id = update.effective_user.id
|
user_id = update.effective_user.id
|
||||||
conjunta_id = context.args[0]
|
query = update.callback_query
|
||||||
|
await query.answer(text="Cerrando conjunta")
|
||||||
|
|
||||||
|
conjunta_id = int(query.data.split("close ")[1])
|
||||||
|
|
||||||
cursor.execute("SELECT * FROM conjuntas WHERE id=?", (conjunta_id,))
|
cursor.execute("SELECT * FROM conjuntas WHERE id=?", (conjunta_id,))
|
||||||
conjunta = cursor.fetchone()
|
conjunta = cursor.fetchone()
|
||||||
|
|
||||||
if conjunta:
|
if conjunta:
|
||||||
conjunta_id, message_id, product_name, product_description, limit, limit_per_user, closed, photo_id = conjunta
|
conjunta_id, message_id, product_name, product_description, limit, limit_per_user, price, price_member, closed, photo_id = conjunta
|
||||||
|
|
||||||
if user_id in admin_ids:
|
if 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()
|
||||||
await update.message.reply_text(f"La conjunta para '{product_name}' ha sido cerrada.")
|
message = f"La conjunta para <b>{product_name}</b> ha sido cerrada.\n"
|
||||||
|
message += f"La lista de apuntados es la siguiente:\n\n<code>"
|
||||||
|
|
||||||
|
cursor.execute("SELECT * FROM conjunta_users WHERE conjunta_id = ?", (conjunta_id,))
|
||||||
|
|
||||||
|
for user in cursor.fetchall():
|
||||||
|
id, conjunta_id, user_id, user_name, quantity = user
|
||||||
|
message += f"@{user_name},{quantity}\n"
|
||||||
|
|
||||||
|
message += "</code>"
|
||||||
|
|
||||||
|
message += f"\n\n🗒️ <b>{product_description}</b>\n"
|
||||||
|
message += f"\n💰 Precio para socios: <b>{price_member}€</b>\n"
|
||||||
|
message += f"💰 Precio para NO socios: <b>{price}€</b>\n"
|
||||||
|
|
||||||
|
await context.bot.send_message(chat_id=group_chat_id, text=message, parse_mode=ParseMode.HTML)
|
||||||
|
|
||||||
# Desanclamos el mensaje
|
# Desanclamos el mensaje
|
||||||
#context.bot.unpin_chat_message(chat_id)
|
await context.bot.unpin_chat_message(group_chat_id, message_id)
|
||||||
else:
|
else:
|
||||||
await update.message.reply_text("Solo el administrador puede cerrar la conjunta.")
|
await context.bot.send_message(chat_id=group_chat_id, text="Solo el administrador puede cerrar la conjunta.")
|
||||||
else:
|
else:
|
||||||
await update.message.reply_text("La conjunta no existe.")
|
await context.bot.send_message(chat_id=group_chat_id, text="La conjunta no existe.")
|
||||||
|
|
||||||
# Función para obtener un resumen de las conjuntas activas
|
# Función para obtener un resumen de las conjuntas activas
|
||||||
async def admin_summary(update: Update, context: CallbackContext):
|
async def admin_summary(update: Update, context: CallbackContext):
|
||||||
@@ -372,7 +467,7 @@ async def admin_summary(update: Update, context: CallbackContext):
|
|||||||
if conjuntas:
|
if conjuntas:
|
||||||
summary_text = "Resumen de conjuntas activas:\n\n"
|
summary_text = "Resumen de conjuntas activas:\n\n"
|
||||||
for conjunta in conjuntas:
|
for conjunta in conjuntas:
|
||||||
conjunta_id, message_id, product_name, product_description, limit, limit_per_user, closed, photo_id = conjunta
|
conjunta_id, message_id, product_name, product_description, limit, limit_per_user, price, price_member, closed, photo_id = conjunta
|
||||||
cursor.execute("SELECT COUNT(*) FROM conjunta_users WHERE conjunta_id=?", (conjunta_id,))
|
cursor.execute("SELECT COUNT(*) FROM conjunta_users WHERE conjunta_id=?", (conjunta_id,))
|
||||||
num_users = cursor.fetchone()[0]
|
num_users = cursor.fetchone()[0]
|
||||||
cursor.execute("SELECT quantity FROM conjunta_users WHERE conjunta_id=?", (conjunta_id,))
|
cursor.execute("SELECT quantity FROM conjunta_users WHERE conjunta_id=?", (conjunta_id,))
|
||||||
@@ -380,10 +475,12 @@ async def admin_summary(update: Update, context: CallbackContext):
|
|||||||
if num_users:
|
if num_users:
|
||||||
for quantity in cursor.fetchall():
|
for quantity in cursor.fetchall():
|
||||||
total_quantity += quantity[0]
|
total_quantity += quantity[0]
|
||||||
summary_text += f"ID: <b>{conjunta_id}</b>\n"
|
summary_text += f"🛒 <b>{product_name} ({conjunta_id})</b>\n"
|
||||||
summary_text += f"Producto: <b>{product_name}</b>\n"
|
summary_text += f"🧍 Usuarios apuntados: <b>{num_users}</b>\n"
|
||||||
summary_text += f"Usuarios apuntados: <b>{num_users}</b>\n"
|
if limit:
|
||||||
summary_text += f"Cantidad total de productos pedidos: <b>{total_quantity}</b>\n"
|
summary_text += f"#️⃣ Límite: <b>{limit}</b>\n"
|
||||||
|
summary_text += f"#️⃣ Límite por usuario: <b>{limit_per_user}</b>\n"
|
||||||
|
summary_text += f"🔢 Cantidad total de productos pedidos: <b>{total_quantity}</b>\n"
|
||||||
summary_text += f"\n--------------------------------------\n\n"
|
summary_text += f"\n--------------------------------------\n\n"
|
||||||
|
|
||||||
await update.message.reply_text(summary_text, parse_mode=ParseMode.HTML)
|
await update.message.reply_text(summary_text, parse_mode=ParseMode.HTML)
|
||||||
@@ -391,9 +488,15 @@ async def admin_summary(update: Update, context: CallbackContext):
|
|||||||
|
|
||||||
# Agregar botones para seleccionar una conjunta
|
# Agregar botones para seleccionar una conjunta
|
||||||
keyboard = []
|
keyboard = []
|
||||||
|
conjuntas_line = []
|
||||||
|
count = 0
|
||||||
for conjunta in conjuntas:
|
for conjunta in conjuntas:
|
||||||
keyboard.append([str(conjunta[0])])
|
conjunta_id, message_id, product_name, product_description, limit, limit_per_user, price, price_member, closed, photo_id = conjunta
|
||||||
reply_markup = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True)
|
conjuntas_line.append(InlineKeyboardButton(f"ℹ️ {product_name} ({str(conjunta_id)})", callback_data=f"info {str(conjunta_id)}"))
|
||||||
|
conjuntas_line.append(InlineKeyboardButton(f"❌ {product_name} ({str(conjunta_id)})", callback_data=f"close {str(conjunta_id)}"))
|
||||||
|
keyboard.append(conjuntas_line)
|
||||||
|
conjuntas_line = []
|
||||||
|
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||||
await update.message.reply_text("Selecciona una conjunta para ver más detalles.", reply_markup=reply_markup)
|
await update.message.reply_text("Selecciona una conjunta para ver más detalles.", reply_markup=reply_markup)
|
||||||
else:
|
else:
|
||||||
await update.message.reply_text("No hay conjuntas activas en este grupo.")
|
await update.message.reply_text("No hay conjuntas activas en este grupo.")
|
||||||
@@ -402,29 +505,33 @@ async def admin_summary(update: Update, context: CallbackContext):
|
|||||||
|
|
||||||
# Función para mostrar detalles de una conjunta seleccionada
|
# Función para mostrar detalles de una conjunta seleccionada
|
||||||
async def show_conjunta_details(update: Update, context: CallbackContext):
|
async def show_conjunta_details(update: Update, context: CallbackContext):
|
||||||
if "conjuntas" in context.user_data:
|
query = update.callback_query
|
||||||
selected_conjunta_idx = int(update.message.text)
|
await query.answer(text="Mostrando detalles")
|
||||||
|
|
||||||
|
selected_conjunta_idx = int(query.data.split("info ")[1])
|
||||||
|
|
||||||
cursor.execute("SELECT * FROM conjuntas WHERE id = ?", (selected_conjunta_idx,))
|
cursor.execute("SELECT * FROM conjuntas WHERE id = ?", (selected_conjunta_idx,))
|
||||||
conjunta = cursor.fetchone()
|
conjunta = cursor.fetchone()
|
||||||
conjunta_id, message_id, product_name, product_description, limit, limit_per_user, closed, photo_id = conjunta
|
conjunta_id, message_id, product_name, product_description, limit, limit_per_user, price, price_member, closed, photo_id = conjunta
|
||||||
|
|
||||||
selected_conjunta_details = f"Detalles de la conjunta seleccionada:\n"
|
selected_conjunta_details = f"Detalles de la conjunta seleccionada:\n"
|
||||||
selected_conjunta_details += f"Producto: <b>{product_name}</b>\n"
|
selected_conjunta_details += f"🛒 <b>{product_name}</b>\n"
|
||||||
selected_conjunta_details += f"Descripción: <b>{product_description}</b>\n"
|
selected_conjunta_details += f"🗒️ <b>{product_description}</b>\n"
|
||||||
if limit:
|
if limit:
|
||||||
selected_conjunta_details += f"Límite total: <b>{limit}</b>\n"
|
selected_conjunta_details += f"#️⃣ Límite: <b>{limit}</b>\n"
|
||||||
selected_conjunta_details += f"Límite por usuario: <b>{limit_per_user}</b>\n"
|
selected_conjunta_details += f"#️⃣ Límite por usuario: <b>{limit_per_user}</b>\n"
|
||||||
|
selected_conjunta_details += f"💰 Precio para socios: <b>{price_member}€</b>\n"
|
||||||
|
selected_conjunta_details += f"💰 Precio para NO socios: <b>{price}€</b>\n"
|
||||||
|
|
||||||
cursor.execute("SELECT * FROM conjunta_users WHERE conjunta_id = ?", (conjunta_id,))
|
cursor.execute("SELECT * FROM conjunta_users WHERE conjunta_id = ?", (conjunta_id,))
|
||||||
|
|
||||||
selected_conjunta_details += f"Apuntados:\n\n-----------------------\n"
|
selected_conjunta_details += f"\n🧍 Usuarios apuntados:\n\n-----------------------\n"
|
||||||
for user in cursor.fetchall():
|
for user in cursor.fetchall():
|
||||||
id, conjunta_id, user_id, user_name, quantity = user
|
id, conjunta_id, user_id, user_name, quantity = user
|
||||||
selected_conjunta_details += f"@{user_name},{quantity}\n"
|
selected_conjunta_details += f"@{user_name},{quantity}\n"
|
||||||
selected_conjunta_details += "-----------------------"
|
selected_conjunta_details += "-----------------------"
|
||||||
|
|
||||||
await update.message.reply_photo(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=selected_conjunta_details, parse_mode=ParseMode.HTML)
|
||||||
|
|
||||||
def main()->None:
|
def main()->None:
|
||||||
application = Application.builder().get_updates_http_version('1.1').http_version('1.1').token(bot_token).build()
|
application = Application.builder().get_updates_http_version('1.1').http_version('1.1').token(bot_token).build()
|
||||||
@@ -434,6 +541,8 @@ def main()->None:
|
|||||||
states={
|
states={
|
||||||
PRODUCT_NAME: [MessageHandler(filters.TEXT, product_name)],
|
PRODUCT_NAME: [MessageHandler(filters.TEXT, product_name)],
|
||||||
PRODUCT_DESCRIPTION: [MessageHandler(filters.TEXT, product_description)],
|
PRODUCT_DESCRIPTION: [MessageHandler(filters.TEXT, product_description)],
|
||||||
|
PRICE_MEMBER: [MessageHandler(filters.TEXT, product_price_member)],
|
||||||
|
PRICE: [MessageHandler(filters.TEXT, product_price)],
|
||||||
PRODUCT_IMAGE: [MessageHandler(filters.PHOTO, product_image)],
|
PRODUCT_IMAGE: [MessageHandler(filters.PHOTO, product_image)],
|
||||||
LIMIT: [MessageHandler(filters.TEXT, limit)],
|
LIMIT: [MessageHandler(filters.TEXT, limit)],
|
||||||
LIMIT_PER_USER: [MessageHandler(filters.TEXT, limit_per_user)],
|
LIMIT_PER_USER: [MessageHandler(filters.TEXT, limit_per_user)],
|
||||||
@@ -445,13 +554,15 @@ def main()->None:
|
|||||||
|
|
||||||
application.add_handler(conv_handler)
|
application.add_handler(conv_handler)
|
||||||
application.add_handler(CommandHandler('status', status_conjunta))
|
application.add_handler(CommandHandler('status', status_conjunta))
|
||||||
application.add_handler(CommandHandler('close', close_conjunta))
|
application.add_handler(CallbackQueryHandler(close_conjunta, pattern="close \d"))
|
||||||
application.add_handler(CommandHandler('list', list_conjuntas))
|
application.add_handler(CommandHandler('list', list_conjuntas))
|
||||||
application.add_handler(CommandHandler('admin_summary', admin_summary))
|
application.add_handler(CommandHandler('admin_summary', admin_summary))
|
||||||
application.add_handler(MessageHandler(filters.TEXT & filters.Regex(r'^\d+$'), show_conjunta_details))
|
application.add_handler(CallbackQueryHandler(show_conjunta_details, pattern="info \d"))
|
||||||
application.add_handler(MessageHandler(filters.REPLY, handle_conjunta))
|
application.add_handler(MessageHandler(filters.REPLY, handle_conjunta))
|
||||||
|
|
||||||
application.run_polling()
|
application.run_polling()
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
python-telegram-bot==20.4
|
python-telegram-bot==20.4
|
||||||
|
gspread==5.12.0
|
||||||
|
oauth2client==4.1.3
|
||||||
@@ -18,5 +18,6 @@ services:
|
|||||||
- NR_HOST_METRICS=${NR_HOST_METRICS}
|
- NR_HOST_METRICS=${NR_HOST_METRICS}
|
||||||
- ADMIN_IDS=${ADMIN_IDS}
|
- ADMIN_IDS=${ADMIN_IDS}
|
||||||
- GROUP_CHAT_ID=${GROUP_CHAT_ID}
|
- GROUP_CHAT_ID=${GROUP_CHAT_ID}
|
||||||
|
- SPREADSHEET_ID=${SPREADSHEET_ID}
|
||||||
dns:
|
dns:
|
||||||
- 8.8.8.8
|
- 8.8.8.8
|
||||||
Reference in New Issue
Block a user