From d9a080d8546f8cc60755dffa626e765e514d70c6 Mon Sep 17 00:00:00 2001 From: Parvshah-01 <108631149+Parvshah-01@users.noreply.github.com> Date: Thu, 5 Jun 2025 20:20:46 +0530 Subject: [PATCH] =?UTF-8?q?Added=20support=20for=20extracting=20IDs=20and?= =?UTF-8?q?=20fetching=20content=20from=20Telegram=20=E2=80=9Copenmessage?= =?UTF-8?q?=E2=80=9D=20links=20=20(#471)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added support to fetch message content from Telegram “openmessage” links. --- plugins/utilities.py | 12 ++++++++++-- pyUltroid/fns/tools.py | 17 ++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/plugins/utilities.py b/plugins/utilities.py index f8b62f6..20cd792 100644 --- a/plugins/utilities.py +++ b/plugins/utilities.py @@ -743,14 +743,21 @@ async def get_restricted_msg(event): chat, msg = get_chat_and_msgid(match) if not (chat and msg): return await event.eor( - "Invalid link!\nEg: `https://t.me/TeamUltroid/3` or `https://t.me/c/1313492028/3`" + "Invalid link!\nExamples:\n" + "`https://t.me/TeamUltroid/3`\n" + "`https://t.me/c/1313492028/3`\n" + "`tg://openmessage?user_id=1234567890&message_id=1`" ) try: - message = await event.client.get_messages(chat, ids=msg) + input_entity = await event.client.get_input_entity(chat) + message = await event.client.get_messages(input_entity, ids=msg) except BaseException as er: return await event.eor(f"**ERROR**\n`{er}`") + if not message: + return await event.eor("`Message not found or may not exist.`") + try: await event.client.send_message(event.chat_id, message) await xx.try_delete() @@ -819,3 +826,4 @@ async def get_restricted_msg(event): await event.eor("`Cannot process this type of media.`") else: await event.eor("`No media found in the message.`") + diff --git a/pyUltroid/fns/tools.py b/pyUltroid/fns/tools.py index 3c23f21..eaafc70 100644 --- a/pyUltroid/fns/tools.py +++ b/pyUltroid/fns/tools.py @@ -1081,13 +1081,16 @@ def safe_load(file, *args, **kwargs): def get_chat_and_msgid(link): - matches = re.findall("https:\\/\\/t\\.me\\/(c\\/|)(.*)\\/(.*)", link) - if not matches: - return None, None - _, chat, msg_id = matches[0] - if chat.isdigit(): - chat = int("-100" + chat) - return chat, int(msg_id) + m = re.findall(r"t\.me\/(c\/)?(\d+)\/(\d+)", link) + if m: + _, chat, msg_id = m[0] + return int("-100" + chat) if _ else chat, int(msg_id) + + m = re.findall(r"user_id=(\d+)&message_id=(\d+)", link) + if m: + return int(m[0][0]), int(m[0][1]) + + return None, None # --------- END --------- #