iShotaBot/modules/lofter.py

52 lines
1.9 KiB
Python
Raw Normal View History

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
2022-10-02 17:14:56 +00:00
@Client.on_message(filters.incoming & filters.text &
2022-10-03 08:31:20 +00:00
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:
url = message.text[entity.offset:entity.offset + entity.length]
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:
await message.reply_media_group(media=await input_media(img[:9], static), quote=True)
2022-10-06 07:40:03 +00:00
elif "front/blog" in url:
pass
2022-10-02 17:14:56 +00:00
else:
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,
reply_markup=lofter_user_link(username, status_link)
)
else:
await message.reply_text(
text,
quote=True,
disable_web_page_preview=True,
reply_markup=lofter_user_link(username, status_link)
)
2022-10-03 06:13:37 +00:00
except Exception as e:
print(e)
2022-10-02 17:14:56 +00:00
raise ContinuePropagation