Added support for extracting IDs and fetching content from Telegram “openmessage” links (#471)
Added support to fetch message content from Telegram “openmessage” links.
This commit is contained in:
@@ -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.`")
|
||||
|
||||
|
||||
@@ -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 --------- #
|
||||
|
||||
Reference in New Issue
Block a user