Skip to content

Commit

Permalink
Do not send "Invalid URL" message in group chats (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
nett00n authored Feb 20, 2024
1 parent 4fb916d commit c3a54c7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ async def process_message(message: types.Message):
tasks = []
error_messages = []

# Check if there are valid URLs in the message
valid_urls_exist = any(url.startswith(("http", "www")) for url in urls)

for url in urls:
if not url.startswith(("http", "www")):
error_messages.append(f"Invalid URL format: {url}")
Expand All @@ -130,7 +133,7 @@ async def process_message(message: types.Message):
for result in results:
if isinstance(result, Exception):
error_messages.append(str(result))
if error_messages:
if error_messages and not valid_urls_exist: # Only send error messages if valid URLs exist
await message.reply("\n".join(error_messages))


Expand Down

0 comments on commit c3a54c7

Please sign in to comment.