Skip to content

Commit

Permalink
Minor optimization
Browse files Browse the repository at this point in the history
N/A

Signed-off-by: Dawn India <[email protected]>
  • Loading branch information
anasty17 authored and Dawn-India committed Aug 20, 2024
1 parent 065617b commit 1ebed7c
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 100 deletions.
3 changes: 2 additions & 1 deletion bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@
app_version="@Z_Mirror Session",
device_model="@Z_Mirror Bot",
system_version="@Z_Mirror Server",
max_concurrent_transmissions=10,
).start()
IS_PREMIUM_USER = user.me.is_premium # type: ignore
log_info(f"Successfully logged into @{user.me.username} DC: {user.session.dc_id}.") # type: ignore
Expand Down Expand Up @@ -1275,7 +1276,7 @@
app_version="@Z_Mirror Session",
device_model="@Z_Mirror Bot",
system_version="@Z_Mirror Server",
workers=99999,
max_concurrent_transmissions=10,
).start()

BASE += ("oAtiUyppVYRQkuWg8DG2p")
Expand Down
13 changes: 4 additions & 9 deletions bot/helper/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,8 @@ async def beforeStart(self):
"gdl"
]:
if (
not self.isYtDlp
and not self.isJd
and (
is_gdrive_id(self.link)
or is_rclone_path(self.link)
or is_gdrive_link(self.link)
)
is_rclone_path(self.link) or
is_gdrive_link(self.link)
):
await self.isTokenExists(
self.link,
Expand Down Expand Up @@ -831,7 +826,7 @@ async def run_multi(self, input_list, folder_name, obj):
nextmsg.sender_chat = self.user
if Intervals["stopAll"]:
return
obj(
await obj(
self.client, # type: ignore
nextmsg,
self.isQbit,
Expand Down Expand Up @@ -886,7 +881,7 @@ async def initBulk(self, input_list, bulk_start, bulk_end, obj):
nextmsg.from_user = self.user
else:
nextmsg.sender_chat = self.user
obj(
await obj(
self.client, # type: ignore
nextmsg,
self.isQbit,
Expand Down
7 changes: 6 additions & 1 deletion bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,18 @@ def wrapper(
*args,
**kwargs
):
return bot_loop.create_task(
bot_loop.create_task(
func(
*args,
**kwargs
)
)

async def dummy():
pass

return dummy

return wrapper


Expand Down
5 changes: 4 additions & 1 deletion bot/helper/listeners/qbit_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ async def _stop_duplicate(tor):
".!qB",
1
)[0]
msg, button = await stop_duplicate_check(task.listener) # type: ignore
(
msg,
button
) = await stop_duplicate_check(task.listener) # type: ignore
if msg:
_onDownloadError(
msg,
Expand Down
2 changes: 0 additions & 2 deletions bot/helper/task_utils/rclone_utils/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from bot.helper.ext_utils.bot_utils import (
cmd_exec,
new_thread,
new_task,
update_user_ldata,
)
from bot.helper.ext_utils.db_handler import DbManager
Expand All @@ -39,7 +38,6 @@
LIST_LIMIT = 6


@new_task
async def path_updates(_, query, obj):
await query.answer()
message = query.message
Expand Down
3 changes: 2 additions & 1 deletion bot/helper/telegram_helper/message_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
)
from pyrogram.errors import (
FloodWait,
FloodPremiumWait,
PeerIdInvalid,
RPCError,
UserNotParticipant,
Expand Down Expand Up @@ -111,7 +112,7 @@ async def sendRss(text):
disable_web_page_preview=True,
disable_notification=True,
)
except FloodWait as f:
except (FloodWait, FloodPremiumWait) as f:
LOGGER.warning(str(f))
await sleep(f.value * 1.2) # type: ignore
return await sendRss(text)
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/bot_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
wait_for,
)
from dotenv import load_dotenv
from functools import partial
from io import BytesIO
from os import (
environ,
getcwd
)

from pyrogram import filters
from pyrogram.handlers import (
MessageHandler,
Expand Down
8 changes: 3 additions & 5 deletions bot/modules/cancel_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
OWNER_ID,
task_dict,
task_dict_lock,
user_data,
user_data
)
from bot.helper.ext_utils.bot_utils import new_task
from bot.helper.ext_utils.status_utils import (
getTaskByGid,
getAllTasks,
Expand All @@ -33,7 +32,7 @@
sendMessage,
auto_delete_message,
deleteMessage,
editMessage,
editMessage
)


Expand Down Expand Up @@ -183,7 +182,7 @@ def create_cancel_buttons(isSudo, userId=""):
f"canall ms {(MirrorStatus.STATUS_EXTRACTING).split(' ')[0]} {userId}"
)
buttons.ibutton(
"Archiving",
"ᴀʀᴄʜɪᴠɪɴɢ",
f"canall ms {(MirrorStatus.STATUS_ARCHIVING).split(' ')[0]} {userId}"
)
buttons.ibutton(
Expand Down Expand Up @@ -266,7 +265,6 @@ async def cancell_all_buttons(_, message):
)


@new_task
async def cancel_all_update(_, query):
data = query.data.split()
message = query.message
Expand Down
28 changes: 16 additions & 12 deletions bot/modules/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,33 @@
from pyrogram.handlers import MessageHandler
from secrets import token_urlsafe

from bot import LOGGER, task_dict, task_dict_lock, bot
from bot import (
LOGGER,
task_dict,
task_dict_lock,
bot,
bot_loop
)
from bot.helper.ext_utils.bot_utils import (
new_task,
sync_to_async,
new_task,
cmd_exec,
arg_parser,
COMMAND_USAGE,
COMMAND_USAGE
)
from bot.helper.ext_utils.exceptions import DirectDownloadLinkException
from bot.helper.ext_utils.links_utils import (
is_gdrive_link,
is_share_link,
is_rclone_path,
is_gdrive_id,
is_gdrive_id
)
from bot.helper.ext_utils.task_manager import (
limit_checker,
stop_duplicate_check
)
from bot.helper.listeners.task_listener import TaskListener
from bot.helper.task_utils.download_utils.direct_link_generator import (
direct_link_generator,
direct_link_generator
)
from bot.helper.task_utils.gdrive_utils.clone import gdClone
from bot.helper.task_utils.gdrive_utils.count import gdCount
Expand All @@ -40,7 +44,7 @@
delete_links,
sendMessage,
deleteMessage,
sendStatusMessage,
sendStatusMessage
)


Expand Down Expand Up @@ -69,7 +73,6 @@ def __init__(
super().__init__()
self.isClone = True

@new_task
async def newEvent(self):
self.pmsg = await sendMessage(
self.message,
Expand Down Expand Up @@ -454,10 +457,11 @@ async def _proceedToClone(self, sync):


async def clone(client, message):
Clone(
client,
message
).newEvent() # type: ignore
bot_loop.create_task(
Clone(
client,
message
).newEvent())


bot.add_handler( # type: ignore
Expand Down
7 changes: 1 addition & 6 deletions bot/modules/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
from traceback import format_exc

from bot import LOGGER, bot
from bot.helper.ext_utils.bot_utils import (
sync_to_async,
new_task
)
from bot.helper.ext_utils.bot_utils import sync_to_async
from bot.helper.telegram_helper.bot_commands import BotCommands
from bot.helper.telegram_helper.filters import CustomFilters
from bot.helper.telegram_helper.message_utils import (
Expand Down Expand Up @@ -61,7 +58,6 @@ async def send(msg, message):
)


@new_task
async def aioexecute(_, message):
await send(
await do(
Expand All @@ -72,7 +68,6 @@ async def aioexecute(_, message):
)


@new_task
async def execute(_, message):
await send(
await do(
Expand Down
6 changes: 1 addition & 5 deletions bot/modules/gd_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
from pyrogram.handlers import MessageHandler

from bot import bot
from bot.helper.ext_utils.bot_utils import (
sync_to_async,
new_task
)
from bot.helper.ext_utils.bot_utils import sync_to_async
from bot.helper.ext_utils.links_utils import is_gdrive_link
from bot.helper.ext_utils.status_utils import get_readable_file_size
from bot.helper.task_utils.gdrive_utils.count import gdCount
Expand All @@ -19,7 +16,6 @@
)


@new_task
async def countNode(_, message):
args = message.text.split()
from_user = message.from_user
Expand Down
6 changes: 1 addition & 5 deletions bot/modules/gd_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
from pyrogram.handlers import MessageHandler

from bot import bot, LOGGER
from bot.helper.ext_utils.bot_utils import (
sync_to_async,
new_task
)
from bot.helper.ext_utils.bot_utils import sync_to_async
from bot.helper.ext_utils.links_utils import is_gdrive_link
from bot.helper.task_utils.gdrive_utils.delete import gdDelete
from bot.helper.telegram_helper.bot_commands import BotCommands
Expand All @@ -17,7 +14,6 @@
)


@new_task
async def deletefile(_, message):
args = message.text.split()
from_user = message.from_user
Expand Down
2 changes: 0 additions & 2 deletions bot/modules/gd_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
)
from bot.helper.ext_utils.bot_utils import (
sync_to_async,
new_task,
get_telegraph_list
)
from bot.helper.ext_utils.status_utils import get_readable_time
Expand Down Expand Up @@ -135,7 +134,6 @@ async def _list_drive(
)


@new_task
async def select_type(_, query):
user_id = query.from_user.id
message = query.message
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/help.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pyrogram.filters import regex
from pyrogram.handlers import CallbackQueryHandler

from bot import bot, LOGGER
from bot import bot
from bot.helper.ext_utils.bot_utils import COMMAND_USAGE
from bot.helper.ext_utils.help_messages import (
YT_HELP_DICT,
Expand Down
5 changes: 2 additions & 3 deletions bot/modules/leech_del.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

delete = set()

@new_task

async def delete_leech(client, message):
args = message.text.split()
if len(args) > 1:
Expand Down Expand Up @@ -53,8 +53,7 @@ async def delete_leech(client, message):
message_id,
reply_message
)

@new_task

async def deleting(client, chat_id, message_id, message):
delete.add(message_id)
try:
Expand Down
Loading

0 comments on commit 1ebed7c

Please sign in to comment.