-
Notifications
You must be signed in to change notification settings - Fork 58
/
iTorrent.py
148 lines (127 loc) · 3.83 KB
/
iTorrent.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
import os
import aiohttp
import json
from pyrogram import Client, filters, emoji
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
app = Client("trntsrcbot", api_id=int(os.environ.get("API_ID")), api_hash=os.environ.get("API_HASH"), bot_token=os.environ.get("BOT_TOKEN"))
print("\nBot Started\n")
@app.on_message(filters.command(['start']))
async def start(_, message):
await message.reply_text("Hello I'm iTorrent Torrent Scraper Bot\nSend /help To Show Help Screen\nBot by @unkusr")
@app.on_message(filters.command(['help']))
async def help(_, message):
await message.reply_text("Example: /find titanic")
m = None
i = 0
a = None
query = None
@app.on_message(filters.command(["find"]))
async def find(_, message):
global m
global i
global a
global query
try:
await message.delete()
except:
pass
if len(message.command) < 2:
await message.reply_text("Usage: /find query")
return
query = message.text.split(None, 1)[1].replace(" ", "%20")
m = await message.reply_text("Searching\nThis might take a while")
try:
async with aiohttp.ClientSession() as session:
async with session.get(f"https://itor.api-zero.workers.dev/?name={query}") \
as resp:
a = json.loads(await resp.text())
except:
await m.edit("Found Nothing.")
return
result = (
f"**Page - {i+1}**\n\n"
f"➲Name: {a[i]['name']}\n"
f"➲Link: `{a[i]['link']}`\n\n\n"
)
await m.edit(
result,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(f"Next",
callback_data="next"),
InlineKeyboardButton(f"{emoji.CROSS_MARK}",
callback_data="delete")
]
]
),
parse_mode="markdown",
)
@app.on_callback_query(filters.regex("next"))
async def callback_query_next(_, message):
global i
global m
global a
global query
i += 1
result = (
f"**Page - {i+1}**\n\n"
f"➲Name: {a[i]['name']}\n"
f"➲Link: `{a[i]['link']}`\n\n\n"
)
await m.edit(
result,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(f"Prev",
callback_data="previous"),
InlineKeyboardButton(f"{emoji.CROSS_MARK}",
callback_data="delete"),
InlineKeyboardButton(f"Next",
callback_data="next")
]
]
),
parse_mode="markdown",
)
@app.on_callback_query(filters.regex("previous"))
async def callback_query_previous(_, message):
global i
global m
global a
global query
i -= 1
result = (
f"**Page - {i+1}**\n\n"
f"➲Name: {a[i]['name']}\n"
f"➲Link: `{a[i]['link']}`\n\n\n"
)
await m.edit(
result,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(f"Prev",
callback_data="previous"),
InlineKeyboardButton(f"{emoji.CROSS_MARK}",
callback_data="delete"),
InlineKeyboardButton(f"Next",
callback_data="next")
]
]
),
parse_mode="markdown",
)
@app.on_callback_query(filters.regex("delete"))
async def callback_query_delete(_, message):
global m
global i
global a
global query
await m.delete()
m = None
i = 0
a = None
query = None
app.run()