-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.py
More file actions
339 lines (330 loc) · 17.5 KB
/
main.py
File metadata and controls
339 lines (330 loc) · 17.5 KB
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# (c) @PredatorHackerzZ
import asyncio
from pyrogram import Client, filters
from pyrogram.errors import QueryIdInvalid, FloodWait
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, Message, InlineQuery, CallbackQuery, InlineQueryResultArticle, \
InputTextMessageContent
from MultiSearchBot.scripts import Script
from MultiSearchBot.callback import *
from configs import Config
from tool import SearchYTS, SearchAnime, Search1337x, SearchPirateBay, SearchPyPi
Bot = Client(session_name=Config.SESSION_NAME, api_id=Config.API_ID, api_hash=Config.API_HASH, bot_token=Config.BOT_TOKEN)
@Bot.on_message(filters.command("start"))
async def start_handler(_, message: Message):
try:
await message.reply_text(
text=Script.START_TEXT.format(message.from_user.mention),
disable_web_page_preview=True,
parse_mode="html",
reply_markup=Script.START_BUTTONS
)
except FloodWait as e:
print(f"[{Config.SESSION_NAME}] - Sleeping for {e.x}s")
await asyncio.sleep(e.x)
await start_handler(_, message)
@Bot.on_inline_query()
async def inline_handlers(_, inline: InlineQuery):
search_ts = inline.query
answers = []
if search_ts == "":
answers.append(
InlineQueryResultArticle(
title="Search Something Inline...",
description="Search For Google, PYPI, Torrents, YouTube...",
input_message_content=InputTextMessageContent(
message_text="Search for Anything you Want from Inline!",
parse_mode="Markdown"
),
reply_markup=Script.SEARCH_BUTTONS
)
)
elif search_ts.startswith("!pb"):
query = search_ts.split(" ", 1)[-1]
if (query == "") or (query == " "):
answers.append(
InlineQueryResultArticle(
title="!pb [text]",
description="Search For Torrent in ThePirateBay ...",
input_message_content=InputTextMessageContent(
message_text="`!pb [text]`\n\nSearch ThePirateBay Torrents from Inline!",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Search Again", switch_inline_query_current_chat="!pb ")]])
)
)
else:
torrentList = await SearchPirateBay(query)
if not torrentList:
answers.append(
InlineQueryResultArticle(
title="No Torrents Found in ThePirateBay!",
description=f"Can't find torrents for {query} in ThePirateBay !!",
input_message_content=InputTextMessageContent(
message_text=f"No Torrents Found For `{query}` in ThePirateBay !!",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Try Again", switch_inline_query_current_chat="!pb ")]])
)
)
else:
for i in range(len(torrentList)):
answers.append(
InlineQueryResultArticle(
title=f"{torrentList[i]['Name']}",
description=f"Seeders: {torrentList[i]['Seeders']}, Leechers: {torrentList[i]['Leechers']}\nSize: {torrentList[i]['Size']}",
input_message_content=InputTextMessageContent(
message_text=f"**Category:** `{torrentList[i]['Category']}`\n"
f"**Name:** `{torrentList[i]['Seeders']}`\n"
f"**Size:** `{torrentList[i]['Size']}`\n"
f"**Seeders:** `{torrentList[i]['Seeders']}`\n"
f"**Leechers:** `{torrentList[i]['Leechers']}`\n"
f"**Uploader:** `{torrentList[i]['Uploader']}`\n"
f"**Uploaded on {torrentList[i]['Date']}**\n\n"
f"**Magnet:**\n`{torrentList[i]['Magnet']}`\n\nPowered By @TheTeleRoid",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Search Again", switch_inline_query_current_chat="!pb ")]])
)
)
elif search_ts.startswith("!pypi"):
query = search_ts.split(" ", 1)[-1]
if (query == "") or (query == " "):
answers.append(
InlineQueryResultArticle(
title="!pypi [text]",
description="Search For the PYPI in Inline...",
input_message_content=InputTextMessageContent(
message_text="`!pypi [text]`\n\nSearch The PyPi from Inline!",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Search Again", switch_inline_query_current_chat="!pypi ")]])
)
)
else:
torrentList = await pypi(query)
if not torrentList:
answers.append(
InlineQueryResultArticle(
title="No PYPI Data Found in The API!",
description=f"Can't find pypi for {query} in The Bot !!",
input_message_content=InputTextMessageContent(
message_text=f"No pypi Found For `{query}` in The Bot !!",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Try Again", switch_inline_query_current_chat="!pb ")]])
)
)
else:
for i in range(len(torrentList)):
answers.append(
InlineQueryResultArticle(
title=f"{torrentList[i]['Name']}",
description=f"Seeders: {torrentList[i]['Seeders']}, Leechers: {torrentList[i]['Leechers']}\nSize: {torrentList[i]['Size']}",
input_message_content=InputTextMessageContent(
message_text=f"**Information**\n"
f"**Package Name:** {torrentList[i]['PackageName']}\n"
f"**Title:** {torrentList[i]['Title']}\n"
f"**Pip Command:** {torrentList[i]['PipCommand']}\n"
f"**About:** `{torrentList[i]['About']}`\n"
f"**Uploader:** `{torrentList[i]['Uploader']}`\n"
f"**Uploaded on {torrentList[i]['Date']}**\n\nPowered By @TheTeleRoid",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Search Again", switch_inline_query_current_chat="!pypi ")]])
)
)
elif search_ts.startswith("!yts"):
query = search_ts.split(" ", 1)[-1]
if (query == "") or (query == " "):
answers.append(
InlineQueryResultArticle(
title="!yts [text]",
description="Search For Torrent in YTS ...",
input_message_content=InputTextMessageContent(
message_text="`!yts [text]`\n\nSearch YTS Torrents from Inline!",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Search Again", switch_inline_query_current_chat="!yts ")]])
)
)
else:
torrentList = await SearchYTS(query)
if not torrentList:
answers.append(
InlineQueryResultArticle(
title="No Torrents Found!",
description=f"Can't find YTS torrents for {query} !!",
input_message_content=InputTextMessageContent(
message_text=f"No YTS Torrents Found For `{query}`",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Try Again", switch_inline_query_current_chat="!yts ")]])
)
)
else:
for i in range(len(torrentList)):
dl_links = "- " + "\n\n- ".join(torrentList[i]['Downloads'])
answers.append(
InlineQueryResultArticle(
title=f"{torrentList[i]['Name']}",
description=f"Language: {torrentList[i]['Language']}\nLikes: {torrentList[i]['Likes']}, Rating: {torrentList[i]['Rating']}",
input_message_content=InputTextMessageContent(
message_text=f"**Genre:** `{torrentList[i]['Genre']}`\n"
f"**Name:** `{torrentList[i]['Name']}`\n"
f"**Language:** `{torrentList[i]['Language']}`\n"
f"**Likes:** `{torrentList[i]['Likes']}`\n"
f"**Rating:** `{torrentList[i]['Rating']}`\n"
f"**Duration:** `{torrentList[i]['Runtime']}`\n"
f"**Released on {torrentList[i]['ReleaseDate']}**\n\n"
f"**Torrent Download Links:**\n{dl_links}\n\nPowered By @TheTeleRoid",
parse_mode="Markdown",
disable_web_page_preview=True
),
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Search Again", switch_inline_query_current_chat="!yts ")]]),
thumb_url=torrentList[i]["Poster"]
)
)
elif search_ts.startswith("!a"):
query = search_ts.split(" ", 1)[-1]
if (query == "") or (query == " "):
answers.append(
InlineQueryResultArticle(
title="!a [text]",
description="Search For Torrents for Anime ...",
input_message_content=InputTextMessageContent(
message_text="`!a [text]`\n\nSearch Anime Torrents from Inline!",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Search Again", switch_inline_query_current_chat="!a ")]])
)
)
else:
torrentList = await SearchAnime(query)
if not torrentList:
answers.append(
InlineQueryResultArticle(
title="No Anime Torrents Found!",
description=f"Can't find Anime torrents for {query} !!",
input_message_content=InputTextMessageContent(
message_text=f"No Anime Torrents Found For `{query}`",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Try Again", switch_inline_query_current_chat="!a ")]])
)
)
else:
for i in range(len(torrentList)):
answers.append(
InlineQueryResultArticle(
title=f"{torrentList[i]['Name']}",
description=f"Seeders: {torrentList[i]['Seeder']}, Leechers: {torrentList[i]['Leecher']}\nSize: {torrentList[i]['Size']}",
input_message_content=InputTextMessageContent(
message_text=f"**Category:** `{torrentList[i]['Category']}`\n"
f"**Name:** `{torrentList[i]['Name']}`\n"
f"**Seeders:** `{torrentList[i]['Seeder']}`\n"
f"**Leechers:** `{torrentList[i]['Leecher']}`\n"
f"**Size:** `{torrentList[i]['Size']}`\n"
f"**Upload Date:** `{torrentList[i]['Date']}`\n\n"
f"**Magnet:** \n`{torrentList[i]['Magnet']}`\n\nPowered By @TheTeleRoid",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Search Again", switch_inline_query_current_chat="!a ")]]
)
)
)
else:
torrentList = await Search1337x(search_ts)
if not torrentList:
answers.append(
InlineQueryResultArticle(
title="No Torrents Found!",
description=f"Can't find torrents for {search_ts} !!",
input_message_content=InputTextMessageContent(
message_text=f"No Torrents Found For `{search_ts}`",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Try Again", switch_inline_query_current_chat="")]])
)
)
else:
for i in range(len(torrentList)):
answers.append(
InlineQueryResultArticle(
title=f"{torrentList[i]['Name']}",
description=f"Seeders: {torrentList[i]['Seeders']}, Leechers: {torrentList[i]['Leechers']}\nSize: {torrentList[i]['Size']}, Downloads: {torrentList[i]['Downloads']}",
input_message_content=InputTextMessageContent(
message_text=f"**Category:** `{torrentList[i]['Category']}`\n"
f"**Name:** `{torrentList[i]['Name']}`\n"
f"**Language:** `{torrentList[i]['Language']}`\n"
f"**Seeders:** `{torrentList[i]['Seeders']}`\n"
f"**Leechers:** `{torrentList[i]['Leechers']}`\n"
f"**Size:** `{torrentList[i]['Size']}`\n"
f"**Downloads:** `{torrentList[i]['Downloads']}`\n"
f"__Uploaded by {torrentList[i]['UploadedBy']}__\n"
f"__Uploaded {torrentList[i]['DateUploaded']}__\n"
f"__Last Checked {torrentList[i]['LastChecked']}__\n\n"
f"**Magnet:**\n`{torrentList[i]['Magnet']}`\n\nPowered By @TheTeleRoid",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Search Again", switch_inline_query_current_chat="")]]
),
thumb_url=torrentList[i]['Poster']
)
)
try:
await inline.answer(
results=answers,
cache_time=0
)
print(f"[{Config.SESSION_NAME}] - Answered Successfully - {inline.from_user.first_name}")
except QueryIdInvalid:
print(f"[{Config.SESSION_NAME}] - Failed to Answer - {inline.from_user.first_name} - Sleeping for 5s")
await asyncio.sleep(5)
try:
await inline.answer(
results=answers,
cache_time=0,
switch_pm_text="Error: Search timed out!",
switch_pm_parameter="start",
)
except QueryIdInvalid:
print(f"[{Config.SESSION_NAME}] - Failed to Answer Error - {inline.from_user.first_name} - Sleeping for 5s")
await asyncio.sleep(5)
@Bot.on_callback_query()
async def button(_, message):
if message.data == "home":
await message.edit(
text=Script.START_TEXT.format(message.from_user.mention),
reply_markup=Script.START_BUTTONS,
disable_web_page_preview=True
)
elif message.data == "help":
await message.edit(
text=Script.HELP_TEXT,
reply_markup=Script.HELP_BUTTONS,
disable_web_page_preview=True
)
elif message.data == "about":
await message.edit(
text=Script.ABOUT_TEXT,
reply_markup=Script.ABOUT_BUTTONS,
disable_web_page_preview=True
)
elif message.data == "inline_buttons":
await message.edit(
text=Script.INLINE_TEXT,
reply_markup=Script.SEARCH_BUTTONS,
disable_web_page_preview=True
)
else:
await message.delete()
Bot.run()