From 95ae9d3413f150c8304b46ec07dcc632938905c1 Mon Sep 17 00:00:00 2001 From: Levi <57452819+l3v11@users.noreply.github.com> Date: Thu, 24 Nov 2022 13:52:49 +0600 Subject: [PATCH] Fix bot crashing when DOWNLOAD_DIR env var isn't filled up --- bot/__init__.py | 10 ++++++---- bot/__main__.py | 5 ++++- bot/modules/status.py | 10 +++------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/bot/__init__.py b/bot/__init__.py index 2cf20bbd..5a1de24c 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -90,9 +90,11 @@ USE_SERVICE_ACCOUNTS = os.environ.get('USE_SERVICE_ACCOUNTS', '') USE_SERVICE_ACCOUNTS = USE_SERVICE_ACCOUNTS.lower() == 'true' -DOWNLOAD_DIR = os.environ.get('DOWNLOAD_DIR', '/usr/src/app/downloads/') -if not DOWNLOAD_DIR.endswith('/'): - DOWNLOAD_DIR = DOWNLOAD_DIR + '/' +DOWNLOAD_DIR = os.environ.get('DOWNLOAD_DIR', '') +if len(DOWNLOAD_DIR) == 0: + DOWNLOAD_DIR = '/usr/src/app/downloads/' +elif not DOWNLOAD_DIR.endswith('/'): + DOWNLOAD_DIR = f'{DOWNLOAD_DIR}/' STATUS_UPDATE_INTERVAL = os.environ.get('STATUS_UPDATE_INTERVAL', '') STATUS_UPDATE_INTERVAL = 10 if len(STATUS_UPDATE_INTERVAL) == 0 else int(STATUS_UPDATE_INTERVAL) @@ -129,7 +131,7 @@ if res.status_code == 200: with open('accounts.zip', 'wb+') as f: f.write(res.content) - subprocess.run(["unzip", "-q", "-o", "accounts.zip"]) + subprocess.run(["unzip", "-q", "-o", "accounts.zip", "-x", "accounts/emails.txt"]) subprocess.run(["chmod", "-R", "777", "accounts"]) os.remove("accounts.zip") else: diff --git a/bot/__main__.py b/bot/__main__.py index 945c5ffb..3c81bf77 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -138,7 +138,10 @@ def main(): if os.path.isfile(".restartmsg"): with open(".restartmsg") as f: chat_id, msg_id = map(int, f) - bot.editMessageText("Restarted successfully", chat_id, msg_id, parse_mode='HTML') + try: + bot.editMessageText("Restarted successfully", chat_id, msg_id, parse_mode='HTML') + except: + pass os.remove(".restartmsg") start_handler = CommandHandler(BotCommands.StartCommand, start, run_async=True) diff --git a/bot/modules/status.py b/bot/modules/status.py index b7c53a87..8c2dc201 100644 --- a/bot/modules/status.py +++ b/bot/modules/status.py @@ -19,13 +19,9 @@ def statusNode(update, context): sendStatusMessage(update.message, context.bot) deleteMessage(context.bot, update.message) with status_reply_dict_lock: - try: - if Interval: - Interval[0].cancel() - Interval.clear() - except: - pass - finally: + if Interval: + Interval[0].cancel() + Interval.clear() Interval.append(SetInterval(STATUS_UPDATE_INTERVAL, update_all_messages)) status_handler = CommandHandler(BotCommands.StatusCommand, statusNode,