Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions userbot/plugins/video_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
# Combined regex for function trigger
video_url_regex = f"({instagram_regex}|{tiktok_regex}|{youtube_regex}|{facebook_regex})"

# Cache for the bot's user ID to avoid repeated API calls
_bot_user_id = None


async def get_final_url(url):
timeout = aiohttp.ClientTimeout(total=10)
Expand All @@ -51,6 +54,16 @@ async def process_urls(url):

@UserBot.on_message(filters.regex(video_url_regex) & filters.me)
async def video_downloader(bot: UserBot, message: Message, from_reply=False):
global _bot_user_id

# Don't download if the message is sent to saved messages (to myself)
if _bot_user_id is None:
me = await bot.get_me()
_bot_user_id = me.id

if message.chat.id == _bot_user_id:
return

# Extract the video URL from the message
message_text = message.text or message.caption

Expand Down