Skip to content

Commit

Permalink
Bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nubuki-all committed Jan 24, 2024
1 parent 5a55634 commit d2b394d
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 18 deletions.
1 change: 0 additions & 1 deletion bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
queue_lock = asyncio.Lock()
rename_file = "Auto-rename.txt"
rss_dict_lock = asyncio.Lock()
startup_ = []
thumb = "thumb.jpg"
version_file = "version.txt"

Expand Down
11 changes: 10 additions & 1 deletion bot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self):
self.CMD_SUFFIX = config("CMD_SUFFIX", default=str())
self.DATABASE_URL = config("DATABASE_URL", default=None)
self.DBNAME = config("DBNAME", default="ENC")
self.DEV = config("DEV", default=123456, cast=int)
self.DEV = config("DEV", default=0, cast=int)
self.DL_STUFF = config("DL_STUFF", default=None)
self.DUMP_CHANNEL = config("DUMP_CHANNEL", default=0, cast=int)
self.DUMP_LEECH = config("DUMP_LEECH", default=True, cast=bool)
Expand Down Expand Up @@ -87,5 +87,14 @@ def __init__(self):
print(traceback.format_exc())
exit()

class Runtime_Config:
# will slowly replace the Var_list class in utils.bot_utils
def __init__(self):
self.aria2 = None
self.sas = False
self.sqs = False
self.started = False


conf = Config()
_bot = Runtime_Config()
25 changes: 18 additions & 7 deletions bot/startup/after.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

async def start_aria2p():
try:
globals()["aria2"] = aria2p.API(
aria2 = aria2p.API(
aria2p.Client(host="http://localhost", port=conf.ARIA2_PORT, secret="")
)
aria2.add(
Expand All @@ -20,9 +20,8 @@ async def start_aria2p():
downloads = aria2.get_downloads()
await asyncio.sleep(3)
aria2.remove(downloads, force=True, files=True, clean=True)
ARIA2.append(aria2)

# return aria2
_bot.aria2 = aria2
_bot.sas = True

except Exception:
await logger(Exception, critical=True)
Expand All @@ -33,6 +32,8 @@ async def start_qbit():
os.system(
f"qbittorrent-nox -d --webui-port={conf.QBIT_PORT} --profile={os.getcwd()}"
)
# TO_DO: Properly check if qbit is fully operational.
_bot.sqs = True


async def start_rpc():
Expand All @@ -41,8 +42,8 @@ async def start_rpc():
"--seed-time=0 --follow-torrent=mem --summary-interval=0 --daemon=true --allow-overwrite=true "
"--user-agent=Wget/1.12"
)
if not startup_:
await asyncio.sleep(3)
if not _bot.started:
await asyncio.sleep(1)
await start_aria2p()


Expand Down Expand Up @@ -78,6 +79,15 @@ async def onstart():
await tele.send_message(
conf.LOG_CHANNEL, f"**{me.first_name} is {enquip()} {enmoji()}**"
)
dev = conf.DEV or conf.LOG_CHANNEL or int(conf.OWNER.split()[0])
try:
await tele.send_message(
dev,
f"**Aria2:** `{'Online' if _bot.sas else 'Offline/Not_ready'}`"
f"\n**Qbit:** `{'Online' if _bot.sqs else 'Offline/Not_ready'}`"
)
except Exception:
await logger(Exception)
except BaseException:
pass

Expand Down Expand Up @@ -114,11 +124,12 @@ async def on_startup():
if len(sys.argv) == 3:
await onrestart()
else:
await asyncio.sleep(1)
await onstart()
await entime.start()
await asyncio.sleep(30)
asyncio.create_task(something())
except Exception:
logger(Exception)
startup_.append(1)
_bot.started = True
# STARTUP.append(1)
2 changes: 1 addition & 1 deletion bot/startup/before.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pymongo import MongoClient

from bot import *
from bot.config import conf
from bot.config import _bot, conf
from bot.utils.bot_utils import create_api_token, var
from bot.utils.local_db_utils import load_local_db
from bot.utils.os_utils import file_exists
Expand Down
5 changes: 2 additions & 3 deletions bot/utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
tgp_client,
time,
)
from bot.config import conf
from bot.config import _bot, conf

suffix = conf.CMD_SUFFIX

Expand All @@ -46,7 +46,6 @@ class Var_list:
STARTUP = []
WORKING = []
EVENT2 = []
ARIA2 = []

PREVIEW_BATCH = {}
BATCH_QUEUE = {}
Expand Down Expand Up @@ -125,7 +124,7 @@ def get_pause_status():


def get_aria2():
return ARIA2[0] if ARIA2 else None
return _bot.aria2


def get_var(var):
Expand Down
10 changes: 9 additions & 1 deletion bot/utils/rss_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from feedparser import parse as feedparse

from bot import pyro, rss_dict_lock
from bot.config import conf
from bot.config import _bot, conf
from bot.workers.auto.schedule import addjob, scheduler
from bot.workers.handlers.queue import enleech, enleech2

Expand All @@ -18,6 +18,14 @@ async def rss_monitor():
"""
An asynchronous function to get rss links
"""
if not (_bot.sas and _bot.sqs):
await asyncio.sleep(10)
if _bot.sas and _bot.sqs:
return
log(e='RSS scheduler has been paused since a download service is not responding…')
if _bot.started:
scheduler.pause()
return
if not conf.RSS_CHAT:
log(e="RSS_CHAT not added! Shutting down rss scheduler...")
scheduler.shutdown(wait=False)
Expand Down
6 changes: 3 additions & 3 deletions bot/workers/auto/status.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from bot import asyncio, itertools, pyro, startup_, tele
from bot.config import conf
from bot import asyncio, itertools, pyro, tele
from bot.config import _bot, conf
from bot.fun.emojis import enmoji
from bot.fun.quips import enquip4
from bot.fun.quotes import enquotes
Expand Down Expand Up @@ -127,7 +127,7 @@ def wait():
else:
if check.done:
check.done = False
if startup_:
if _bot.started:
if wait():
await asyncio.sleep(60)
continue
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.2.0-beta.0.5.13 (beta)
v2.2.0-beta.0.6.00 (beta)

0 comments on commit d2b394d

Please sign in to comment.