Skip to content

Commit b78d84f

Browse files
committed
some reverts and switch back to pyrofork
Signed-off-by: anasty17 <[email protected]>
1 parent d14a60b commit b78d84f

File tree

8 files changed

+60
-63
lines changed

8 files changed

+60
-63
lines changed

bot/__init__.py

-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from time import time
2727
from tzlocal import get_localzone
2828
from uvloop import install
29-
from concurrent.futures import ThreadPoolExecutor
3029

3130
# from faulthandler import enable as faulthandler_enable
3231
# faulthandler_enable()
@@ -49,9 +48,6 @@
4948
bot_loop = new_event_loop()
5049
set_event_loop(bot_loop)
5150

52-
THREADPOOL = ThreadPoolExecutor(max_workers=99999)
53-
bot_loop.set_default_executor(THREADPOOL)
54-
5551
basicConfig(
5652
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
5753
handlers=[FileHandler("log.txt"), StreamHandler()],

bot/__main__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
)
1414
from pyrogram.filters import command
1515
from pyrogram.handlers import MessageHandler
16-
from pyrogram.types import LinkPreviewOptions
1716
from signal import signal, SIGINT
1817
from sys import executable
1918
from time import time
@@ -231,7 +230,7 @@ async def send_incomplete_task_message(cid, msg):
231230
await bot.send_message(
232231
chat_id=cid,
233232
text=msg,
234-
link_preview_options=LinkPreviewOptions(is_disabled=True),
233+
disable_web_page_preview=True,
235234
disable_notification=True,
236235
)
237236
except Exception as e:

bot/helper/ext_utils/bot_utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from httpx import AsyncClient
22
from asyncio.subprocess import PIPE
33
from functools import partial, wraps
4+
from concurrent.futures import ThreadPoolExecutor
45
from asyncio import (
56
create_subprocess_exec,
67
create_subprocess_shell,
@@ -18,6 +19,7 @@
1819
)
1920

2021
COMMAND_USAGE = {}
22+
THREADPOOL = ThreadPoolExecutor(max_workers=99999)
2123

2224

2325
class SetInterval:
@@ -213,7 +215,7 @@ def wrapper(*args, **kwargs):
213215

214216
async def sync_to_async(func, *args, wait=True, **kwargs):
215217
pfunc = partial(func, *args, **kwargs)
216-
future = bot_loop.run_in_executor(None, pfunc)
218+
future = bot_loop.run_in_executor(THREADPOOL, pfunc)
217219
return await future if wait else future
218220

219221

bot/helper/ext_utils/status_utils.py

+11-13
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ async def get_task_by_gid(gid: str):
6161
return None
6262

6363

64-
def get_specific_tasks(status, userId):
64+
def get_specific_tasks(status, user_id):
6565
if status == "All":
66-
if userId:
67-
return [tk for tk in task_dict.values() if tk.listener.user_id == userId]
66+
if user_id:
67+
return [tk for tk in task_dict.values() if tk.listener.user_id == user_id]
6868
else:
6969
return list(task_dict.values())
70-
elif userId:
70+
elif user_id:
7171
return [
7272
tk
7373
for tk in task_dict.values()
74-
if tk.listener.user_id == userId
74+
if tk.listener.user_id == user_id
7575
and (
7676
(st := tk.status())
7777
and st == status
@@ -90,23 +90,21 @@ def get_specific_tasks(status, userId):
9090
]
9191

9292

93-
async def get_all_tasks(req_status: str, userId):
93+
async def get_all_tasks(req_status: str, user_id):
9494
async with task_dict_lock:
95-
return await sync_to_async(get_specific_tasks, req_status, userId)
95+
return await sync_to_async(get_specific_tasks, req_status, user_id)
9696

9797

9898
def get_readable_file_size(size_in_bytes: int):
99-
if size_in_bytes is None:
99+
if not isinstance(size_in_bytes, int) or size_in_bytes < 0:
100100
return "0B"
101+
101102
index = 0
102103
while size_in_bytes >= 1024 and index < len(SIZE_UNITS) - 1:
103104
size_in_bytes /= 1024
104105
index += 1
105-
return (
106-
f"{size_in_bytes:.2f}{SIZE_UNITS[index]}"
107-
if index > 0
108-
else f"{size_in_bytes:.2f}B"
109-
)
106+
107+
return f"{size_in_bytes:.2f}{SIZE_UNITS[index]}"
110108

111109

112110
def get_readable_time(seconds: int):

bot/helper/mirror_leech_utils/telegram_uploader.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
InputMediaVideo,
1818
InputMediaDocument,
1919
InputMediaPhoto,
20-
LinkPreviewOptions,
2120
)
2221
from tenacity import (
2322
retry,
@@ -98,15 +97,15 @@ async def _msg_to_reply(self):
9897
self._sent_msg = await user.send_message(
9998
chat_id=self._listener.up_dest,
10099
text=msg,
101-
link_preview_options=LinkPreviewOptions(is_disabled=True),
100+
disable_web_page_preview=True,
102101
message_thread_id=self._listener.chat_thread_id,
103102
disable_notification=True,
104103
)
105104
else:
106105
self._sent_msg = await self._listener.client.send_message(
107106
chat_id=self._listener.up_dest,
108107
text=msg,
109-
link_preview_options=LinkPreviewOptions(is_disabled=True),
108+
disable_web_page_preview=True,
110109
message_thread_id=self._listener.chat_thread_id,
111110
disable_notification=True,
112111
)
@@ -122,7 +121,7 @@ async def _msg_to_reply(self):
122121
self._sent_msg = await user.send_message(
123122
chat_id=self._listener.message.chat.id,
124123
text="Deleted Cmd Message! Don't delete the cmd message again!",
125-
link_preview_options=LinkPreviewOptions(is_disabled=True),
124+
disable_web_page_preview=True,
126125
disable_notification=True,
127126
)
128127
else:

bot/helper/telegram_helper/message_utils.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from asyncio import sleep
22
from pyrogram.errors import FloodWait, FloodPremiumWait
3-
from pyrogram.types import LinkPreviewOptions
43
from re import match as re_match
54
from time import time
65

@@ -15,7 +14,7 @@ async def send_message(message, text, buttons=None, block=True):
1514
return await message.reply(
1615
text=text,
1716
quote=True,
18-
link_preview_options=LinkPreviewOptions(is_disabled=True),
17+
disable_web_page_preview=True,
1918
disable_notification=True,
2019
reply_markup=buttons,
2120
)
@@ -34,7 +33,7 @@ async def edit_message(message, text, buttons=None, block=True):
3433
try:
3534
await message.edit(
3635
text=text,
37-
link_preview_options=LinkPreviewOptions(is_disabled=True),
36+
disable_web_page_preview=True,
3837
reply_markup=buttons,
3938
)
4039
except FloodWait as f:
@@ -68,7 +67,7 @@ async def send_rss(text):
6867
return await app.send_message(
6968
chat_id=config_dict["RSS_CHAT"],
7069
text=text,
71-
link_preview_options=LinkPreviewOptions(is_disabled=True),
70+
disable_web_page_preview=True,
7271
disable_notification=True,
7372
)
7473
except (FloodWait, FloodPremiumWait) as f:

bot/modules/cancel_task.py

+38-34
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ async def cancel_multi(_, query):
7575
await delete_message(query.message)
7676

7777

78-
async def cancel_all(status, userId):
79-
matches = await get_all_tasks(status.strip(), userId)
78+
async def cancel_all(status, user_id):
79+
matches = await get_all_tasks(status.strip(), user_id)
8080
if not matches:
8181
return False
8282
for task in matches:
@@ -86,41 +86,45 @@ async def cancel_all(status, userId):
8686
return True
8787

8888

89-
def create_cancel_buttons(isSudo, userId=""):
89+
def create_cancel_buttons(is_sudo, user_id=""):
9090
buttons = button_build.ButtonMaker()
9191
buttons.data_button(
92-
"Downloading", f"canall ms {MirrorStatus.STATUS_DOWNLOADING} {userId}"
92+
"Downloading", f"canall ms {MirrorStatus.STATUS_DOWNLOADING} {user_id}"
9393
)
9494
buttons.data_button(
95-
"Uploading", f"canall ms {MirrorStatus.STATUS_UPLOADING} {userId}"
95+
"Uploading", f"canall ms {MirrorStatus.STATUS_UPLOADING} {user_id}"
9696
)
97-
buttons.data_button("Seeding", f"canall ms {MirrorStatus.STATUS_SEEDING} {userId}")
97+
buttons.data_button("Seeding", f"canall ms {MirrorStatus.STATUS_SEEDING} {user_id}")
9898
buttons.data_button(
99-
"Spltting", f"canall ms {MirrorStatus.STATUS_SPLITTING} {userId}"
99+
"Spltting", f"canall ms {MirrorStatus.STATUS_SPLITTING} {user_id}"
100100
)
101-
buttons.data_button("Cloning", f"canall ms {MirrorStatus.STATUS_CLONING} {userId}")
101+
buttons.data_button("Cloning", f"canall ms {MirrorStatus.STATUS_CLONING} {user_id}")
102102
buttons.data_button(
103-
"Extracting", f"canall ms {MirrorStatus.STATUS_EXTRACTING} {userId}"
103+
"Extracting", f"canall ms {MirrorStatus.STATUS_EXTRACTING} {user_id}"
104104
)
105105
buttons.data_button(
106-
"Archiving", f"canall ms {MirrorStatus.STATUS_ARCHIVING} {userId}"
106+
"Archiving", f"canall ms {MirrorStatus.STATUS_ARCHIVING} {user_id}"
107107
)
108-
buttons.data_button("QueuedDl", f"canall ms {MirrorStatus.STATUS_QUEUEDL} {userId}")
109-
buttons.data_button("QueuedUp", f"canall ms {MirrorStatus.STATUS_QUEUEUP} {userId}")
110108
buttons.data_button(
111-
"SampleVideo", f"canall ms {MirrorStatus.STATUS_SAMVID} {userId}"
109+
"QueuedDl", f"canall ms {MirrorStatus.STATUS_QUEUEDL} {user_id}"
112110
)
113111
buttons.data_button(
114-
"ConvertMedia", f"canall ms {MirrorStatus.STATUS_CONVERTING} {userId}"
112+
"QueuedUp", f"canall ms {MirrorStatus.STATUS_QUEUEUP} {user_id}"
115113
)
116-
buttons.data_button("Paused", f"canall ms {MirrorStatus.STATUS_PAUSED} {userId}")
117-
buttons.data_button("All", f"canall ms All {userId}")
118-
if isSudo:
119-
if userId:
120-
buttons.data_button("All Added Tasks", f"canall bot ms {userId}")
114+
buttons.data_button(
115+
"SampleVideo", f"canall ms {MirrorStatus.STATUS_SAMVID} {user_id}"
116+
)
117+
buttons.data_button(
118+
"ConvertMedia", f"canall ms {MirrorStatus.STATUS_CONVERTING} {user_id}"
119+
)
120+
buttons.data_button("Paused", f"canall ms {MirrorStatus.STATUS_PAUSED} {user_id}")
121+
buttons.data_button("All", f"canall ms All {user_id}")
122+
if is_sudo:
123+
if user_id:
124+
buttons.data_button("All Added Tasks", f"canall bot ms {user_id}")
121125
else:
122-
buttons.data_button("My Tasks", f"canall user ms {userId}")
123-
buttons.data_button("Close", f"canall close ms {userId}")
126+
buttons.data_button("My Tasks", f"canall user ms {user_id}")
127+
buttons.data_button("Close", f"canall close ms {user_id}")
124128
return buttons.build_menu(2)
125129

126130

@@ -131,8 +135,8 @@ async def cancell_all_buttons(_, message):
131135
if count == 0:
132136
await send_message(message, "No active tasks!")
133137
return
134-
isSudo = await CustomFilters.sudo("", message)
135-
button = create_cancel_buttons(isSudo, message.from_user.id)
138+
is_sudo = await CustomFilters.sudo("", message)
139+
button = create_cancel_buttons(is_sudo, message.from_user.id)
136140
can_msg = await send_message(message, "Choose tasks to cancel!", button)
137141
await auto_delete_message(message, can_msg)
138142

@@ -142,37 +146,37 @@ async def cancel_all_update(_, query):
142146
data = query.data.split()
143147
message = query.message
144148
reply_to = message.reply_to_message
145-
userId = int(data[3]) if len(data) > 3 else ""
146-
isSudo = await CustomFilters.sudo("", query)
147-
if not isSudo and userId and userId != query.from_user.id:
149+
user_id = int(data[3]) if len(data) > 3 else ""
150+
is_sudo = await CustomFilters.sudo("", query)
151+
if not is_sudo and user_id and user_id != query.from_user.id:
148152
await query.answer("Not Yours!", show_alert=True)
149153
else:
150154
await query.answer()
151155
if data[1] == "close":
152156
await delete_message(reply_to)
153157
await delete_message(message)
154158
elif data[1] == "back":
155-
button = create_cancel_buttons(isSudo, userId)
159+
button = create_cancel_buttons(is_sudo, user_id)
156160
await edit_message(message, "Choose tasks to cancel!", button)
157161
elif data[1] == "bot":
158-
button = create_cancel_buttons(isSudo, "")
162+
button = create_cancel_buttons(is_sudo, "")
159163
await edit_message(message, "Choose tasks to cancel!", button)
160164
elif data[1] == "user":
161-
button = create_cancel_buttons(isSudo, query.from_user.id)
165+
button = create_cancel_buttons(is_sudo, query.from_user.id)
162166
await edit_message(message, "Choose tasks to cancel!", button)
163167
elif data[1] == "ms":
164168
buttons = button_build.ButtonMaker()
165-
buttons.data_button("Yes!", f"canall {data[2]} confirm {userId}")
166-
buttons.data_button("Back", f"canall back confirm {userId}")
167-
buttons.data_button("Close", f"canall close confirm {userId}")
169+
buttons.data_button("Yes!", f"canall {data[2]} confirm {user_id}")
170+
buttons.data_button("Back", f"canall back confirm {user_id}")
171+
buttons.data_button("Close", f"canall close confirm {user_id}")
168172
button = buttons.build_menu(2)
169173
await edit_message(
170174
message, f"Are you sure you want to cancel all {data[2]} tasks", button
171175
)
172176
else:
173-
button = create_cancel_buttons(isSudo, userId)
177+
button = create_cancel_buttons(is_sudo, user_id)
174178
await edit_message(message, "Choose tasks to cancel.", button)
175-
res = await cancel_all(data[1], userId)
179+
res = await cancel_all(data[1], user_id)
176180
if not res:
177181
await send_message(reply_to, f"No matching tasks for {data[1]}!")
178182

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pillow
2121
psutil
2222
pycryptodome
2323
pymongo
24-
pyrotgfork
24+
pyrofork
2525
python-dotenv
2626
python-magic
2727
qbittorrent-api

0 commit comments

Comments
 (0)