Skip to content

Commit

Permalink
Fix bot crashing when DOWNLOAD_DIR env var isn't filled up
Browse files Browse the repository at this point in the history
  • Loading branch information
l3v11 authored Nov 24, 2022
1 parent c41fefa commit 95ae9d3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
10 changes: 6 additions & 4 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<b>Restarted successfully</b>", chat_id, msg_id, parse_mode='HTML')
try:
bot.editMessageText("<b>Restarted successfully</b>", chat_id, msg_id, parse_mode='HTML')
except:
pass
os.remove(".restartmsg")

start_handler = CommandHandler(BotCommands.StartCommand, start, run_async=True)
Expand Down
10 changes: 3 additions & 7 deletions bot/modules/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 95ae9d3

Please sign in to comment.