Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
anasty17
GitHub Repository: anasty17/mirror-leech-telegram-bot
Path: blob/master/bot/helper/ext_utils/bulk_links.py
1635 views
1
from aiofiles import open as aiopen
2
from aiofiles.os import remove
3
4
5
def filter_links(links_list, bulk_start, bulk_end):
6
start = bulk_start if bulk_start > 0 else None
7
end = bulk_end if bulk_end > 0 else None
8
return links_list[start:end]
9
10
11
def get_links_from_message(text):
12
links_list = text.split("\n")
13
return [item.strip() for item in links_list if len(item) != 0]
14
15
16
async def get_links_from_file(message):
17
links_list = []
18
text_file_dir = await message.download()
19
async with aiopen(text_file_dir, "r+") as f:
20
lines = await f.readlines()
21
links_list.extend(line.strip() for line in lines if len(line) != 0)
22
await remove(text_file_dir)
23
return links_list
24
25
26
async def extract_bulk_links(message, bulk_start, bulk_end):
27
bulk_start = int(bulk_start)
28
bulk_end = int(bulk_end)
29
links_list = []
30
if reply_to := message.reply_to_message:
31
if (file_ := reply_to.document) and (file_.mime_type == "text/plain"):
32
links_list = await get_links_from_file(reply_to)
33
elif text := reply_to.text:
34
links_list = get_links_from_message(text)
35
return filter_links(links_list, bulk_start, bulk_end) if links_list else links_list
36
37