Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
Switched to NekoZee

Signed-off-by: Dawn India <[email protected]>
  • Loading branch information
Dawn-India committed Aug 14, 2024
1 parent e53d024 commit 47251ad
Show file tree
Hide file tree
Showing 35 changed files with 704 additions and 641 deletions.
5 changes: 5 additions & 0 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Lock,
get_event_loop
)
from concurrent.futures import ThreadPoolExecutor
from dotenv import (
load_dotenv,
dotenv_values
Expand Down Expand Up @@ -40,6 +41,7 @@
Popen,
run
)
from sys import exit
from time import time
from tzlocal import get_localzone
from uvloop import install
Expand All @@ -60,6 +62,8 @@

botStartTime = time()
bot_loop = get_event_loop()
THREADPOOL = ThreadPoolExecutor(max_workers=99999)
bot_loop.set_default_executor(THREADPOOL)

basicConfig(
format="%(levelname)s | From %(name)s -> %(module)s line no: %(lineno)d | %(message)s",
Expand Down Expand Up @@ -1271,6 +1275,7 @@
app_version="@Z_Mirror Session",
device_model="@Z_Mirror Bot",
system_version="@Z_Mirror Server",
workers=99999,
).start()

BASE += ("oAtiUyppVYRQkuWg8DG2p")
Expand Down
12 changes: 8 additions & 4 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,31 +316,35 @@ async def main():
MessageHandler(
log,
filters=command(
BotCommands.LogCommand
BotCommands.LogCommand,
case_sensitive=True
) & CustomFilters.sudo
)
)
bot.add_handler( # type: ignore
MessageHandler(
restart,
filters=command(
BotCommands.RestartCommand
BotCommands.RestartCommand,
case_sensitive=True
) & CustomFilters.sudo
)
)
bot.add_handler( # type: ignore
MessageHandler(
ping,
filters=command(
BotCommands.PingCommand
BotCommands.PingCommand,
case_sensitive=True
) & CustomFilters.sudo
)
)
bot.add_handler( # type: ignore
MessageHandler(
bot_help,
filters=command(
BotCommands.HelpCommand
BotCommands.HelpCommand,
case_sensitive=True
) & CustomFilters.authorized,
)
)
Expand Down
21 changes: 12 additions & 9 deletions bot/helper/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,20 @@ def getConfigPath(self, dest):
)

async def isTokenExists(self, path, status):
if not self.upDest:
raise ValueError("No Upload Destination!")
if (
not is_gdrive_id(self.upDest) # type: ignore
and not is_rclone_path(self.upDest) # type: ignore
):
raise ValueError("Wrong Upload Destination!")
if is_rclone_path(path):
config_path = self.getConfigPath(path)

if (
config_path != "rclone.conf"
and status == "up"
):
self.privateLink = True

if not await aiopath.exists(config_path):
raise ValueError(f"Rclone Config: {config_path} not Exists!")

Expand Down Expand Up @@ -401,6 +406,11 @@ async def beforeStart(self):
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)
)
):
await self.isTokenExists(
self.link,
Expand Down Expand Up @@ -467,13 +477,6 @@ async def beforeStart(self):
self.userDict.get("gdrive_id")
or config_dict["GDRIVE_ID"]
)
if not self.upDest:
raise ValueError("No Upload Destination!")
if (
not is_gdrive_id(str(self.upDest))
and not is_rclone_path(str(self.upDest))
):
raise ValueError("Wrong Upload Destination!")
if (
self.upDest
not in [
Expand Down
9 changes: 1 addition & 8 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
sleep,
)
from asyncio.subprocess import PIPE
from concurrent.futures import ThreadPoolExecutor
from functools import partial, wraps

from pyrogram.types import BotCommand
Expand All @@ -26,8 +25,6 @@
from bot.helper.telegram_helper.button_build import ButtonMaker
from bot.helper.telegram_helper.bot_commands import BotCommands

THREADPOOL = ThreadPoolExecutor(max_workers=1000)

COMMAND_USAGE = {}


Expand Down Expand Up @@ -211,10 +208,6 @@ async def set_commands(client):
f"{BotCommands.StatsCommand[0]}",
"ᴄʜᴇᴄᴋ ʙᴏᴛ ꜱᴛᴀᴛꜱ"
),
BotCommand(
f"{BotCommands.SelectCommand}",
"ꜱᴇʟᴇᴄᴛ ꜰɪʟᴇꜱ ᴛᴏ ᴅᴏᴡɴʟᴏᴀᴅ"
),
BotCommand(
f"{BotCommands.CancelTaskCommand[0]}",
"ᴄᴀɴᴄᴇʟ ᴀ ᴛᴀꜱᴋ"
Expand Down Expand Up @@ -435,7 +428,7 @@ async def sync_to_async(func, *args, wait=True, **kwargs):
**kwargs
)
future = bot_loop.run_in_executor(
THREADPOOL,
None,
pfunc
)
return (
Expand Down
30 changes: 1 addition & 29 deletions bot/helper/ext_utils/db_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ async def db_load(self):
)
except Exception as e:
LOGGER.error(f"DataBase Collection Error: {e}")
self._conn.close # type: ignore
return
# Save Aria2c options
if await self._db.settings.aria2c.find_one({"_id": bot_id}) is None: # type: ignore
Expand Down Expand Up @@ -121,7 +120,6 @@ async def db_load(self):
user_id = row["_id"]
del row["_id"]
rss_dict[user_id] = row
self._conn.close # type: ignore

async def update_deploy_config(self):
if self._err:
Expand All @@ -132,7 +130,6 @@ async def update_deploy_config(self):
current_config,
upsert=True
)
self._conn.close # type: ignore

async def update_config(self, dict_):
if self._err:
Expand All @@ -142,7 +139,6 @@ async def update_config(self, dict_):
{"$set": dict_},
upsert=True
)
self._conn.close # type: ignore

async def update_aria2(self, key, value):
if self._err:
Expand All @@ -152,7 +148,6 @@ async def update_aria2(self, key, value):
{"$set": {key: value}},
upsert=True
)
self._conn.close # type: ignore

async def update_qbittorrent(self, key, value):
if self._err:
Expand All @@ -162,7 +157,6 @@ async def update_qbittorrent(self, key, value):
{"$set": {key: value}},
upsert=True
)
self._conn.close # type: ignore

async def save_qbit_settings(self):
if self._err:
Expand All @@ -172,7 +166,6 @@ async def save_qbit_settings(self):
qbit_options,
upsert=True
)
self._conn.close # type: ignore

async def update_private_file(self, path):
if self._err:
Expand All @@ -190,8 +183,6 @@ async def update_private_file(self, path):
)
if path == "config.env":
await self.update_deploy_config()
else:
self._conn.close # type: ignore

async def update_nzb_config(self):
async with aiopen(
Expand Down Expand Up @@ -223,7 +214,6 @@ async def update_user_data(self, user_id):
data,
upsert=True
)
self._conn.close # type: ignore

async def update_user_doc(self, user_id, key, path=""):
if self._err:
Expand All @@ -241,7 +231,6 @@ async def update_user_doc(self, user_id, key, path=""):
{"$set": {key: doc_bin}},
upsert=True
)
self._conn.close # type: ignore

async def rss_update_all(self):
if self._err:
Expand All @@ -252,7 +241,6 @@ async def rss_update_all(self):
rss_dict[user_id],
upsert=True
)
self._conn.close # type: ignore

async def rss_update(self, user_id):
if self._err:
Expand All @@ -262,13 +250,11 @@ async def rss_update(self, user_id):
rss_dict[user_id],
upsert=True
)
self._conn.close # type: ignore

async def rss_delete(self, user_id):
if self._err:
return
await self._db.rss[bot_id].delete_one({"_id": user_id}) # type: ignore
self._conn.close # type: ignore

async def add_incomplete_task(self, cid, link, tag):
if self._err:
Expand All @@ -280,13 +266,11 @@ async def add_incomplete_task(self, cid, link, tag):
"tag": tag
}
)
self._conn.close # type: ignore

async def rm_complete_task(self, link):
if self._err:
return
await self._db.tasks[bot_id].delete_one({"_id": link}) # type: ignore
self._conn.close # type: ignore

async def get_incomplete_tasks(self):
notifier_dict = {}
Expand All @@ -304,14 +288,12 @@ async def get_incomplete_tasks(self):
else:
notifier_dict[row["cid"]] = {row["tag"]: [row["_id"]]}
await self._db.tasks[bot_id].drop() # type: ignore
self._conn.close # type: ignore
return notifier_dict # return a dict ==> {cid: {tag: [_id, _id, ...]}}

async def trunc_table(self, name):
if self._err:
return
await self._db[name][bot_id].drop() # type: ignore
self._conn.close # type: ignore

async def add_download_url(self, url: str, tag: str):
if self._err:
Expand All @@ -326,13 +308,11 @@ async def add_download_url(self, url: str, tag: str):
{"$set": download},
upsert=True
)
self._conn.close # type: ignore

async def check_download(self, url: str):
if self._err:
return
exist = await self._db.download_links.find_one({"_id": url}) # type: ignore
self._conn.close # type: ignore
return exist

async def clear_download_links(self, botName=None):
Expand All @@ -341,13 +321,11 @@ async def clear_download_links(self, botName=None):
if not botName:
botName = bot_name
await self._db.download_links.delete_many({"botname": botName}) # type: ignore
self._conn.close # type: ignore

async def remove_download(self, url: str):
if self._err:
return
await self._db.download_links.delete_one({"_id": url}) # type: ignore
self._conn.close # type: ignore

async def update_user_tdata(self, user_id, token, time):
if self._err:
Expand All @@ -357,7 +335,6 @@ async def update_user_tdata(self, user_id, token, time):
{"$set": {"token": token, "time": time}},
upsert=True
)
self._conn.close # type: ignore

async def update_user_token(self, user_id, token, inittime):
if self._err:
Expand All @@ -367,15 +344,13 @@ async def update_user_token(self, user_id, token, inittime):
{"$set": {"token": token, "inittime": inittime}},
upsert=True
)
self._conn.close # type: ignore

async def get_token_expire_time(self, user_id):
if self._err:
return None
user_data = await self._db.access_token.find_one({"_id": user_id}) # type: ignore
if user_data:
return user_data.get("time")
self._conn.close # type: ignore
return None

async def get_user_token(self, user_id):
Expand All @@ -384,7 +359,6 @@ async def get_user_token(self, user_id):
user_data = await self._db.access_token.find_one({"_id": user_id}) # type: ignore
if user_data:
return user_data.get("token")
self._conn.close # type: ignore
return None

async def get_token_init_time(self, user_id):
Expand All @@ -393,11 +367,9 @@ async def get_token_init_time(self, user_id):
user_data = await self._db.access_token.find_one({"_id": user_id}) # type: ignore
if user_data:
return user_data.get("inittime")
self._conn.close # type: ignore
return None

async def delete_all_access_tokens(self):
if self._err:
return
await self._db.access_token.delete_many({}) # type: ignore
self._conn.close # type: ignore
await self._db.access_token.delete_many({}) # type: ignore
6 changes: 3 additions & 3 deletions bot/helper/ext_utils/files_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
rmtree
)
from subprocess import run as srun
from sys import exit as sexit
from sys import exit

from bot import (
aria2,
Expand Down Expand Up @@ -156,10 +156,10 @@ def exit_clean_up(signal, frame):
"-f",
"gunicorn|aria2c|qbittorrent-nox|ffmpeg|java"
])
sexit(0)
exit(0)
except KeyboardInterrupt:
LOGGER.warning("Force Exiting before the cleanup finishes!")
sexit(1)
exit(1)


async def clean_unwanted(path, custom_list=None):
Expand Down
Loading

0 comments on commit 47251ad

Please sign in to comment.