Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# main.py (Correcting
|
2 |
import os
|
3 |
import re
|
4 |
import logging
|
@@ -416,22 +416,34 @@ async def handle_summary_type_callback(update: Update, context: ContextTypes.DEF
|
|
416 |
logger.info(f"User {user.id} chose '{summary_type}' for msg {message_id_to_edit}. URL in context: {'Yes' if url else 'No'}")
|
417 |
if not url:
|
418 |
logger.warning(f"No URL in context for user {user.id} (cb {query_id}).")
|
419 |
-
try:
|
420 |
-
await query.edit_message_text(text="Sorry, I couldn't find the URL associated with this request. Please send the link again.")
|
421 |
-
# *** FIX: Correct syntax for nested try/except ***
|
422 |
except Exception as e:
|
423 |
logger.error(f"Failed edit 'URL not found' msg: {e}")
|
424 |
-
|
425 |
-
|
426 |
-
await context.bot.send_message(chat_id=user.id, text="Sorry, context lost. Send link again.")
|
427 |
-
except Exception:
|
428 |
-
pass # Ignore if sending fallback also fails
|
429 |
return
|
430 |
|
431 |
context.user_data.pop('url_to_summarize', None); context.user_data.pop('original_message_id', None); logger.debug(f"Cleared URL context for user {user.id}")
|
|
|
432 |
global TELEGRAM_TOKEN, OPENROUTER_API_KEY
|
433 |
-
|
434 |
-
if not
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
435 |
logger.info(f"Scheduling task for user {user.id}, chat {query.message.chat_id}, msg {message_id_to_edit}")
|
436 |
asyncio.create_task( process_summary_task( user_id=user.id, chat_id=query.message.chat_id, message_id_to_edit=message_id_to_edit, url=url, summary_type=summary_type, bot_token=TELEGRAM_TOKEN ), name=f"SummaryTask-{user.id}-{message_id_to_edit}" )
|
437 |
|
|
|
1 |
+
# main.py (Correcting SyntaxErrors at lines 433-434)
|
2 |
import os
|
3 |
import re
|
4 |
import logging
|
|
|
416 |
logger.info(f"User {user.id} chose '{summary_type}' for msg {message_id_to_edit}. URL in context: {'Yes' if url else 'No'}")
|
417 |
if not url:
|
418 |
logger.warning(f"No URL in context for user {user.id} (cb {query_id}).")
|
419 |
+
try: await query.edit_message_text(text="Sorry, I couldn't find the URL associated with this request. Please send the link again.")
|
|
|
|
|
420 |
except Exception as e:
|
421 |
logger.error(f"Failed edit 'URL not found' msg: {e}")
|
422 |
+
try: await context.bot.send_message(chat_id=user.id, text="Sorry, context lost. Send link again.")
|
423 |
+
except Exception: pass
|
|
|
|
|
|
|
424 |
return
|
425 |
|
426 |
context.user_data.pop('url_to_summarize', None); context.user_data.pop('original_message_id', None); logger.debug(f"Cleared URL context for user {user.id}")
|
427 |
+
|
428 |
global TELEGRAM_TOKEN, OPENROUTER_API_KEY
|
429 |
+
# --- FIX: Correct Syntax for key checks ---
|
430 |
+
if not TELEGRAM_TOKEN:
|
431 |
+
logger.critical("TG TOKEN missing!")
|
432 |
+
try:
|
433 |
+
await query.edit_message_text(text="β Bot config error.")
|
434 |
+
except Exception:
|
435 |
+
pass
|
436 |
+
return # Stop processing
|
437 |
+
|
438 |
+
if not OPENROUTER_API_KEY:
|
439 |
+
logger.error("OpenRouter key missing!")
|
440 |
+
try:
|
441 |
+
await query.edit_message_text(text="β AI config error.")
|
442 |
+
except Exception:
|
443 |
+
pass
|
444 |
+
return # Stop processing
|
445 |
+
# --- End FIX ---
|
446 |
+
|
447 |
logger.info(f"Scheduling task for user {user.id}, chat {query.message.chat_id}, msg {message_id_to_edit}")
|
448 |
asyncio.create_task( process_summary_task( user_id=user.id, chat_id=query.message.chat_id, message_id_to_edit=message_id_to_edit, url=url, summary_type=summary_type, bot_token=TELEGRAM_TOKEN ), name=f"SummaryTask-{user.id}-{message_id_to_edit}" )
|
449 |
|