Skip to content

Commit

Permalink
Some minor fixes
Browse files Browse the repository at this point in the history
Signed-off-by: anasty17 <[email protected]>
  • Loading branch information
anasty17 committed May 17, 2024
1 parent f3eb4b6 commit 58bafa5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 25 deletions.
9 changes: 7 additions & 2 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ async def restart(_, message):
await sync_to_async(clean_all)
nzb_client = get_sabnzb_client()
if nzb_client.LOGGED_IN:
await nzb_client.pause_all()
await nzb_client.purge_all(True)
await gather(
nzb_client.pause_all(),
nzb_client.purge_all(True),
nzb_client.delete_history("all", delete_files=True),
)
await nzb_client.shutdown()
proc1 = await create_subprocess_exec(
"pkill",
Expand Down Expand Up @@ -248,6 +251,8 @@ async def send_incompelete_task_message(cid, msg):


async def main():
if DATABASE_URL:
await DbManager().db_load()
jdownloader.initiate()
await gather(
sync_to_async(clean_all),
Expand Down
17 changes: 6 additions & 11 deletions bot/helper/ext_utils/db_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
config_dict,
aria2_options,
qbit_options,
bot_loop,
)


Expand All @@ -38,8 +37,8 @@ async def db_load(self):
return
# Save bot settings
try:
await self._db.settings.config.update_one(
{"_id": bot_id}, {"$set": config_dict}, upsert=True
res = await self._db.settings.config.replace_one(
{"_id": bot_id}, config_dict, upsert=True
)
except Exception as e:
LOGGER.error(f"DataBase Collection Error: {e}")
Expand Down Expand Up @@ -137,8 +136,8 @@ async def update_qbittorrent(self, key, value):
async def save_qbit_settings(self):
if self._err:
return
await self._db.settings.qbittorrent.update_one(
{"_id": bot_id}, {"$set": qbit_options}, upsert=True
await self._db.settings.qbittorrent.replace_one(
{"_id": bot_id}, qbit_options, upsert=True
)
self._conn.close

Expand All @@ -162,8 +161,8 @@ async def update_private_file(self, path):
async def update_nzb_config(self):
async with aiopen("sabnzbd/SABnzbd.ini", "rb+") as pf:
nzb_conf = await pf.read()
await self._db.settings.nzb.update_one(
{"_id": bot_id}, {"$set": {"SABnzbd__ini": nzb_conf}}, upsert=True
await self._db.settings.nzb.replace_one(
{"_id": bot_id}, {"SABnzbd__ini": nzb_conf}, upsert=True
)

async def update_user_data(self, user_id):
Expand Down Expand Up @@ -251,7 +250,3 @@ async def trunc_table(self, name):
return
await self._db[name][bot_id].drop()
self._conn.close


if DATABASE_URL:
bot_loop.run_until_complete(DbManager().db_load())
10 changes: 7 additions & 3 deletions bot/helper/mirror_leech_utils/download_utils/nzb_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ async def add_servers(client):
except LoginFailed as e:
raise e
elif not res and (
not config_dict["USENET_SERVERS"][0]["host"]
or not config_dict["USENET_SERVERS"][0]["username"]
or not config_dict["USENET_SERVERS"][0]["password"]
config_dict["USENET_SERVERS"]
and (
not config_dict["USENET_SERVERS"][0]["host"]
or not config_dict["USENET_SERVERS"][0]["username"]
or not config_dict["USENET_SERVERS"][0]["password"]
)
or not config_dict["USENET_SERVERS"]
):
raise NotLoggedIn("Set USENET_SERVERS in bsetting or config!")
else:
Expand Down
8 changes: 8 additions & 0 deletions sabnzbdapi/bound_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ class SubFunctions:
def __init__(self):
pass

async def check_login(self):
res = await self.get_config("servers")
if res["config"]:
self.LOGGED_IN = True
return res["config"]
else:
return False

async def add_server(self, server: dict):
"""server = {
"name": "main",
Expand Down
2 changes: 1 addition & 1 deletion sabnzbdapi/job_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ async def retry_all(self):
return await self.call({"mode": "retry_all"})

async def delete_history(
self, nzo_ids: str | list[str], archive: int = 0, delete_files: int = 0
self, nzo_ids: str | list[str], archive: int = 0, delete_files: bool = False
):
"""return {"status": True}"""
return await self.call(
Expand Down
8 changes: 0 additions & 8 deletions sabnzbdapi/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,6 @@ async def call(
raise APIConnectionError("Failed to connect to API!")
return response

async def check_login(self):
res = await self.get_config("servers")
if res["config"]:
self.LOGGED_IN = True
return res["config"]
else:
return False

async def log_out(self):
if self._http_session is not None:
await self._http_session.aclose()
Expand Down

0 comments on commit 58bafa5

Please sign in to comment.