Did some modifications...

This commit is contained in:
Joan
2025-10-29 11:14:34 +01:00
parent 8bcf8c8819
commit c012f03cb4
8 changed files with 420 additions and 168 deletions

View File

@@ -144,6 +144,41 @@ async def check_winner_numbers(context: ContextTypes.DEFAULT_TYPE):
logger.info(f"Winner number for {raffle['name']} is {winner_num}")
await end_raffle_logic(context, raffle['id'], [int(winner_num)%100], ADMIN_IDS[0])
async def announce_reminder_active_raffles(context: ContextTypes.DEFAULT_TYPE):
"""Job callback to announce active raffles in announce channels."""
# context is automatically provided by PTB's Job Queue
# No need to get app from context explicitly here for bot access,
# context.bot can be used directly.
logger.info(f"Running announce_reminder_active_raffles")
raffles = get_active_raffles()
if not raffles:
logger.info("No active raffles to announce.")
return
message_lines = ["🎉 <b>Sorteos Activos</b> 🎉\n"]
for raffle in raffles:
remaining = get_remaining_numbers_amount(raffle['id'])
message_lines.append(
f"• <b>{raffle['name']}</b>\n"
f" Donación mínima: {raffle['price']}\n"
f" Participaciones restantes: {remaining}\n"
f" https://t.me/{REVERSE_CHANNELS.get(raffle['channel_id'])}/{get_main_message_id(raffle['id'])}\n"
)
message_text = "\n".join(message_lines)
for alias, channel_id in ANNOUNCE_CHANNELS.items():
try:
await context.bot.send_message(chat_id=channel_id, text=message_text, parse_mode=ParseMode.HTML)
logger.info(f"Announced active raffles in channel {alias} ({channel_id}).")
except Forbidden:
logger.warning(f"Cannot send announcement to channel {alias} ({channel_id}) (Forbidden).")
except BadRequest as e:
logger.error(f"BadRequest sending announcement to channel {alias} ({channel_id}): {e}")
except Exception as e:
logger.error(f"Failed to send announcement to channel {alias} ({channel_id}): {e}")
# --- Main Function ---
def main():
init_db()
@@ -171,6 +206,13 @@ def main():
)
logger.info("Scheduled winner check job every day at 21:45 Madrid time.")
job_queue.run_daily(
callback=announce_reminder_active_raffles,
time=dtime(hour=13, minute=0, tzinfo=madrid_tz),
name="announce_active_raffles_job"
)
logger.info("Scheduled announce active raffles job every day at 13:00 Madrid time.")
# --- Handlers (Remain the same) ---
# 1. Raffle Creation Conversation Handler
raffle_creation_conv = ConversationHandler(