-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
135 lines (110 loc) · 4.88 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#safe_repo
import time
import asyncio
from pyrogram import filters, Client
from safe_repo import app
from config import API_ID, API_HASH
from safe_repo.core.get_func import get_msg
from safe_repo.core.func import *
from safe_repo.core.mongo import db
from pyrogram.errors import FloodWait
@app.on_message(filters.regex(r'https?://[^\s]+'))
async def single_link(_, message):
user_id = message.chat.id
lol = await chk_user(message, user_id)
if lol == 1:
return
link = get_link(message.text)
try:
join = await subscribe(_, message)
if join == 1:
return
msg = await message.reply("Processing...")
data = await db.get_data(user_id)
if data and data.get("session"):
session = data.get("session")
try:
userbot = Client(":userbot:", api_id=API_ID, api_hash=API_HASH, session_string=session)
await userbot.start()
except:
return await msg.edit_text("Login expired /login again...")
else:
await msg.edit_text("Login in bot first ...")
return
try:
if 't.me/+' in link:
q = await userbot_join(userbot, link)
await msg.edit_text(q)
return
if 't.me/' in link:
await get_msg(userbot, user_id, msg.id, link, 0, message)
except Exception as e:
await msg.edit_text(f"Link: `{link}`\n\n**Error:** {str(e)}")
except FloodWait as fw:
await msg.edit_text(f'Try again after {fw.x} seconds due to floodwait from telegram.')
except Exception as e:
await msg.edit_text(f"Link: `{link}`\n\n**Error:** {str(e)}")
users_loop = {}
@app.on_message(filters.command("batch"))
async def batch_link(_, message):
user_id = message.chat.id
lol = await chk_user(message, user_id)
if lol == 1:
return
start = await app.ask(message.chat.id, text="Please send the start link.")
start_id = start.text
s = start_id.split("/")[-1]
cs = int(s)
last = await app.ask(message.chat.id, text="Please send the end link.")
last_id = last.text
l = last_id.split("/")[-1]
cl = int(l)
if cl - cs > 4000:
await app.send_message(message.chat.id, "Only 1000 messages allowed in batch size... Purchase premium to fly 💸")
return
try:
data = await db.get_data(user_id)
if data and data.get("session"):
session = data.get("session")
try:
userbot = Client(":userbot:", api_id=API_ID, api_hash=API_HASH, session_string=session)
await userbot.start()
except:
return await app.send_message(message.chat.id, "Your login expired ... /login again")
else:
await app.send_message(message.chat.id, "Login in bot first ...")
try:
users_loop[user_id] = True
for i in range(int(s), int(l)):
if user_id in users_loop and users_loop[user_id]:
msg = await app.send_message(message.chat.id, "Processing!")
try:
x = start_id.split('/')
y = x[:-1]
result = '/'.join(y)
url = f"{result}/{i}"
link = get_link(url)
await get_msg(userbot, user_id, msg.id, link, 0, message)
sleep_msg = await app.send_message(message.chat.id, "Sleeping for 5 seconds to avoid flood...")
await asyncio.sleep(1.5)
await sleep_msg.delete()
await asyncio.sleep(0.5)
except Exception as e:
print(f"Error processing link {url}: {e}")
continue
else:
break
except Exception as e:
await app.send_message(message.chat.id, f"Error: {str(e)}")
except FloodWait as fw:
await app.send_message(message.chat.id, f'Try again after {fw.x} seconds due to floodwait from Telegram.')
except Exception as e:
await app.send_message(message.chat.id, f"Error: {str(e)}")
@app.on_message(filters.command("cancel"))
async def stop_batch(_, message):
user_id = message.chat.id
if user_id in users_loop:
users_loop[user_id] = False
await app.send_message(message.chat.id, "Batch processing stopped.")
else:
await app.send_message(message.chat.id, "No active batch processing to stop.")