Skip to content

Commit

Permalink
stay silent if nothing to say in group chat
Browse files Browse the repository at this point in the history
  • Loading branch information
nett00n committed Oct 28, 2024
1 parent 5f7c32c commit 3b8cab6
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions app/url_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ async def attempt_download(final_url: str) -> str:
return None

async def process_url_request(url: str, is_group_chat: bool = False) -> str:
url = str(url)
final_url = follow_redirects(url)
url = str(url) # Ensure url is a string

youtube_alternative = transform_youtube_url(final_url)
# Now continue as before with the transformed url
youtube_alternative = transform_youtube_url(url)
if youtube_alternative:
return (
"YouTube video cannot be downloaded, but here’s an alternative link:"
Expand All @@ -75,23 +75,27 @@ async def process_url_request(url: str, is_group_chat: bool = False) -> str:
)

try:
response = await attempt_download(final_url)
response = await attempt_download(url)
if response:
return response
except UnsupportedUrlError:
modified_url = apply_rewrite_map(final_url)
modified_url = apply_rewrite_map(url)
if modified_url == url and is_group_chat:
return None # Silent response for unmodified URLs in group/supergroup
return (
"I failed to download the file by myself.\n\n"
"I failed to download this by myself.\n\n"
+ "Here is an alternative link, which Telegram may parse better: "
+ f"\n\n[📎 Modified URL]({modified_url})"
+ f"\n\n[📎 Original]({final_url})"
+ f"\n\n[📎 Original]({url})"
)
except Exception as e:
logger.error(f"Unknown error processing URL: {e}")
modified_url = apply_rewrite_map(final_url)
modified_url = apply_rewrite_map(url)
if modified_url == url and is_group_chat:
return None # Silent response for unmodified URLs in group/supergroup
return (
"I failed to download the file by myself.\n\n"
"I failed to download this by myself.\n\n"
+ "Here is an alternative link, which Telegram may parse better: "
+ f"\n\n[📎 Modified URL]({modified_url})"
+ f"\n\n[📎 Original]({final_url})"
+ f"\n\n[📎 Original]({url})"
)

0 comments on commit 3b8cab6

Please sign in to comment.