Skip to content

Commit d9a080d

Browse files
authored
Added support for extracting IDs and fetching content from Telegram “openmessage” links (#471)
Added support to fetch message content from Telegram “openmessage” links.
1 parent 7d689dd commit d9a080d

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

plugins/utilities.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,14 +743,21 @@ async def get_restricted_msg(event):
743743
chat, msg = get_chat_and_msgid(match)
744744
if not (chat and msg):
745745
return await event.eor(
746-
"Invalid link!\nEg: `https://t.me/TeamUltroid/3` or `https://t.me/c/1313492028/3`"
746+
"Invalid link!\nExamples:\n"
747+
"`https://t.me/TeamUltroid/3`\n"
748+
"`https://t.me/c/1313492028/3`\n"
749+
"`tg://openmessage?user_id=1234567890&message_id=1`"
747750
)
748751

749752
try:
750-
message = await event.client.get_messages(chat, ids=msg)
753+
input_entity = await event.client.get_input_entity(chat)
754+
message = await event.client.get_messages(input_entity, ids=msg)
751755
except BaseException as er:
752756
return await event.eor(f"**ERROR**\n`{er}`")
753757

758+
if not message:
759+
return await event.eor("`Message not found or may not exist.`")
760+
754761
try:
755762
await event.client.send_message(event.chat_id, message)
756763
await xx.try_delete()
@@ -819,3 +826,4 @@ async def get_restricted_msg(event):
819826
await event.eor("`Cannot process this type of media.`")
820827
else:
821828
await event.eor("`No media found in the message.`")
829+

pyUltroid/fns/tools.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,13 +1081,16 @@ def safe_load(file, *args, **kwargs):
10811081

10821082

10831083
def get_chat_and_msgid(link):
1084-
matches = re.findall("https:\\/\\/t\\.me\\/(c\\/|)(.*)\\/(.*)", link)
1085-
if not matches:
1086-
return None, None
1087-
_, chat, msg_id = matches[0]
1088-
if chat.isdigit():
1089-
chat = int("-100" + chat)
1090-
return chat, int(msg_id)
1084+
m = re.findall(r"t\.me\/(c\/)?(\d+)\/(\d+)", link)
1085+
if m:
1086+
_, chat, msg_id = m[0]
1087+
return int("-100" + chat) if _ else chat, int(msg_id)
1088+
1089+
m = re.findall(r"user_id=(\d+)&message_id=(\d+)", link)
1090+
if m:
1091+
return int(m[0][0]), int(m[0][1])
1092+
1093+
return None, None
10911094

10921095

10931096
# --------- END --------- #

0 commit comments

Comments
 (0)