Skip to content

Commit

Permalink
Stop further execution after sending the reply
Browse files Browse the repository at this point in the history
  • Loading branch information
ovchynnikov committed Jan 29, 2025
1 parent 1d80e46 commit 4ad7a9d
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,26 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE): #
Handles incoming messages from the Telegram bot.
This function processes text messages sent to the bot and determines the appropriate response
based on the message content. It supports specific keywords and URLs, such as Instagram Reels
, or other supported sites, and attempts to download and send the corresponding video.
based on the message content. It supports specific keywords and URLs, such as Instagram Reels,
Facebook Reels, YouTube Shorts, TikTok, Reddit, and X/Twitter, and attempts to download and send
the corresponding video to the user.
Parameters:
update (telegram.Update): Represents the incoming update from the Telegram bot.
context (ContextTypes.DEFAULT_TYPE): The context object for the handler.
Behavior:
- If the message contains "ботяра" (case insensitive), responds with a random response
from a predefined list.
- If the message contains an Instagram Stories URL, informs the user that login is required.
- If the message contains a supported URL (Instagram Reels, Facebook Reels, Youtube Shorts, TikTok, Reddit, X/Twitter):
- Downloads and optionally compresses the video
- Sends the video back to the user via Telegram
- Preserves spoiler tags if present in original message
- Cleans up temporary files after sending
- Handles various error cases with appropriate user feedback
from a predefined list of bot responses.
- If the message contains an Instagram Stories URL, informs the user that downloading is not supported.
- If the message contains a supported URL
(Instagram Reels, Facebook Reels, YouTube Shorts,
TikTok, Reddit, X/Twitter):
- Downloads and optionally compresses the video.
- Sends the video back to the user via Telegram.
- Preserves any spoiler tags present in the original message.
- Cleans up temporary files after sending the video.
- Handles various error cases with appropriate user feedback, ensuring a smooth user experience.
Returns:
None
Expand Down Expand Up @@ -125,9 +128,11 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE): #
# Handle Instagram stories
if "instagram.com/stories/" in message_text:
if language == "ua":
await update.message.reply_text("Сторіз не можу скачати.")
response_message = "Сторіз не можу скачати."
else:
await update.message.reply_text("Instagram stories not supported.")
response_message = "Instagram stories not supported."

await update.message.reply_text(response_message)
return

message_text = message_text.replace("** ", "**")
Expand All @@ -140,7 +145,7 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE): #
else:

await update.message.reply_text("This site is not supported. Try adding ** before the https://")
return
return # Stop further execution after sending the reply
else:
return

Expand Down Expand Up @@ -176,11 +181,9 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE): #
error("Telegram timeout while sending video. %s", e)
except (NetworkError, TelegramError):
await update.message.reply_text(
(
f"О kurwa! Compressed file size: "
f"{os.path.getsize(video_path) / (1024 * 1024):.2f}MB. "
f"Telegram API Max is 50MB"
)
f"О kurwa! Compressed file size: "
f"{os.path.getsize(video_path) / (1024 * 1024):.2f}MB. "
f"Telegram API Max is 50MB"
)

finally:
Expand Down

0 comments on commit 4ad7a9d

Please sign in to comment.