Path: blob/master/bot/helper/ext_utils/bulk_links.py
1635 views
from aiofiles import open as aiopen1from aiofiles.os import remove234def filter_links(links_list, bulk_start, bulk_end):5start = bulk_start if bulk_start > 0 else None6end = bulk_end if bulk_end > 0 else None7return links_list[start:end]8910def get_links_from_message(text):11links_list = text.split("\n")12return [item.strip() for item in links_list if len(item) != 0]131415async def get_links_from_file(message):16links_list = []17text_file_dir = await message.download()18async with aiopen(text_file_dir, "r+") as f:19lines = await f.readlines()20links_list.extend(line.strip() for line in lines if len(line) != 0)21await remove(text_file_dir)22return links_list232425async def extract_bulk_links(message, bulk_start, bulk_end):26bulk_start = int(bulk_start)27bulk_end = int(bulk_end)28links_list = []29if reply_to := message.reply_to_message:30if (file_ := reply_to.document) and (file_.mime_type == "text/plain"):31links_list = await get_links_from_file(reply_to)32elif text := reply_to.text:33links_list = get_links_from_message(text)34return filter_links(links_list, bulk_start, bulk_end) if links_list else links_list353637