forked from bipinkrish/Link-Bypasser-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
284 lines (249 loc) · 7.89 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
from pyrogram import Client, filters
from pyrogram.types import (
InlineKeyboardMarkup,
InlineKeyboardButton,
BotCommand,
Message,
)
from os import environ, remove
from threading import Thread
from json import load
from re import search
from texts import HELP_TEXT
import bypasser
import freewall
from time import time
from db import DB
# bot
with open("config.json", "r") as f:
DATA: dict = load(f)
def getenv(var):
return environ.get(var) or DATA.get(var, None)
bot_token = getenv("TOKEN")
api_hash = getenv("HASH")
api_id = getenv("ID")
app = Client("my_bot", api_id=api_id, api_hash=api_hash, bot_token=bot_token)
with app:
app.set_bot_commands(
[
BotCommand("start", "Welcome Message"),
BotCommand("help", "List of All Supported Sites"),
]
)
# DB
db_api = getenv("DB_API")
db_owner = getenv("DB_OWNER")
db_name = getenv("DB_NAME")
try: database = DB(api_key=db_api, db_owner=db_owner, db_name=db_name)
except:
print("Database is Not Set")
database = None
# handle index
def handleIndex(ele: str, message: Message, msg: Message):
result = bypasser.scrapeIndex(ele)
try:
app.delete_messages(message.chat.id, msg.id)
except:
pass
if database and result: database.insert(ele, result)
for page in result:
app.send_message(
message.chat.id,
page,
reply_to_message_id=message.id,
disable_web_page_preview=True,
)
# loop thread
def loopthread(message: Message, otherss=False):
urls = []
if otherss:
texts = message.caption
else:
texts = message.text
if texts in [None, ""]:
return
for ele in texts.split():
if "http://" in ele or "https://" in ele:
urls.append(ele)
if len(urls) == 0:
return
if bypasser.ispresent(bypasser.ddl.ddllist, urls[0]):
msg: Message = app.send_message(
message.chat.id, "⚡ __generating...__", reply_to_message_id=message.id
)
elif freewall.pass_paywall(urls[0], check=True):
msg: Message = app.send_message(
message.chat.id, "🕴️ __jumping the wall...__", reply_to_message_id=message.id
)
else:
if "https://olamovies" in urls[0] or "https://psa.wf/" in urls[0]:
msg: Message = app.send_message(
message.chat.id,
"⏳ __this might take some time...__",
reply_to_message_id=message.id,
)
else:
msg: Message = app.send_message(
message.chat.id, "🔎 __bypassing...__", reply_to_message_id=message.id
)
strt = time()
links = ""
temp = None
for ele in urls:
if database: df_find = database.find(ele)
else: df_find = None
if df_find:
print("Found in DB")
temp = df_find
elif search(r"https?:\/\/(?:[\w.-]+)?\.\w+\/\d+:", ele):
handleIndex(ele, message, msg)
return
elif bypasser.ispresent(bypasser.ddl.ddllist, ele):
try:
temp = bypasser.ddl.direct_link_generator(ele)
except Exception as e:
temp = "**Error**: " + str(e)
elif freewall.pass_paywall(ele, check=True):
freefile = freewall.pass_paywall(ele)
if freefile:
try:
app.send_document(
message.chat.id, freefile, reply_to_message_id=message.id
)
remove(freefile)
app.delete_messages(message.chat.id, [msg.id])
return
except:
pass
else:
app.send_message(
message.chat.id, "__Failed to Jump", reply_to_message_id=message.id
)
else:
try:
temp = bypasser.shortners(ele)
except Exception as e:
temp = "**Error**: " + str(e)
print("bypassed:", temp)
if temp != None:
if (not df_find) and ("http://" in temp or "https://" in temp) and database:
print("Adding to DB")
database.insert(ele, temp)
links = links + temp + "\n"
end = time()
print("Took " + "{:.2f}".format(end - strt) + "sec")
if otherss:
try:
app.send_photo(
message.chat.id,
message.photo.file_id,
f"__{links}__",
reply_to_message_id=message.id,
)
app.delete_messages(message.chat.id, [msg.id])
return
except:
pass
try:
final = []
tmp = ""
for ele in links.split("\n"):
tmp += ele + "\n"
if len(tmp) > 4000:
final.append(tmp)
tmp = ""
final.append(tmp)
app.delete_messages(message.chat.id, msg.id)
tmsgid = message.id
for ele in final:
tmsg = app.send_message(
message.chat.id,
f"__{ele}__",
reply_to_message_id=tmsgid,
disable_web_page_preview=True,
)
tmsgid = tmsg.id
except Exception as e:
app.send_message(
message.chat.id,
f"__Failed to Bypass : {e}__",
reply_to_message_id=message.id,
)
# start command
@app.on_message(filters.command(["start"]))
def send_start(
client: Client,
message: Message,
):
app.send_message(
message.chat.id,
f"__👋 Hi **{message.from_user.mention}**, i am Link Bypasser Bot, just send me any supported links and i will you get you results.\nCheckout /help to Read More__",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"🌐 Source Code",
url="https://github.com/bipinkrish/Link-Bypasser-Bot",
)
],
[
InlineKeyboardButton(
"Replit",
url="https://replit.com/@bipinkrish/Link-Bypasser#app.py",
)
],
]
),
reply_to_message_id=message.id,
)
# help command
@app.on_message(filters.command(["help"]))
def send_help(
client: Client,
message: Message,
):
app.send_message(
message.chat.id,
HELP_TEXT,
reply_to_message_id=message.id,
disable_web_page_preview=True,
)
# links
@app.on_message(filters.text)
def receive(
client: Client,
message: Message,
):
bypass = Thread(target=lambda: loopthread(message), daemon=True)
bypass.start()
# doc thread
def docthread(message: Message):
msg: Message = app.send_message(
message.chat.id, "🔎 __bypassing...__", reply_to_message_id=message.id
)
print("sent DLC file")
file = app.download_media(message)
dlccont = open(file, "r").read()
links = bypasser.getlinks(dlccont)
app.edit_message_text(
message.chat.id, msg.id, f"__{links}__", disable_web_page_preview=True
)
remove(file)
# files
@app.on_message([filters.document, filters.photo, filters.video])
def docfile(
client: Client,
message: Message,
):
try:
if message.document.file_name.endswith("dlc"):
bypass = Thread(target=lambda: docthread(message), daemon=True)
bypass.start()
return
except:
pass
bypass = Thread(target=lambda: loopthread(message, True), daemon=True)
bypass.start()
# server loop
print("Bot Starting")
app.run()