2022-10-02 17:14:56 +00:00
|
|
|
from pyrogram import Client, filters, ContinuePropagation
|
|
|
|
from pyrogram.enums import MessageEntityType
|
|
|
|
from pyrogram.types import Message
|
|
|
|
|
2022-10-03 08:31:20 +00:00
|
|
|
from defs.lofter import get_loft, input_media, get_loft_user, lofter_user_link
|
2023-06-23 15:37:55 +00:00
|
|
|
from init import bot
|
2022-10-02 17:14:56 +00:00
|
|
|
|
|
|
|
|
2023-06-23 15:37:55 +00:00
|
|
|
@bot.on_message(filters.incoming & filters.text & filters.regex(r"lofter.com"))
|
2022-10-02 17:14:56 +00:00
|
|
|
async def lofter_share(_: Client, message: Message):
|
|
|
|
if not message.text:
|
|
|
|
return
|
2022-10-03 06:13:37 +00:00
|
|
|
static = "static" in message.text
|
|
|
|
try:
|
2022-10-02 17:14:56 +00:00
|
|
|
for num in range(len(message.entities)):
|
|
|
|
entity = message.entities[num]
|
|
|
|
if entity.type == MessageEntityType.URL:
|
2023-01-12 13:19:54 +00:00
|
|
|
url = message.text[entity.offset : entity.offset + entity.length]
|
2022-10-02 17:14:56 +00:00
|
|
|
elif entity.type == MessageEntityType.TEXT_LINK:
|
|
|
|
url = entity.url
|
|
|
|
else:
|
|
|
|
continue
|
2022-10-03 08:31:20 +00:00
|
|
|
if "/post/" in url:
|
|
|
|
img = await get_loft(url)
|
|
|
|
if not img:
|
|
|
|
continue
|
|
|
|
if len(img) == 1:
|
|
|
|
await img[0].reply_to(message, static=static)
|
|
|
|
else:
|
2023-01-12 13:19:54 +00:00
|
|
|
await message.reply_media_group(
|
|
|
|
media=await input_media(img[:9], static), quote=True
|
|
|
|
)
|
2022-10-13 14:36:43 +00:00
|
|
|
elif "front/blog" not in url:
|
2022-10-03 08:31:20 +00:00
|
|
|
text, avatar, username, status_link = await get_loft_user(url)
|
2022-10-03 09:35:32 +00:00
|
|
|
if avatar:
|
|
|
|
await message.reply_photo(
|
|
|
|
avatar,
|
|
|
|
caption=text,
|
|
|
|
quote=True,
|
2023-01-12 13:19:54 +00:00
|
|
|
reply_markup=lofter_user_link(username, status_link),
|
2022-10-03 09:35:32 +00:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
await message.reply_text(
|
|
|
|
text,
|
|
|
|
quote=True,
|
|
|
|
disable_web_page_preview=True,
|
2023-01-12 13:19:54 +00:00
|
|
|
reply_markup=lofter_user_link(username, status_link),
|
2022-10-03 09:35:32 +00:00
|
|
|
)
|
2022-10-03 06:13:37 +00:00
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
2022-10-02 17:14:56 +00:00
|
|
|
raise ContinuePropagation
|